无法导入X问题。Oregonator模型的刚性ODE解算器

2024-05-19 01:45:07 发布

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

错误来自尝试从scipy.integrate导入Radau方法(需要,因为Oregonator模型是一个刚性系统)

我试图用数值积分的方法来表示,在参数f的0和3之间一定有一个过渡点,这样在这个区间的某个特定子集中,就会发生振荡

请原谅我的经验不足,我对Python还不熟悉

错误:ImportError:无法从“scipy.integrate”导入名称“radau”

在我的无知中,我从零开始构造了一个四阶龙格库塔方法。在发现了股票价格而不是化学振荡之后,我转而使用odeint。但还是失败了。直到这之后,我才发现了刚性系统的概念,所以我一直在研究Radau方法

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate. import radau

# Dimensionless parameters
e = 0.04
q = 0.0008
f = 1.0

# Oregonator model
def Oregonator(Y, t):
    return [((Y[0] * (1 - Y[0])  - ((Y[0] - q) * f * Y[1]) // (q + Y[0]))) 
    // e, Y[0] - Y[1]]

# Time span and inital conditions
ts = np.linspace(0, 10, 100)
Y0 = [1, 3]

# Numerical algorithm/method
NumSol = radau(Oregonator, 0, Y0, t_bound=30)
x = NumSol[:,0]
z = NumSol[:,1]

预期结果应该是振荡,如(第12页): https://pdfs.semanticscholar.org/0959/9106a563e9d88ce6442e3bb5b242d5ccbdad.pdf 仅适用于x和z。没有y是由于我使用的稳态近似


Tags: 方法模型import系统as错误npscipy
1条回答
网友
1楼 · 发布于 2024-05-19 01:45:07

使用solve_ivp作为RK45Radau等解算器类的单行接口。使用正确的大写字母。在ODE函数中使用正确的参数顺序(您可以在odeint中使用tfirst=True来使用相同的函数)。避免使用浮点除法的整数除法

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp

# Dimensionless parameters
eps = 4e-2
q = 8e-4
f = 2.0/3

# Oregonator model
def Oregonator(t,Y):
    x,z = Y;
    return [(x * (1 - x) + (f*(q-x)*z) / (q + x)) / eps, x - z]

# Time span and inital conditions
ts = np.linspace(0, 10, 100)
Y0 = [1, 0.5]

# Numerical algorithm/method
NumSol = solve_ivp(Oregonator, [0, 30], Y0, method="Radau")
x, z = NumSol.y
y = (f*z)/(q+x)
t = NumSol.t
plt.subplot(221);
plt.plot(t,x,'b'); plt.xlabel("t"); plt.ylabel("x");
plt.subplot(222);
plt.plot(t,y,'r'); plt.xlabel("t"); plt.ylabel("y");
plt.subplot(223);
plt.plot(t,z,'g'); plt.xlabel("t"); plt.ylabel("z");
plt.subplot(224);
plt.plot(x,z,'k'); plt.xlabel("x"); plt.ylabel("z");
plt.tight_layout(); plt.show()

然后生成绘图

enter image description here

表现出周期性振荡的

进一步的步骤可以是使用tspan选项或“密集输出”在用户定义的采样点获取解决方案样本。为获得可靠的结果,请手动设置误差容限

f=0.51262接近从收敛到振荡的转变点。 enter image description here

相关问题 更多 >

    热门问题