# ode_solver : unable to convert to float

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I am trying to solve a system of 38 first-order differential equations using ode_solver(). Among many problems, I have a problem with complex numbers. The functions in question are complex functions (equations include conjugate(function)), and initial contitions are also complex numbers.

The error I get is following:

TypeError: Unable to convert 0.0353553390593274 - 0.0353553390593274*I
to float; use abs() or real_part() as desired


0.0353553390593274 - 0.0353553390593274*I is the value of one of the inital conditions. I am rather new to sage, so I wonder if ode_solver() can deal with complex functions and complex numbers as such?

Thank you!

edit retag close merge delete

If you have a specific example, that would be really helpful. If it's quite long, use http://pastebin.com or something to link to.

( 2012-02-13 06:49:38 -0500 )edit

It's REALY long, and it contains lots of abbreviations and definitions within definitions... I doubt it would be very useful. I can describe the system: I have 39 functions (y[0], ..., y[38]) and 39 dependent first-order diferential equations. Functions are defined in the complex ring, the inital values are complex numbers, etc. RHS of equations are complicated combinations of y's. So i write them all down, define range and initial conditions and that's it. In Mathematica I did it with NDSolve, there were absolutly no problems (I have just typed the equations) and the whole job is done in about 2 seconds. Now I am trying to do the same job with Sage. But it turns out it's not that simple :(

( 2012-02-13 07:51:02 -0500 )edit

Can you maybe post a much smaller test case that illustrates the problem?

( 2012-02-13 14:52:58 -0500 )edit

Sort by » oldest newest most voted

This post is a wiki. Anyone with karma >750 is welcome to improve it.

It is not possible to solve complex differential equation with ode_solver. You have to convert n complex differential equations to 2n real differential equations.

more

Thank you for your answer, I had a feeling something like that will be the case :) Can you advise me with the best way to do that conversion? Do I have to do it "by hand" (separating each function f = fRe + fIm, and each value like y0 = y0Re + y0Im) , or is there some routine that can do it?

( 2012-02-13 07:11:59 -0500 )edit

I normally use .real().simplify() and .imag().simplify() to seperate the real and imaginary parts of the function and just redefine the function in terms of 2n variables. I think there might be a more elegant way of doing it. But I don't have anything offhand.

( 2012-02-13 08:16:27 -0500 )edit

This post is a wiki. Anyone with karma >750 is welcome to improve it.

You could just write a Runge-Kutta 4th-order solver in python, and if your system isn't too nasty that will speedily and happily use complex values.

more

So are you saying that the Runge-Kutta methods from GSL in ode_solver we have don't work with complex values at all? Is there anything else in Sage (maybe Maxima?) that does numerical ODEs over complex values?

( 2012-02-24 01:41:36 -0500 )edit

This post is a wiki. Anyone with karma >750 is welcome to improve it.

scipy.integrate.ode hanldes numerical solution of variable coefficient complex valued ODEs, by means of the quite fast 'zvode' fortran routine. see http://docs.scipy.org/doc/scipy/refer...

more