Math 277

Elementary Differential Equations

Spring 2001

Dr. Constant J. Goutziers

Department of Mathematical Sciences

goutzicj@oneonta.edu

Lesson 6

Euler's Method

6.1 A simple numerical technique, Euler's Method

A fi rst order differential equation defines [Maple Math] as a function of t and y , [Maple Math] . This means that we can give the linear approx imation of the solution function y(t) using the first two terms of its taylor series:

[Maple Math] .

The formula above leads to the following discrete iteration scheme:

[Maple Math] and [Maple Math] . This process is known as Euler's method.

Examples

Example 6.1.1

Use Euler's Method to solve the initial value problem [Maple Math] , y(0)=1 on the interval [0, 2]. Use a stepsize h=0.1 , sketch your result and compare it with the exact solution of this initial value problem. Then generate another numeric solution using the RK 4-5 method provided by the dsolve command with type = numeric option.

We code f(t, y), the stepsize h, the starting values [Maple Math] , [Maple Math] , and iterate. In order not to disturb the variables t and y we will use tp and yp as iteration variables.

> with(plots):

> h:=0.1; f:=(t, y)->-2*t*y^2; tp[0]:=0.0; yp[0]:=1.0;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> for k from 0 to 20 do
tp[k+1]:=tp[k]+h;
yp[k+1]:=yp[k]+h*f(tp[k], yp[k]);
print(evalf([k, tp[k], yp[k]], 4));
od:

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]


[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Compare these values to table 1.7 of page 59b in the textbook. Of course we can nicely graph these points.

> points:=[seq([tp[k], yp[k]], k=0..20)];

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> pointplot(points);

[Maple Plot]

Next we quickly compute the exact solution, and graph it together with the result of Euler's method in one picture.

> sol1:=dsolve({diff(y(t), t)=f(t, y(t)), y(0)=1}, y(t));

[Maple Math]

> sol2:=subs(sol1, y(t));

[Maple Math]

> p1:=pointplot(points):

> p2:=plot(sol2, t=0..2):

> display([p1, p2]);

[Maple Plot]

Alternatively we can display the result of Euler's method in line mode.

> p1:=pointplot(points, style=line, color=black):

> p2:=plot(sol2, t=0..2):

> display([p1, p2]);

[Maple Plot]

Finally we compare the exact solution with the output of the dsolve routine which uses a professional adaptive stepsize Runge-Kutta sheme.

> deq:=diff(y(t), t)=f(t, y(t));

[Maple Math]

> ic:=y(0)=1;

[Maple Math]

> e1:=dsolve({deq, ic}, y(t), type=numeric, output=listprocedure);

[Maple Math]

> sol:=subs(e1, y(t));

[Maple Math]

Sketch the exact solution in thick yellow and superimpose the result of the numeric Runge-Kutta scheme in thin black.

> p1:=plot(sol2, t=0..2, thickness=7, color=yellow):

> p2:=plot('sol(t)', t=0..2, color=black):

> display([p2, p1]);

[Maple Plot]

As you can see, the professonal RK 4-5 method produced a near perfect result.

>