Ask Your Question
0

ode_solver : unable to convert to float

asked 2012-02-13 06:58:01 +0200

this post is marked as community wiki

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 flag offensive close merge delete

Comments

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.

kcrisman gravatar imagekcrisman ( 2012-02-13 13:49:38 +0200 )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 :(

Hurin gravatar imageHurin ( 2012-02-13 14:51:02 +0200 )edit

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

Jason Grout gravatar imageJason Grout ( 2012-02-13 21:52:58 +0200 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2012-02-13 14:09:46 +0200

this post is marked as community wiki

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.

edit flag offensive delete link more

Comments

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?

Hurin gravatar imageHurin ( 2012-02-13 14:11:59 +0200 )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.

Shashank gravatar imageShashank ( 2012-02-13 15:16:27 +0200 )edit
0

answered 2013-12-19 04:09:55 +0200

this post is marked as community wiki

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...

edit flag offensive delete link more
0

answered 2012-02-24 00:13:20 +0200

this post is marked as community wiki

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.

edit flag offensive delete link more

Comments

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?

kcrisman gravatar imagekcrisman ( 2012-02-24 08:41:36 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-02-13 06:58:01 +0200

Seen: 1,344 times

Last updated: Dec 19 '13