简体   繁体   中英

Python: Solving a second order differential equation with complex initial conditions

I want to solve a second order differential equation with variable coefficients by using something like odeint. The problem with this one is that it doesn't work if the initial conditions are complex (which is the case now).

Do you know a way to solve the aforementioned equation with something similar to odeint?

odeint does not accept complex variables. You could use: the newer solver, solve_ivp ; the older ode class with the "zvode" integrator; or odeintw , a wrapper of odeint that I wrote that handles complex-valued and matrix-valued differential equations.

You could always work with the real components ( odeint convention)

def odesys(u,t):
    z = u[0]+1j*u[1]
    dz = u[2]+1j*u[3]
    d2z = f(t,z,dz)
    return [ dz.real, dz.imag, d2z.real, d2z.imag ]

where f stands for the explicit form of the second order ODE.

If I remember correctly, one of the methods ("vzode"?) that you can use in scipy.integrate.ode works directly with complex state variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM