目标是绘制两个耦合的完全相同的动力系统。
我们有:
X= x0、x1、x2
U= u0、u1、u2
和
Xdot = f(X) + alpha*(U-X)
Udot = f(U) + alpha*(X-U)
因此,我希望将这个大系统的解绘制在一组轴上(例如,在xyz中),并最终改变耦合强度来研究其行为。
import matplotlib.pyplot as plt
from scipy.integrate import odeint
from mpl_toolkits.mplot3d import Axes3D
def couple(s,t,a=0.2,beta=0.2,gamma=5.7,alpha=0.03):
[x,u] = s
[u0,u1,u2] = u
[x0,x1,x2] = x
xdot = np.zeros(3)
xdot[0] = -x1-x2
xdot[1] = x0+a*x1
xdot[2] = beta + x2*(x0-gamma)
udot = np.zeros(3)
udot[0] = -u1-u2
udot[1] = u0+a*u1
udot[2] = beta + u2*(u0-gamma)
sdot = np.zeros(2)
sdot[0] = xdot + alpha*(u-x)
sdot[1] = udot + alpha*(x-u)
return sdot
s_init = [0.1,0.1]
t_init=0; t_final = 300; t_step = 0.01
tpoints = np.arange(t_init,t_final,t_step)
a=0.2; beta=0.2; gamma=5.7; alpha=0.03
y = odeint(couple, s_init, tpoints,args=(a,beta,gamma,alpha), hmax = 0.01)我认为s_init有问题,因为它应该是两个初始条件向量,但当我尝试时,我得到了"odeint: y0应该是一维的“。另一方面,当我尝试将s_init作为一个6向量时,我得到了“太多的值要解包(应该是两个)”。使用当前的设置,我得到了错误
File "C:/Users/Python Scripts/dynsys2019work.py", line 88, in couple
[u0,u1,u2] = u
TypeError: cannot unpack non-iterable numpy.float64 object干杯
*编辑:请注意,这基本上是我第一次尝试这种事情,我很高兴收到更多的文档和参考资料。
发布于 2019-09-04 01:52:19
ode定义接收并返回scipy odeint中的1D向量,我认为您可能会感到困惑,因为您实际上有1个系统的ode,其中有6个变量。你刚刚在心理上把它分成了两个独立的ODEs,它们是耦合的。
你可以这样做:
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import numpy as np
def couple(s,t,a=0.2,beta=0.2,gamma=5.7,alpha=0.03):
x0, x1, x2, u0, u1, u2 = s
xdot = np.zeros(3)
xdot[0] = -x1-x2
xdot[1] = x0+a*x1
xdot[2] = beta + x2*(x0-gamma)
udot = np.zeros(3)
udot[0] = -u1-u2
udot[1] = u0+a*u1
udot[2] = beta + u2*(u0-gamma)
return np.ravel([xdot, udot])
s_init = [0.1,0.1, 0.1, 0.1, 0.1, 0.1]
t_init=0; t_final = 300; t_step = 0.01
tpoints = np.arange(t_init,t_final,t_step)
a=0.2; beta=0.2; gamma=5.7; alpha=0.03
y = odeint(couple, s_init, tpoints,args=(a,beta,gamma,alpha), hmax = 0.01)
plt.plot(tpoints,y[:,0])https://stackoverflow.com/questions/57773349
复制相似问题