我试图了解scipy.odeint的工作原理,但是我有一些问题。例如:
import numpy as np
from scipy.integrate import odeint
from scipy.integrate import odeint
def Diffeq(v,t, lam, gam,c, a):
vdot = v
for i in range(0,len(v)):
if i == 0:
vdot[0] = c[1]*v[1]- lam*a[0]*v[0]
elif i == (len(v)-1):
vdot[i] = lam*a[i-1]*v[i-1] - (lam*a[i]+c[i])*v[i]
else:
vdot[i]= lam*a[i-1]*v[i-1] - (lam*a[i]+c[i])*v[i]+ c[i+1]*v[i+1]
print vdot
return vdot
incond=np.array([0]*900)
incond[1] =1
t = np.linspace(0.0, 2, 1000)
ak = [2*i for i in range(0,900)]
lamma =2
gamma =1
c=[i*gamma for i in range(0,900)]
y = odeint(Diffeq, incond, t, args=(lamma,gamma,c,ak) )
其中
xdot_0 =-(a_0 + c_0)* x_0(t)+ c_1 * x_1(t)
xdot_899 = a_898 * x_898(t)-(a_899 + c_899)* x_900(t)
具有初始条件x(0)=(0,1,0 ... 0) 当我尝试分析结果时,我注意到我的函数爆炸到+无限。如果我使用常数ak,lamma和gamma,可以将结果卡在类似
的位置x_k(t)= [0,-21,21,0,0,...,0]
每次操作。因此,我认为我在代码中犯了一些错误,但是看不到哪里。