我正在尝试数值求解一个由两个相互耦合的系统组成的系统。
一般说明在this图片中详细说明。
到目前为止,我已经编写了以下代码:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
%matplotlib inline
ep=0.1
a=0.2
N = 200
T=0.001
i = np.arange(N)
theta = (2*np.pi)*i/N
I0 = 0.2
J0 = 0
J1 = 2.5
delta_theta = np.subtract.outer(theta, theta)
J = (J0 + J1*np.cos(delta_theta)+J1*ep*np.sin(delta_theta))/(2*N)
t = np.linspace(0, 2.5, 1000)
np.random.seed(123)
rL0 = np.random.rand(N)
rR0 = np.random.rand(N)
V=[1,2,3]
for tr in V:
def v_func(t1):
if t1>0.499 and t1<1.5:
if tr==1:
v=1
elif tr==2:
v=2*(t1-0.5)
else:
v=np.cos(2*np.pi*t1)
else:
v=0
return v
def vectors2(rL,rR, t, IL,IR, J):
s1 = J @ rL
s2 = J @ rR
drLdt = (-rL + np.maximum(I0*(1-a*v_func(t)) + s1 + s2, 0))/T
drRdt = (-rR + np.maximum(I0*(1+a*v_func(t)) + s1 + s2, 0))/T
return drLdt,drRdt
rL,rR = odeint(vectors2, [rL0,rR0], t,args=(a,T))
plt.figure(figsize=[15,8])
for i in [0, 100, 200, 300, 399]:
plt.plot(t, rL[:, i], label='r(%d)' % i)
plt.xlabel('t')
plt.ylabel('rate of firing')
plt.legend(shadow=True)
plt.grid()
plt.title('general observation of the dynamics : development through time of arbitrary neurons \n random initial conditions, I1=0.001')
plt.show()
我收到此错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-236-7ff71f3388ef> in <module>
43 return drLdt,drRdt
44
---> 45 rL,rR = odeint(vectors2, [rL0,rR0], t,args=(a,T))
46
47 plt.figure(figsize=[15,8])
~/anaconda3/lib/python3.7/site-packages/scipy/integrate/odepack.py in odeint(func, y0, t, args, Dfun, col_deriv, full_output, ml, mu, rtol, atol, tcrit, h0, hmax, hmin, ixpr, mxstep, mxhnil, mxordn, mxords, printmessg, tfirst)
231 full_output, rtol, atol, tcrit, h0, hmax, hmin,
232 ixpr, mxstep, mxhnil, mxordn, mxords,
--> 233 int(bool(tfirst)))
234 if output[-1] < 0:
235 warning_msg = _msgs[output[-1]] + " Run with full_output = 1 to get quantitative information."
ValueError: Initial condition y0 must be one-dimensional.
基本上,我所做的是创建两个矩阵rR
和rL
,它们每个都是N
ODE的系统,我试图将它们传递到ODEINT
中。我相信发生错误是因为我不知道如何通过初始条件(两个由N
,rL0
组成的rR0
元素组成的列表)。
也许我的方法从一开始就错了。任何帮助将不胜感激。