Maple Implementation of Euler's Method

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 the first-order linear ordinary initial-value problem


= , x (0) = 1.

Following Florin Diacu, Introduction to Differential Equations/Order and Chaos , Sections 2.6 and 2.7, this routine uses step size h = 0.1 on the interval [0, 1.5]. (See p. 70.)

> f := (t, x) -> 2*t*x + exp(t^2);
printf (" ");
t_0 := 0:
x_0 := 1:
h := 0.1:
n := 15:
t := t_0:
x := x_0:
A := matrix(n + 2, 2):
A[1, 1] := 't':
A[1, 2] := 'x':
A[2, 1] := t_0:
A[2, 2] := x_0:
for i from 2 to n + 1 do
x := x + h*f(t, x):
t := t + h:
A[i + 1, 1] := t:
A[i + 1, 2] := x:
end do:
print(A);

 

>

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