1 回答

TA貢獻1880條經驗 獲得超4個贊
用作求解器類(如或solve_ivp)的單行接口。使用類的正確大寫。在 ODE 函數中使用正確的參數順序(您可以使用in來使用相同的函數)。在您打算使用浮點除法的地方避免整數除法。RK45Radautfirst=Trueodeint
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()
然后這會產生情節
表現出周期性振蕩。
進一步的步驟可能是使用tspan
選項或“密集輸出”在用戶定義的采樣點處獲取解決方案樣本。為獲得可靠的結果,請手動設置誤差容限。
f=0.51262
接近從收斂到振蕩行為的過渡點。
添加回答
舉報