我想解一个三阶微分方程组,改变初始条件
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
#__________________________Condiciones Problema ________________________
#Constants that are use in the problem
Yxs = 0.06
Yxp = 0.06
Umax = 0.24
Ks = 1.6
Cpm = 100
n = 2
#Function to solve de ODE
def fermentation_process(C,t):
Cx , Cs , Cp = C
U = (Umax*((Cs/(Ks+Cs))*(1-(Cp/Cpm)))**n)
rx = U*Cx
rs = -(1/Yxs)*(rx)
rp = (1/Yxp)*(rx)
dCx_dt = rx
dCs_dt = rs
dCp_dt = rp
return [dCx_dt,dCs_dt,dCp_dt]
#________________________Initial condition_____________________
Cx0 = 0.1
Cp0 = 0
#________________________Iterable intial Condition______
我将初始条件保存在函数中,以便在bucle中使用此函数
#Fuction to save the inintial conditions
def ini(Cs0):
return np.array([Cx0,Cs0,Cp0])
t_lim = (0,60)
Cs0 = 0
颊部评估变量初始条件Cs0
for i in range(5):
Cs0 += 10
sol = solve_ivp(fermentation_process, ini(Cs0), t_lim)
Tiempo = sol.t
concentraciones = sol.y
figure, axis = plt.subplots()
plt.plot(Tiempo, concentraciones[0])
plt.plot(Tiempo, concentraciones[2])
plt.show()
我得到的错误是:
File "C:/Users/Paula/.spyder-py3/Sin título0.py", line 50, in fermentation_process Cx , Cs , Cp = C
TypeError: cannot unpack non-iterable float object
请更新以下函数(因为我们不能将数组分配给多个变量)
(或)
相关问题 更多 >
编程相关推荐