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