Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python solving differential equation with complex variables

folks,

Is it possible to solve ODE with complex variable in python? The equation I have has the following form

dx/dt = -a x -i y(t)

where y(t) is a known function, a is a known number and i is the root of -1.

I tried to use odeint() but it gives many error messages.

I am guessing odeint() does not work with complex variables. So one way out would be to separate the real and imaginary parts of x and treat the original ODE as two coupled ODEs.

But I am also wondering if there are some more convenient way for this task? Solving ODE/PDE with complex variables is a general problem and it will be quite a hassle to make this complex -> real conversion by hand all the time.

Thanks very much.

like image 376
nos Avatar asked Sep 13 '26 13:09

nos


1 Answers

I'd suggest using scipy.integrate.complex_ode instead of scipy.integrate.odeint which performs the conversion automatically.

like image 196
Tanriol Avatar answered Sep 15 '26 01:09

Tanriol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!