MapleEuler.mws

Euler's Method

dy/dx = cos(x)

y(0) = 0, step size of Pi/8

>    with(plots):

>    solns:=array(1..33);

solns := array(1 .. 33,[])

>    solns[1]:=(0,0):

>    y:=0:

>    for i from 2 to 33 do

>    y:=y+cos((i-2)*Pi/8)*Pi/8:solns[i]:=((i-1)*Pi/8,y):

>    end do:

>    solnss:=convert(solns,listlist):

>    EulerSoln:=pointplot(solnss,symbol=circle,symbolsize=12,color=red):

>    AnalyticalSoln:=plot(sin(x),x=0..4*Pi,thickness=3,color=blue):

>    display(EulerSoln,AnalyticalSoln);

[Maple Plot]

y(0) = 0, step size Pi/16

>    solns2:=array(1..65);

solns2 := array(1 .. 65,[])

>    solns2[1]:=(0,0):

>    y:=0:

>    for i from 2 to 65 do

>    y:=y+cos((i-2)*Pi/16)*Pi/16:solns2[i]:=((i-1)*Pi/16,y):

>    end do:

>    solns2s:=convert(solns2,listlist):

>    EulerSoln:=pointplot(solns2s,symbol=circle,symbolsize=12,color=red):

>    AnalyticalSoln:=plot(sin(x),x=0..4*Pi,thickness=3,color=blue):

>    display(EulerSoln,AnalyticalSoln);

[Maple Plot]

y(0) = 1, step size Pi/16

>    solns3:=array(1..65);

solns3 := array(1 .. 65,[])

>    solns3[1]:=(0,1):

>    y:=1:

>    for i from 2 to 65 do

>    y1:=y;y:=y1+cos((i-2)*Pi/16)*Pi/16;solns3[i]:=((i-1)*Pi/16,y);

>    end do:

>    solns3[15];

7/8*Pi, 1+1/16*Pi+1/16*cos(1/16*Pi)*Pi+1/16*cos(1/8*Pi)*Pi

>    solns3s:=convert(solns3,listlist):

>    EulerSoln:=pointplot(solns3s,symbol=circle,symbolsize=12,color=red):

>    AnalyticalSoln:=plot(sin(x)+1,x=0..4*Pi,thickness=3,color=blue):

>    display(EulerSoln,AnalyticalSoln);

[Maple Plot]

>