My code is working right except when i enter r1 into the function equation below
def u(Substrate):
return((u_max*ys[:,0])/(Ks+ys[:,0]))
biomass = ys[:,1]
u = u(ys[:,0])
def r1(u,biomass):
r1 = u*biomass*YieldCO2_1
return r1
r1 = r1(u,biomass)
def F(y,t):
Ptot = 710
Vgas = 2
D = 0.00826*(273.15+Temp)
Cstar_CO2 = KH_CO2 * y[2]
Cstar_CH4 = KH_CH4 * y[3]
TG_CO2 = KLa_CO2*(Cstar_CO2-y[0])
TG_CH4 = KLa_CH4*(Cstar_CH4-y[1])
Q_CO2 = -D*V*TG_CO2
Q_CH4 = -D*V*TG_CH4
Qgas = (Q_CO2+Q_CH4)+Q
F=np.zeros(4)
F[0] = Q/V * (CO2_To-y[0]) + TG_CO2 + r1
F[1] = Q/V * (CH4_Do-y[1]) + TG_CH4
F[2] = -Ptot*D*TG_CO2*(V/Vgas)-y[2]*(Qgas/Vgas)
F[3] = -Ptot*D*TG_CH4*(V/Vgas)-y[3]*(Qgas/Vgas)
return F
yinit = np.array([4,3,250,200])
ts = np.arange(0,4,0.4)
y = odeint(F,yinit,ts)
When r1 is seen in equation F[0] I get the following error:
F[0] = Q/V * (CO2_To-y[0]) + TG_CO2 + r1
ValueError: setting an array element with a sequence.
odepack.error: Error occurred while calling the Python function named F
However when I do the function without the r1 array, there is no error. so that is why i am assuming something is wrong with putting the r1 array into the function If anyone could provide input to my problem i would
F = np.zeros((4, len(r1))
u = u(ys[:,0])
,r1 = r1(u,biomass)
, usingF
as a variable in a function calledF
. You should not use variable names that are the same as the function names. It makes your code difficult to understand and difficult to debug.