为什么我的Python BZ Oregonator无法编译?

问题描述 投票:0回答:1

[我正在尝试通过求解ODE来模拟Belousov-Zhabotinsky反应溶液中的颜色变化,并产生一个使用odeint演示振荡的图形。

我收到一条错误消息'AxisError:轴-1超出维度0的数组的范围,并且我不知道为什么会这样,我对Python还是陌生的,我正在苦苦挣扎。

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


# Dimensionless parameters
c1 = 10
c2 = 0.15
c3 = 0.005
c4 = 0.02

#pack 3 initial conditions with state of x,y,z into y0
y0 = [1,0,0]
k = 1


def Oregonator (t,Y):
  x = Y[0]
  y = Y[1]
  z = Y[2]
 dxdt = c1 + c2*x - x - x*y**2
 dydt = (x + x*y**2 - y)/c3
 dzdt = (y-z)/c4
 return [dxdt,dydt,dzdt]


t = np.linspace(0, 10,100)

Y = odeint(y0,t,Oregonator)

plt.plot(t,Y)
plt.xlabel('time')
plt.ylabel('other side')

plt.show()

我正在使用Spyder处理Python代码。感谢您能提供的任何帮助,谢谢。

python ode odeint
1个回答
0
投票

至少您需要将对odeint的呼叫固定为与其文档一致,>

Y = odeint(Oregonator,y0,t, tfirst=True)

并且您需要使Oregonator函数中的缩进相等。然后,您将得到一个振荡图。

也要提高显示分辨率,在100个以上的振荡间隔内100个点太少了。由于存在尖锐的峰,您希望每个振荡至少有20个点,更好的是,所以

t = np.linspace(0, 10,5000)
© www.soinside.com 2019 - 2024. All rights reserved.