MATH 132 -- Calculus for Physical and Life Science 2 

An Euler's Method Example 

March 12, 2008 

 

We study the approximate solution of  y' = Typesetting:-mrow(Typesetting:-mi( 

with initial condition  y(0) = 1.  First, we load the plotting 

packages.  Then we do 10 steps of Euler's method with  

Typesetting:-mrow(Typesetting:-mi(  to approximate the solution: 

> with(DEtools):
 

> with(plots):
 

> xl[0]:=0; yl[0]:=1;
 

 

0
1 (1)
 

> for i to 10 do
  xl[i]:=xl[i-1]+.1;
  yl[i]:= eval(yl[i-1]+(xl[i-1]^2+yl[i-1]^2)*(.1));
end do;
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

.1
1.1
.2
1.222
.3
1.3753284
.4
1.573481221
.5
1.837065536
.6
2.199546514
.7
2.719347001
.8
3.507831812
.9
4.802320214
1.0
7.189548158 (2)
 

> DirField:=dfieldplot(diff(y(x),x)= x^2 + y(x)^2,[y(x)],x=-.1..1,y=0..10):
 

> Pts:=plot([seq([xl[i],yl[i]],i=0..10)],style=point,symbol=circle,color=blue):
 

> Lines:=plot([seq([xl[i],yl[i]],i=0..10)],color=black):
 

> display(DirField,Pts,Lines);
 

Plot_2d
 

We would get a better approximation with smaller Typesetting:-mrow(Typesetting:-mi(.  For instance, with  .01: 

> xl[0]:=0: yl[0]:=1:
 

> for i to 100 do
  xl[i]:=xl[i-1]+.01;
  yl[i]:= eval(yl[i-1]+(xl[i-1]^2+yl[i-1]^2)*(.01));
end do:
 

> Pts:=plot([seq([xl[i],yl[i]],i=0..100)],style=point,symbol=circle,color=blue):
 

> Lines:=plot([seq([xl[i],yl[i]],i=0..100)],color=black):
 

> display(DirField,Pts,Lines);
 

Plot_2d
 

>