Backward integration in time using scipy odeint

前端 未结 3 825
攒了一身酷
攒了一身酷 2021-01-15 11:01

Is it possible to integrate any Ordinary Differential Equation backward in time using scipy.integrate.odeint ? If it is possible, could someone tell me what should be the ar

3条回答
  •  攒了一身酷
    2021-01-15 11:47

    It is not necessary to make a change of variables. Here an example:

    import math
    import numpy
    import scipy
    import pylab as p
    
    from math import *
    from numpy import *
    from scipy.integrate import odeint
    from scipy.interpolate import splrep
    from scipy.interpolate import splev
    
    g1=0.01
    g2=0.01
    w1=1
    w2=1 
    b1=1.0/20.0
    b2=1.0/20.0
    b=1.0/20.0
    c0=0
    c1=0.2
    wf=1
    
    def wtime(t):
      f=1+c0+c1*cos(2*wf*t)
      return f
    
    def dv(y,t):
      return array([y[1], -(wtime(t)+g1*w1+g2*w2)*y[0]+w1*y[2]+w2*y[3], w1*y[2]-g1*w1*y[0], w2*y[3]-g2*w2*y[0]])
    
    tv=linspace(100,0,1000)
    v1zero=array([1,0,0,0])
    v2zero=array([0,1,0,0])
    v1s=odeint(dv,v1zero,tv)
    v2s=odeint(dv,v2zero,tv)
    
    p.plot(tv,v1s[:,0])
    p.show()
    

    I check the result with Wolfram Mathematica (that program can solve backward odes).

提交回复
热议问题