> #sfb Numerical DE solver for ode's using maple > # we want to solve = <-y, x> numberically > # It is easy to check it has a solution < a cos(t), a sin(t) > > with(plots):with(DEtools): > ODE1:=diff(x(t),t)=-y(t); > ODE2:=diff(y(t),t)=x(t); > SYS:=[ODE1,ODE2]; > VARS:=[x(t),y(t)]; > I_C:=[[x(0)=1,y(0)=0]]; > T_RANGE:=t=0..6; > STEP:=stepsize=0.1; > XvsT:=DEplot(SYS,VARS,T_RANGE,I_C,STEP,scene=[t,x(t)],linecolor=blue): > YvsT:=DEplot(SYS,VARS,T_RANGE,I_C,STEP,scene=[t,y(t)],linecolor=red): > XvsY:=DEplot(SYS,VARS,T_RANGE,I_C,STEP,scene=[x(t),y(t)],linecolor=green,color=red): > #The next comand "displays" the first two plots together > display(XvsT,YvsT,title="Solution vs time"); > #The next plot is constrained so the x y scales are the same > display(XvsY,title="Trajectory --- Phase space",scaling=constrained); > # compare the "good" solver with "Euler -- dumb version" Forward Euler > DumbXvsT:=DEplot(SYS,VARS,T_RANGE,I_C,scene=[t,x(t)],linecolor=yellow,method=classical[foreuler]): > display(XvsT,DumbXvsT,title="Yellow Line is Euler (unimproved)"); > DumbXvsY:=DEplot(SYS,VARS,T_RANGE,I_C,scene=[x(t),y(t)],linecolor=yellow,method=classical[foreuler]): > display(XvsY,DumbXvsY,title="Phase plane: Yellow Line is Euler (unimproved)",scaling=constrained); > # add a text label to the YvsT at first max (Pi/2,1) and moved it slightly > display(YvsT,textplot([Pi/2+0.1,1,"First Max at (Pi/2,1)"],align={ABOVE,RIGHT})); >