Page 16-71
The following screens show the RPN stack before and after applying function
RKF for the differential equation dy/dx = x+y,
ε
= 0.001,
∆
x = 0.1.
After applying function RKF, variable
@@@y@@@
contains the value 4.3880...
Function RRK
This function is similar to the RKF function, except that RRK (Rosenbrock and
Runge-Kutta methods) requires as the list in stack level 3 for input not only the
names of the independent and dependent variables and the function defining
the differential equation, but also the expressions for the first and second
derivatives of the expression. Thus, the input stack for this function will look as
follows:
3: {‘x’, ‘y’, ‘f(x,y)’ ‘
∂
f/
∂
x’ ‘
∂
f/
∂
y’ }
2: {
ε
∆
x }
1: x
final
The value in the first stack level is the value of the independent variable where
you want to find your solution, i.e., you want to find, y
final
= f
s
(x
final
), where f
s
(x)
represents the solution to the differential equation. The second stack level may
contain only the value of
ε
, and the step
∆
x will be taken as a small default
value. After running function
@@RKF@@
, the stack will show the lines:
2: {‘x’, ‘y’, ‘f(x,y)’ ‘
∂
f/
∂
x’ ‘
∂
f/vy’ }
1: {
ε
∆
x }
The value of the solution, y
final
, will be available in variable
@@@y@@@
.
This function can be used to solve so-called “stiff” differential equations.
RKF solution
Actual solution
x y x y
0 0 x
init
y
init
x
final
y
final
x
init
+ x
final
y
init
+ y
final