ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 19 Dec 2013 04:09:55 +0100ode_solver : unable to convert to floathttps://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/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!Mon, 13 Feb 2012 06:58:01 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/Comment by Jason Grout for <p>I am trying to solve a system of 38 first-order differential equations using <code>ode_solver()</code>. 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.</p>
<p>The error I get is following:</p>
<pre><code>TypeError: Unable to convert 0.0353553390593274 - 0.0353553390593274*I
to float; use abs() or real_part() as desired
</code></pre>
<p><code>0.0353553390593274 - 0.0353553390593274*I</code> is the value of one of the inital conditions. I am rather new to <code>sage</code>, so I wonder if <code>ode_solver()</code> can deal with complex functions and complex numbers as such?</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20286#post-id-20286Can you maybe post a much smaller test case that illustrates the problem?Mon, 13 Feb 2012 21:52:58 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20286#post-id-20286Comment by kcrisman for <p>I am trying to solve a system of 38 first-order differential equations using <code>ode_solver()</code>. 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.</p>
<p>The error I get is following:</p>
<pre><code>TypeError: Unable to convert 0.0353553390593274 - 0.0353553390593274*I
to float; use abs() or real_part() as desired
</code></pre>
<p><code>0.0353553390593274 - 0.0353553390593274*I</code> is the value of one of the inital conditions. I am rather new to <code>sage</code>, so I wonder if <code>ode_solver()</code> can deal with complex functions and complex numbers as such?</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20298#post-id-20298If you have a specific example, that would be really helpful. If it's quite long, use http://pastebin.com or something to link to.Mon, 13 Feb 2012 13:49:38 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20298#post-id-20298Comment by Hurin for <p>I am trying to solve a system of 38 first-order differential equations using <code>ode_solver()</code>. 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.</p>
<p>The error I get is following:</p>
<pre><code>TypeError: Unable to convert 0.0353553390593274 - 0.0353553390593274*I
to float; use abs() or real_part() as desired
</code></pre>
<p><code>0.0353553390593274 - 0.0353553390593274*I</code> is the value of one of the inital conditions. I am rather new to <code>sage</code>, so I wonder if <code>ode_solver()</code> can deal with complex functions and complex numbers as such?</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20291#post-id-20291It'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 :(
Mon, 13 Feb 2012 14:51:02 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20291#post-id-20291Answer by fmonegaglia for <p>I am trying to solve a system of 38 first-order differential equations using <code>ode_solver()</code>. 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.</p>
<p>The error I get is following:</p>
<pre><code>TypeError: Unable to convert 0.0353553390593274 - 0.0353553390593274*I
to float; use abs() or real_part() as desired
</code></pre>
<p><code>0.0353553390593274 - 0.0353553390593274*I</code> is the value of one of the inital conditions. I am rather new to <code>sage</code>, so I wonder if <code>ode_solver()</code> can deal with complex functions and complex numbers as such?</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?answer=15842#post-id-15842scipy.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/reference/generated/scipy.integrate.ode.html Thu, 19 Dec 2013 04:09:55 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?answer=15842#post-id-15842Answer by mhampton for <p>I am trying to solve a system of 38 first-order differential equations using <code>ode_solver()</code>. 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.</p>
<p>The error I get is following:</p>
<pre><code>TypeError: Unable to convert 0.0353553390593274 - 0.0353553390593274*I
to float; use abs() or real_part() as desired
</code></pre>
<p><code>0.0353553390593274 - 0.0353553390593274*I</code> is the value of one of the inital conditions. I am rather new to <code>sage</code>, so I wonder if <code>ode_solver()</code> can deal with complex functions and complex numbers as such?</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?answer=13295#post-id-13295You 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. Fri, 24 Feb 2012 00:13:20 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?answer=13295#post-id-13295Comment by kcrisman for <p>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. </p>
https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20250#post-id-20250So 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?Fri, 24 Feb 2012 08:41:36 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20250#post-id-20250Answer by Shashank for <p>I am trying to solve a system of 38 first-order differential equations using <code>ode_solver()</code>. 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.</p>
<p>The error I get is following:</p>
<pre><code>TypeError: Unable to convert 0.0353553390593274 - 0.0353553390593274*I
to float; use abs() or real_part() as desired
</code></pre>
<p><code>0.0353553390593274 - 0.0353553390593274*I</code> is the value of one of the inital conditions. I am rather new to <code>sage</code>, so I wonder if <code>ode_solver()</code> can deal with complex functions and complex numbers as such?</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?answer=13270#post-id-13270It is not possible to solve complex differential equation with ode_solver. You have to convert n complex differential equations to 2n real differential equations.Mon, 13 Feb 2012 14:09:46 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?answer=13270#post-id-13270Comment by Shashank for <p>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.</p>
https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20290#post-id-20290I 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.Mon, 13 Feb 2012 15:16:27 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20290#post-id-20290Comment by Hurin for <p>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.</p>
https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20293#post-id-20293Thank 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?Mon, 13 Feb 2012 14:11:59 +0100https://ask.sagemath.org/question/8714/ode_solver-unable-to-convert-to-float/?comment=20293#post-id-20293