Solve an implicit ODE (differential algebraic equation DAE)

前端 未结 2 595
独厮守ぢ
独厮守ぢ 2020-12-30 14:23

I\'m trying to solve a second order ODE using odeint from scipy. The issue I\'m having is the function is implicitly coupled to the second order term, as seen in the simplif

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 15:01

    Quite Old , but worth updating so it may be useful for anyone, who stumbles upon this question. There are quite few packages currently available in python that can solve implicit ODE. GEKKO (https://github.com/BYU-PRISM/GEKKO) is one of the packages, that specializes on dynamic optimization for mixed integer , non linear optimization problems, but can also be used as a general purpose DAE solver.

    The above "pretend physics" problem can be solved in GEKKO as follows.

    m= GEKKO()
    m.time = np.linspace(0,100,101)
    F_l = m.Param(value=1000)
    mass = m.Param(value =1000)
    m.options.IMODE=4
    m.options.NODES=3
    F_r = m.Var(value=0)
    x = m.Var(value=0)
    v = m.Var(value=0,lb=0)
    a = m.Var(value=5,lb=0)
    m.Equation(x.dt() == v)
    m.Equation(v.dt() == a)
    m.Equation (F_r ==  (((1-a)/3)**2 + (2*(1+a)/3)**2 * v)) 
    m.Equation (a == (1000 - F_l)/mass)
    m.solve(disp=False)
    plt.plot(x)
    

提交回复
热议问题