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
as a function of
t
and
y
,
. 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:
.
The formula above leads to the following discrete iteration scheme:
and
. This process is known as Euler's method.
Examples
Example 6.1.1
Use Euler's Method to solve the initial value problem
, 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
,
, 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;
>
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:
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)];
> pointplot(points);
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));
> sol2:=subs(sol1, y(t));
> p1:=pointplot(points):
> p2:=plot(sol2, t=0..2):
> display([p1, p2]);
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]);
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));
> ic:=y(0)=1;
> e1:=dsolve({deq, ic}, y(t), type=numeric, output=listprocedure);
> sol:=subs(e1, y(t));
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]);
As you can see, the professonal RK 4-5 method produced a near perfect result.
>