Maple Implementation of Euler's Method for Systems

Copyright 2002 by James F. Hurley, University of Connecticut Department of Mathematics, 196 Auditorium Road, Unit 3009, Storrs CT 06269-3009. All rights reserved.

The following routine implements Euler's method for a system of two first-order linear ordinary equations with initial values . It implements the Euler method for the system of equations arising from the second-order linear ODE in Example 1 of Section 3.6 of Florin Diacu, Introduction to Differential Equations/Order and Chaos , p. 135, 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. 144 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 + h*y:
w := y + g(t, x, y)*h:
t := t + h:
A[i + 1, 1] := t:
A[i + 1, 2] := v:
A[i + 1, 3] := w:
x := v:
y := w:
end do:
print(A);

 

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