更改t间隔时odeint的行为有所不同

时间:2018-09-29 08:15:30

标签: python plot ode odeint

我有这个方程组:

def Diffeq(v,t, lam, gam,a):
    c=[i for i in range(0,len(v))]
    vdot = np.empty_like(v) 

    for i in range(0,len(v)):
        if i == 0:
            vdot[0] = gam*c[1]*v[1]
        elif i == (len(v)-1):
            vdot[i] =  lam*a[i-1]*v[i-1] - (lam*a[i]+gam*c[i])*v[i]
        else:
            vdot[i]=  lam*a[i-1]*v[i-1] - (lam*a[i]+gam*c[i])*v[i]+ 
                                                     gam*c[i+1]*v[i+1]
    return vdot

其中lambda,gamma和a是以下参数集(N = 1000):

a = [6*i*(N-i)/(N-1.0) for i in range (0,N+1)]
gamma = 1
lam = 2

如果我打电话给

t = np.linspace(0,3,100)
incond=np.array([0.0]*(N+1) #from 0 to 1000 included
incond[i0] =1.0 
y = odeint(Diffeq, incond, t, args=(lam,gamma,a))

然后我尝试绘制y的期望值:

finalv = np.array([0.0]*100)
for time in range(0,100):
    for k in range(0,N+1):
        finalv[time] = finalv[time] + (k)*y[time][k]

我可以绘制结果,并且有一条很好的预期曲线: enter image description here

如果我想将t间隔更改为

t = linspace(0,50,100)

然后我尝试绘制,曲线的形状改变了! enter image description here

有时候,如果我对a的值进行一些调整,则会收到此运行时警告:

/home/myub/Desktop/Odeintegration.py:79: RuntimeWarning: overflow 
encountered in double_scalars

0 个答案:

没有答案