0

I have a function where I need to minimize c_init to make totalF output zero. the problem is that I have some constants over this function which are Es, f_slong and f_c. I need to repeat this whole minimization for 30 different cases meaning that I have 30 different constant variables and 30 different c_init initial values. Then, my aim is to obtain what the values for c_init will be at the end of the algorithm. However, those constant variables give me trouble. I do not have any inequality (I am not sure if I have to define it anyway), I strongly feel that my problem is to define the location and inputs of *args, I've tested out many different scenarios but they all failed. Could anyone help me out? Those constant variables should be coming from their list of array in every iteration and sending through the minimization function.

def c_neutral_un(c_init, Es, f_slong, f_c):
    eps_s = e_cu_un * (d - c_init) / c_init
    eps_s_prime = e_cu_un * (c_init - d_prime) / c_init
    
    if Es * eps_s > f_slong:
        f_s = f_slong
    else:
        f_s = Es * eps_s
        
    if Es * eps_s_prime > f_slong:
        f_s_prime = f_slong
    else:
        f_s_prime = Es * eps_s_prime
        
    T = As * f_s
    Cs_prime = As_prime * (f_s_prime - alfa1 * f_c)
    Cc_conc = alfa1 * f_c * b * beta1 * c_init
    totalF = Cc_conc + Cs_prime - T
    return totalF
c = []
for i in range(31)
    bnd = ([0, 200])
    x0 = c_init[i]
    Es = Es[i]
    f_slong = f_slong[i]
    f_c = f_c[i]
    res = minimize(c_neutral_un, x0, args=([Es, f_slong, f_c], True) method = "SLSQP", bounds = bnd)
    c.append(res.x)


burakdur
  • 11
  • 3

1 Answers1

0

THere is an error for constant assignment like Es = Es[i]

def c_neutral_un(c_init, Es, f_slong, f_c):
    eps_s = e_cu_un * (d - c_init) / c_init
    eps_s_prime = e_cu_un * (c_init - d_prime) / c_init

    if Es * eps_s > f_slong:
        f_s = f_slong
    else:
        f_s = Es * eps_s

    if Es * eps_s_prime > f_slong:
        f_s_prime = f_slong
    else:
        f_s_prime = Es * eps_s_prime

    T = As * f_s
    Cs_prime = As_prime * (f_s_prime - alfa1 * f_c)
    Cc_conc = alfa1 * f_c * b * beta1 * c_init
    totalF = Cc_conc + Cs_prime - T
    return totalF


c = []
for i in range(31):
    bnd = ([0, 200])
    x0 = c_init[i]
    Es2 = Es[i]
    f_slong2 = f_slong[i]
    f_c2 = f_c[i]
    res = minimize(c_neutral_un, x0, args=([Es2, f_slong2, f_c2], True),method = "SLSQP", bounds = bnd)
    c.append(res.x)
ymmx
  • 4,769
  • 5
  • 32
  • 64