
274 CHAPTER 7. CALCULUS OF VARIATIONS
The governing equation of motion, ode , is obtained by applying the
EulerLagrange command as follows. Because L depends explicitly on t,a
first integral is not generated with the EulerLagrange command.
>
ode:=simplify(-EulerLagrange(L,t,theta(t))[1]/(m*b))=0;
ode := g sin(θ(t)) − aω
2
cos(ωt− θ(t)) + b (
d
2
dt
2
θ(t)) = 0
Since ode is a nonlinear ODE, it must be solved numerically. We will consider
a giant version of Daniel’s toy taking a=1 m and b=3 m. The wheel is rotated
at ω =2 rads/s and g =9.8m/s
2
. The ODE is then displayed in ode2 .
>
a:=1: b:=3: omega:=2: g:=9.8: ode2:=ode;
ode2 := 9.8sin(θ(t)) − 4 cos(2 t − θ(t)) + 3 (
d
2
dt
2
θ(t)) = 0
For the initial condition, let’s take θ(0)= π/6radsand
˙
θ(0)= 0.
>
ic:=theta(0)=Pi/6,D(theta)(0)=0:
Then, ode2 is numerically solved in sol, subject to the initial condition, for
θ(t). The output is given as a listprocedure.
>
sol:=dsolve({ode2,ic},theta(t),type=numeric,
output=listprocedure):
Making use of sol, the next three command lines allow us to evaluate the
horizontal and vertical coordinates of m at an arbitrary time t.
>
Theta:=eval(theta(t),sol):
>
X:=t->eval(x,theta(t)=Theta(t)):
>
Y:=t->eval(y,theta(t)=Theta(t)):
The circle command, found in the plottools library package, is used to plot a
thick red circle of radius a, centered on the origin, representing the wheel’s rim.
>
c:=plottools[circle]([0,0],a,color=red,style=line,
thickness=2):
The line command (also in the plottools package) is used to create an arrow
operator l to draw the pendulum rod as a thick green line at arbitrary time t.
>
l:=t->plottools[line]([a*cos(omega*t),a*sin(omega*t)],
[X(t),Y(t)],color=green,thickness=2):
The pointplot command is used to form an operator p to draw size 16 blue
circles at the pivot point and at m at arbitrary time t.
>
p:=t->pointplot({[a*cos(omega*t),a*sin(omega*t)],
[X(t),Y(t)]},symbol=circle,symbolsize=16,color=blue):
The three graphs are superimposed in gr||i at a time t =0.1 i,andadoloop
used to generate plots for i from 0 to 200, i.e, for t=0 to 20 s.
>
for i from 0 to 200 do
>
t:=0.1*i:
>
gr||i:=display({c,p(t),l(t)},labels=["x","y"]):
>
end do: