[sage-support] Sage/Maxima desolve_rk4 problem

103 views
Skip to first unread message

jvkersch

unread,
Apr 19, 2010, 10:38:09 AM4/19/10
to sage-support
Hi all,

Technically, this is not a Sage problem, but I figured I would post it
here anyway since others might have run into the same problem, and I'm
also trying to solve the problem using some Sage/python trickery.

The problem concerns the use of symbolic constants such as pi in
numerical integration with desolve_rk4. The following code is adapted
from the manual page for desolve_rk4 -- note especially the constant
pi in the specification of the ODE:

x, y = var('x y')
desolve_rk4(x*y*(2-y) + pi, y, ics=[0, 1], end_points=1, step=0.5)

and raises the following error:

TypeError: Error executing code in Maxima
CODE:
sage1 : rk(%pi-x*(y-2)*y,y,1,[x,0,1,0.500000000000000]) $
Maxima ERROR: Inconsistent set of equations and variables

This same error occurs whenever you have an ODE with pi in it, no
matter how simple. The error persists when directly running this
command in Maxima, but works fine (both in Sage and Maxima) when
manually replacing pi by 3.14... Since I don't know any Maxima, I
have no idea of what the problem could be or where to look.

So, I was wondering if there is a way to have Sage replace the %pi
when invoking Maxima by the corresponding numerical value? I guess I
could store my ODE in a string and use a regular expression to get rid
of any pi's myself, but that seems very inelegant. Is there anything
you would recommend?

Thanks a lot,
Joris

--
To post to this group, send email to sage-s...@googlegroups.com
To unsubscribe from this group, send email to sage-support...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Robert Dodier

unread,
Apr 19, 2010, 2:52:18 PM4/19/10
to sage-support, Maxima Mailing List
Looks like the rk function in Maxima doesn't try hard enough to
float-ify its argument. I haven't looked at the code, but
maybe rk can call COERCE-FLOAT-FUN to construct a
function to evaluate the expression. At least that would
bring it into line with other Maxima functions which
evaluate expressions to numbers (e.g. plotting, quadpack).

Follow-ups to the Maxima mailing list. I've appended
the original message below.

best

Robert Dodier

PS.

jvkersch

unread,
Apr 20, 2010, 3:39:41 AM4/20/10
to sage-support
Thanks Robert, this seems to be the problem. I wish I were a lisp
programmer so that I could dive into Maxima and put in a call to
coerce-float-fun myself, but while I'm eager to tinker with this, I'm
not sure I can be succesful in a reasonable amount of time.

In the meantime, I will write my own little RK4 routine in python --
while browsing the mailing list yesterday I read about "fast_float",
so I have good hopes that the result will be fast. Sage is so
powerful!

Thanks a lot for your time,
Joris Vankerschaver

ma...@mendelu.cz

unread,
Apr 20, 2010, 9:20:03 AM4/20/10
to sage-support


On 20 dub, 09:39, jvkersch <joris.vankerscha...@gmail.com> wrote:
> Thanks Robert, this seems to be the problem. I wish I were a lisp
> programmer so that I could dive into Maxima and put in a call to
> coerce-float-fun myself, but while I'm eager to tinker with this, I'm
> not sure I can be succesful in a reasonable amount of time.
>
> In the meantime, I will write my own little RK4 routine in python --
> while browsing the mailing list yesterday I read about "fast_float",
> so I have good hopes that the result will be fast. Sage is so
> powerful!
>

You may also try Octave or ode_solve. (run ode_solve? command to see
the help)

Robert

jvkersch

unread,
Apr 21, 2010, 1:47:26 PM4/21/10
to sage-support
Dear Robert,

Thanks a lot for the suggestion. After typing in "ode_solve", the tab-
completion guided me to the class "ode_solver", which also works like
a charm. This is the reason for my late reply: I was so glad to get
everything working that I lost all track of time...

I know this is not the place for a panegyric on Sage, but I've been
playing around with Sage for only a week and it is amazing. I'm
behind on all my work while I'm redoing all my code in Sage, and I
even wrote a small differential forms package, all in one week :)

Thanks a lot!

Joris
Reply all
Reply to author
Forward
0 new messages