behavior of runge-kutta function rk in single step operation inside loop
Subject: behavior of runge-kutta function rk in single step operation inside loop
From: Edwin Woollett
Date: Mon, 8 Jul 2013 15:52:10 -0700
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