Maple Implementation of 2nd-Order Runge-Kutta Method
for First-order Systems

The following routine implements the second-order Runge-Kutta (improved Euler) method for a system of two first-order linear ordinary equations with initial values . It illustrates the method for the system of equations arising from the second-order linear ODE in Example 2 of Section 3.6 of Florin Diacu, Introduction to Differential Equations/Order and Chaos , p. 136, namely

= , x (1) = 1, x '(1) = 2,

over the interval [1, 2.5] with step size h = 0.1. The substitution y = transforms that to the following system (5, p. 135) of two equations with initial conditions:

= y ,
= ,
x
(1) = 1, y (1) = 2.

Compare the following Maple routine, and the output from executing it, to p. 145 of Diacu .

> n := 15:
A := matrix(n + 2, 3):
A[1, 1] := 't':
A[1, 2] := 'x':
A[1, 3] := 'y':
g := (t, x, y) -> (2/t^2)*x -(2/t)*y;
printf(" ");
t_0 := 1:
x_0 := 1:
y_0 := 2:
h := 0.1:
t := t_0:
x := x_0:
y := y_0:
A[2, 1] := t_0:
A[2, 2] := x_0:
A[2, 3] := y_0:
for i from 2 to n + 1 do
v := x + y*h:
w := y + h*g(t, x, y):
z := y + (h/2)*(g(t, x, y) + g(t+h, v, w)):
t := t + h:
x := x + (h/2)*(y + w):
A[i + 1, 1] := t:
A[i + 1, 2] := x:
A[i + 1, 3] := z:
y := z:
end do:
print(A);

` `

Maple TM is a registered trademark of Waterloo Maple Inc.
Math rendered by WebEQ