MATH 134 -- Intensive Calculus for Science 2
April 19, 2002
An Euler's Method Example
We apply Euler's Method to approximate the solution of y ' = 3 - y
with y(0) = 1, using a step-size of h = .5
> restart;
> f:=(x,y)->3 - y;
> xpt[0]:=0: ypt[0]:=1:
> for i to 8 do
> ypt[i]:=ypt[i-1] + f(xpt[i-1],ypt[i-1])*(.5);
> xpt[i]:=xpt[i-1] + (.5);
> end do:
> points:=[seq([xpt[i],ypt[i]],i=0..8)];
> with(DEtools): with(plots):
Warning, the name changecoords has been redefined
> slopefield:=DEplot(diff(y(x),x)=3-y(x),y(x),x=-1..5,y=0..4):
> pointplot:=plot(points,color=black,style=point,symbol=circle):
> lineplot:=plot(points,color=black):
> display(pointplot,slopefield,lineplot);
Taking the step-size h even smaller would yield even better results.