behavior of runge-kutta function rk in single step operation inside loop



Hi Ted,

it seems to me that we experience the result of a floating point conversion
error and that 0.3 + dt is not within the range given by ['t, t, t+dt, dt].

With a by 1e-15 slightly extended range the steps are as expected.

soln2 : rk (-'n, 'n, n, ['t, t, t+dt+1e-15, dt]);

I draw the conclusion that rk cannot guarantee that the right end of the
range is always reached. Don't know if this a bug or a typical numerical
problem.

Volker van Nek



2013/7/9 Edwin Woollett <woollett at charter.net>

> When trying to use the runge-kutta function rk
> in single step mode, inside a loop, I find
> peculiar behavior after a few steps. I am solving the
> decay equation dn/dt = -n, with n(0) = 1, with the
> analytic soln exp(-t) as a test case to get my feet wet.
>
> (%i1) [dt, t, n] : [0.1, 0, 1];
> (%o1) [0.1, 0, 1]
>
> /* lots of debug printouts here...  */
>
> (%i2) for j thru 5 do
>       (print (j),
>        soln2 : rk (-'n, 'n, n, ['t, t, t+dt, dt]),
>        print (soln2),
>        soln1 : second (soln2),
>        print (soln1),
>        t : soln1[1],
>        n : soln1[2],
>        display (t, n))$
>
>
> 1 [[0,1],  [0.1, 0.904837]] [0.1, 0.904837] t = 0.1
>
> n = 0.904837
>
> 2 [[0.1,0.904837], [0.2, 0.818731]] [0.2, 0.818731] t = 0.2
>
> n = 0.818731
>
> 3 [[0.2,0.818731], [0.3, 0.740818]] [0.3, 0.740818] t = 0.3
>
> n = 0.740818
>
> 4 [[0.3, 0.740818]] second: no such element in [[0.3,0.740818]]
> -- an error. To debug this try: debugmode(true);
> ------------------------------**-------
> so do step 4 by hand:
>
> (%i3) [t, n] : [0.3, 0.740818];
> (%o3) [0.3, 0.740818]
>
> (%i4) rk (-'n, 'n, n, ['t, t, t+dt, dt]);
> (%o4) [[0.3, 0.740818],[0.4, 0.67032]]
> ------------------------------**-----------------
> so interactively, rk has no problem, but inside
> the loop I have trouble at j = 4.
>
>
> (%i6) display2d:true$
> (%i7) build_info();
> (%o7) Maxima version: "5.28.0-2"
> Maxima build date: "2012-08-27 23:16:48"
> Host type: "i686-pc-mingw32"
> Lisp implementation type: "GNU Common Lisp (GCL)"
> Lisp implementation version: "GCL 2.6.8"
>
> Ted Woollett
>
>
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>