gpt4 book ai didi

python - Hindmarsh-Rose 模型的相空间轨迹

转载 作者:行者123 更新时间:2023-12-04 07:34:24 35 4
gpt4 key购买 nike

我正在尝试绘制 Hindmarsh-Rose 模型的相空间轨迹。我已经实现了一个 RK4 积分器来解决以下方程组:
enter image description here
到目前为止,我编写的代码如下。

import numpy as np
import matplotlib.pyplot as plt

def RK4(f, x0, t):

dt = t[2] -t[1] #time span
N = len(t)
X = np.empty((len(t), len(x0)))
X[0] = x0

for i in range(1, N):

k1 = f(X[i-1], t[i-1])
k2 = f(X[i-1] + dt/2*k1, t[i-1] + dt/2)
k3 = f(X[i-1] + dt/2*k2, t[i-1] + dt/2)
k4 = f(X[i-1] + dt*k3, t[i-1] + dt)

X[i] = X[i-1] + dt/6*(k1 + 2*k2 + 2*k3 + k4)

return X


def hindmarsh(X, t):

a = 3.0
c = 1.0
d = 5.0
s = 4.0
x0 = - 1.6

# Bifurcation parameters

b = 3.09
I = 3.2
eps = 0.001

x,y,z = X

dxdt = y - (a * x**3) + (b * x**2) + I - z
dydt = c - (d * x**2) - y
dzdt = eps * ( (s * (x - x0)) - z)

return np.array([dxdt, dydt, dzdt])


T = np.linspace(0,100,10000)

Y = [0.03, 0.03, 3]

param = RK4( hindmarsh, Y, T )

ax = plt.axes(projection='3d')

zline = param[2]
yline = param[1]
xline = param[0]


ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')

ax.plot3D(xline, yline, zline)

但是,我没有在相空间中获得轨道,如下图所示,而是在相空间中得到一条直线。我将不胜感激有关如何获得下面的情节的任何提示。
enter image description here

最佳答案

param有形状(len(T), len(Y)) ,所以时间在第一维,x,y,z 在第二维。你会得到正确的情节

zline = param[:,0]
xline = param[:,1]
yline = param[:,2]

关于python - Hindmarsh-Rose 模型的相空间轨迹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67806064/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com