MATH 371 -- Numerical Analysis

Slope Fields and Euler's Method

November 14, 2001

Euler's Method is one way to approximate solutions of a differential equation

dy/dt = f(t,y) . Starting from a given ( t[0], y[0] ), and with a given step size

h , we compute further points on an approximate solution graph by the

formulas:

t[i] = t[i-1]+h

w[i] = w[i-1]+f(t[i-1],w[i-1])*h

( w[i] is the approximation to the value of the exact solution at t = t[i] ),

repeated as often as desired (often, you keep going until x[i] reaches some desired

stopping value). In Maple, this computation can be done as follows. Say we want

to approximate solutions of dy/dt = 3*t^2-y with the initial condition (t[0], y[0]) = (0, 1)

> with(DEtools):

> f:=(t,y) -> 3*t^2-y:

> EulerT[0]:=0: EulerW[0]:=1: h:=.25:

> for i to 4 do EulerT[i]:=EulerT[i-1] + h; EulerW[i]:=EulerW[i-1]+f(EulerT[i-1],EulerW[i-1])*h; end do:

> pts:=[[EulerT[0],EulerW[0]],[EulerT[1],EulerW[1]],[EulerT[2],EulerW[2]],[EulerT[3],EulerW[3]],[EulerT[4],EulerW[4]]]:

> ptsplot1:=plot(pts,color=BLUE):

> ptsplot2:=plot(pts,style=point,color=BLACK,symbol=BOX):

> deplot:=DEplot(diff(y(t),t)=3*t^2-y(t),y(t),t=0..1,y=0..1.5,[[y(0)=1]],linecolor=BLACK,arrows=SLIM):

> with(plots):

The following plot shows:

1) Maple's approximate solution graph (the heavy line)

2) The Euler approximation generated above (the boxes),

which are connected by lighter lines

> display({ptsplot1,ptsplot2,deplot});

>

[Maple Plot]

In fact, Maple's DEplot command uses a more sophisticated numerical method

and generates a list of approximate points on the solution graph and "connects the

dots" as here to draw the graph!