integrating a stateful function with rk()



The example I gave was a greatly simplified
 example to illustrate the problem.? It is not representative of the actual stateful function I am trying to pass to rk().? I realize that rk() calls the function multiple times for each time step (I have written rk4 routines before).


Maxima is my go-to tool of choice; I make every effort to find out if it can efficiently and effectively do the job before I give up and use something else.

In this case, I will probably wind up using Octave because it supports initialized static local variables.



________________________________
 From: Stavros Macrakis <macrakis at alum.mit.edu>
To: Ether Jones <maxima at etherjones.us> 
Cc: maxima <maxima at math.utexas.edu> 
Sent: Wednesday, September 18, 2013 3:36 PM
Subject: Re: [Maxima] integrating a stateful with rk()
 


As a general rule, you shouldn't expect that a routine that takes a functional argument will call the function in any particular order, or any particular number of times, so modelling a "stateful" function using a variable like this is not reliable. ?Try rk('(print(x)),t,0,[x,0,1,.25]) to see the values at which rk evaluates the function.

? ? ? ? ? ? -s



On Wed, Sep 18, 2013 at 9:49 AM, Ether Jones <maxima at etherjones.us> wrote:


>
>
>
>What is the proper method in Maxima to integrate a stateful function with rk()?
>
>
>Below is a greatly simplified example to illustrate the problem. %i4 gives the wrong answer, and %i5 crashes.
>
>
>
>Thank you.
>
>
>
>------------------ begin example -----------------------------
>
>
>Maxima 5.27.0 http://maxima.sourceforge.net
>using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (a.k.a. GCL)
>Distributed under the GNU Public License. See the file COPYING.
>Dedicated to the memory of William Schelter.
>The function bug_report() provides bug reporting information.
>
>(%i1) load("dynamics")$
>
>(%i2) r:0$
>
>(%i3) f(x):=(if r<5 then r:r+1, r)$
>
>(%i4) rk(f(x),x,0,[t,0,1,0.2]);
>
>(%o4) [[0, 0], [0.2, 0.2], [0.4, 0.4], [0.6, 0.6], [0.8, 0.8], [1.0, 1.0]]
>
>(%i5) rk('(f(x)),x,0,[t,0,1,0.2]);
>
>Expecting a number when the initial state is replaced in the equations, but instead found:
>?r
>#0:
 rk(odes=f(x),state=x,initial=0,domain=[t,0,1,0.2])
>?-- an error. To debug this try: debugmode(true);
>
>
>-------------------- end --------------------------------------
>
>_______________________________________________
>Maxima mailing list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima
>
>