我想通过迭代一个初始条件来解这个方程组

2024-09-27 21:31:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我想解一个三阶微分方程组,改变初始条件

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


Tags: inimportdtpltcsrxprocesscp
1条回答
网友
1楼 · 发布于 2024-09-27 21:31:29

请更新以下函数(因为我们不能将数组分配给多个变量)

def fermentation_process(C,t):
    Cx , Cs , Cp = C[0], C[1], C[2]

(或)

def fermentation_process(C,t):
    Cx = C[0]
    Cs = C[1]
    Cp = C[2] 

相关问题 更多 >

    热门问题