Euler's Method Using Maple
Some Comparisons
> | with(plots): |
> | eq1:=diff(y(x),x)=cos(x); |
> | ini1:=y(0)=0; |
> | dsolve({eq1,ini1},{y(x)}); |
> | AnalSoln:=plot(sin(x),x=0..2*Pi,y=-1.5..1.5,color=blue,thickness=2): |
> | sol:=dsolve({eq1,ini1},{y(x)},type=numeric,method=classical[foreuler],stepsize=Pi/16); |
> | EulerSoln:=odeplot(sol,[x,y(x)],0..2*Pi,thickness=2): |
> | sol(Pi/2); |
> | display(AnalSoln,EulerSoln); |
> | sol2:=dsolve({eq1,ini1},{y(x)},type=numeric,method=classical[foreuler],stepsize=Pi/32); |
> | EulerSoln2:=odeplot(sol2,[x,y(x)],0..2*Pi,thickness=2): |
> | sol2(Pi/2); |
> | display(AnalSoln,EulerSoln2); |
> | sol3:=dsolve({eq1,ini1},{y(x)},type=numeric,method=classical[foreuler],stepsize=Pi/64); |
> | EulerSoln3:=odeplot(sol3,[x,y(x)],0..2*Pi,thickness=2): |
> | sol3(Pi/2); |
> | display(AnalSoln,EulerSoln3); |
> | sol4:=dsolve({eq1,ini1},{y(x)},type=numeric,method=classical[foreuler],stepsize=Pi/128); |
> | EulerSoln4:=odeplot(sol4,[x,y(x)],0..2*Pi,thickness=2): |
> | sol4(Pi/2); |
> | display(AnalSoln,EulerSoln4); |
> |