MATH 134 -- Intensive Calculus for Science 2
An Euler's Method Example
April 5, 2006
We study the approximate solution of
y
' =
with initial condition y (0) = 1 . First, we load the plotting
packages. Then we do 10 steps of Euler's method with
to approximate the solution:
> | with(DEtools): |
> | with(plots): |
> | xl[0]:=0; yl[0]:=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; |
> | SField:=DEplot(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(SField,Pts,Lines); |
We would get a better approximation with smaller
. 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(SField,Pts,Lines); |
> |