The Oscillating Pendulum
Linear and Non-Linear Models
Truncated series solutions to the non-linear model are graphed in blue (SeriesSoln). The analytical solution to the linear model is graphed in red (AnalSoln). Note the different initial condition in this example.
> | ode:=diff(y(x),x,x)+sin(y(x))=0; |
> | Order:=12; |
> | dsolve({ode,y(0)=Pi/3,D(y)(0)=0},y(x),type=series); |
> | rhs(%); |
> | poly:=convert(%,polynom); |
> | with(plots):AnalSoln:=plot((Pi/3)*cos(x),x=0..Pi,color=red): |
Warning, the name changecoords has been redefined
> | SeriesSoln:=plot(poly,x=0..Pi,y=-1.5..1.2,color=blue): |
> | display(SeriesSoln,AnalSoln); |
> | Order:=16; |
> | dsolve({ode,y(0)=Pi/3,D(y)(0)=0},y(x),type=series); |
> | rhs(%); |
> | poly:=convert(%,polynom); |
> | with(plots):AnalSoln:=plot((Pi/3)*cos(x),x=0..Pi,color=red): |
> | SeriesSoln:=plot(poly,x=0..Pi,y=-1.5..1.2,color=blue): |
> | display(SeriesSoln,AnalSoln); |
> | Order:=20; |
> | dsolve({ode,y(0)=Pi/3,D(y)(0)=0},y(x),type=series); |
> | rhs(%); |
> | poly:=convert(%,polynom); |
> | with(plots):AnalSoln:=plot((Pi/3)*cos(x),x=0..9*Pi/8,color=red): |
> | SeriesSoln:=plot(poly,x=0..9*Pi/8,y=-1.5..1.2,color=blue): |
> | display(SeriesSoln,AnalSoln); |
> | Order:=24; |
> | dsolve({ode,y(0)=Pi/3,D(y)(0)=0},y(x),type=series); |
> | rhs(%); |
> | poly:=convert(%,polynom); |
> | with(plots):AnalSoln:=plot((Pi/3)*cos(x),x=0..9*Pi/8,color=red): |
> | SeriesSoln:=plot(poly,x=0..9*Pi/8,y=-1.5..1.2,color=blue): |
> | display(SeriesSoln,AnalSoln); |
> | Order:=32; |
> | dsolve({ode,y(0)=Pi/3,D(y)(0)=0},y(x),type=series); |
> | rhs(%); |
> | poly:=convert(%,polynom); |
> | with(plots):AnalSoln:=plot((Pi/3)*cos(x),x=0..9*Pi/8,color=red): |
> | SeriesSoln:=plot(poly,x=0..9*Pi/8,y=-1.5..1.2,color=blue): |
> | display(SeriesSoln,AnalSoln); |
> |