Reputation: 20870
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.
Upvotes: 3
Views: 6309
Reputation: 1206
I'd suggest using scipy.integrate.complex_ode
instead of scipy.integrate.odeint
which performs the conversion automatically.
Upvotes: 5