Pendulum - Purdue Engineering

A Pendulum Problem with Simulink
1
A simple pendulum
Figure 1: The pendulum
Consider a particle of mass m connected to the end of a pendulum of length l swinging
in the x-y plane; see Figure 1. Assume that the mass at the end of the pendulum is attached
by a string or massless rod of length l to the origin in the x-y plane. Let θ be the angle
between the y axis and the string supporting the pendulum. A positive θ corresponds to the
pendulum being in the right half plane. The position of the pendulum is given by
[
]
[
]
l sin(θ)
l cos(θ)
r=
and ṙ =
θ̇.
(1.1)
−l cos(θ)
l sin(θ)
Since the kinetic energy T = m∥ṙ∥2 /2, we see that T = ml2 θ̇2 /2. The potential energy is
given by V = −mgl cos(θ). Notice that the potential energy is mg times the y coordinate of
the position r. Hence the Lagrangian L = T − V is given by
ml2 θ̇2
+ mgl cos(θ).
L=
2
Here the generalized coordinate is q = θ. Using Lagrange’s equations, dtd ∂L
−
∂ q̇
arrive at
d
d ∂L ∂L
= ml2 θ̇ + mgl sin(θ) = ml2 θ̈ + mgl sin(θ).
0=
−
dt ∂ θ̇
∂θ
dt
1
(1.2)
∂L
∂q
= 0 we
simout
To Workspace
ddot{theta}
1
s
dot{theta}
theta
1
s
Integrator
Integrator1
t
Sine Function
Scope
ddot{phi}
1
s
dot{phi}
1
s
Integrator2
phi
Integrator3
simout1
To Workspace1
−9.8/l
Gain
Figure 2: The Simulink model for the pendulum.
Therefore the equation of motion describing the pendulum is given by
θ̈ +
g
sin(θ) = 0.
l
(1.3)
Recall that for small angles sin(θ) ≈ θ. Hence for small angles the equations of motion
are approximately determined by
g
φ̈ + φ = 0.
(1.4)
l
When the angles are small the actual angle of the pendulum θ(t) ≈ φ(t). For small angles
the solution for (1.4) is given by
√
g
(1.5)
θ(t) ≈ φ(t) = a cos(ωt) + b sin(ωt) where ω =
l
and a and b are constants determined by the initial conditions φ(0) = θ(0) and φ̇(0) = θ̇(0).
The solution to the linear differential equation φ̈ + gl φ = 0 with φ(0) = θ(0) and φ̇(0) =
θ̇(0) = 0 is given by
√
( g )
φ(t) = θ(0) cos
t .
(1.6)
l
2
Finally, θ(t) ≈ φ(t) when φ(0) = θ(0) is small and φ̇(0) = θ̇(0) = 0.
The frequency in hertz for the solution φ(t) in (1.6) is determined by
√
1 g
.
2π l
Because the period is one over the frequency (in hertz), the period for the solution φ(t) in
(1.6) is given by
√
l
τlin = 2π
.
(1.7)
g
The energy approach. The total energy of the system is given by the kinetic energy plus
the potential energy. So the total energy of the pendulum is determined by
ml2 θ̇2
H =T +V =
− mgl cos(θ).
2
Because the system is conservative the total energy H equals a constant. Hence
0 = Ḣ = ml2 θ̈θ̇ + mgl sin(θ)θ̇.
Dividing by mlθ̇ yields the differential equation lθ̈ + g sin(θ) = 0, and we arrive at the same
equation of motion in (1.3).
The energy approach can also be used to find the period of the pendulum when θ(0) = θ0
is in [0, π) and θ̇(0) = 0. (Theoretically the pendulum is sits at the unstable equilibrium
when θ(0) = π and θ̇(0) = 0.) To obtain the period notice that the conservation of energy
principle shows that
ml2 θ̇2
− mgl cos(θ) = −mgl cos(θ0 ).
2
Because the kinetic energy is positive, cos(θ) − cos(θ0 ) ≥ 0. Hence
√
√
dθ
2g √
dt
l
1
√
cos(θ) − cos(θ0 ) and
=
=
.
dt
l
dθ
2g cos(θ) − cos(θ0 )
By taking the integral, this implies that
√ ∫
θ0
l
1
√
t0 =
dθ
2g 0
cos(θ) − cos(θ0 )
is the time it takes for the pendulum to move from θ0 to θ = 0. The period is obtained by
moving from θ0 to 0 and then from 0 to −θ0 and then back from −θ0 to 0 and finally from
0 to θ0 . (The conservation of energy principle guarantees that the maximum height of the
pendulum is achieved at θ0 and −θ0 .) Moreover, the time it takes the pendulum to travel
these four paths is the same. So the period is given by
√ ∫
θ0
1
l
√
dθ.
(1.8)
τ =4
2g 0
cos(θ) − cos(θ0 )
3
It is emphasized that the period τ = τ (θ0 ) depends upon the initial condition θ0 .
By consulting the webpage Pendulum (mathematics) in Wikipedia:
http://en.wikipedia.org/wiki/Pendulum %28mathematics%29
one can use elliptic integrals to show that the period
√ (
)
( )2
( ) (
)2
( ) (
)2
( )
l
1
θ
1
·
3
θ
1
·
3
·
5
θ
0
0
0
1+
+
+
+ ··· .
τ = 2π
sin2
sin4
sin6
g
2
2
2·4
2
2·4·6
2
(1.9)
In particular, the linearized model for the pendulum has a smaller period τlin ≤ τ than the
actual pendulum; see (1.7). Therefore the frequency of the pendulum is slower, then the
corresponding frequency of its linearized model. The power series in (1.9) also shows that
τlin ≈ τ for small angles.
Using the power series in (1.9), with Matlab we plotted the graph of
(
)
( )2
( ) (
)2
( ) (
)2
( )
τ
1
θ
1
·
3
θ
1
·
3
·
5
θ
0
0
0
= 1+
+
+
+ ···
sin2
sin4
sin6
τlin
2
2
2·4
2
2·4·6
2
in Figure 3. For example,
• if θ0 =
π
,
12
then τ = 1.0043τlin ;
• if θ0 = π3 , then τ = 1.0732τlin ;
• if θ0 = π2 , then τ = 1.1803τlin ;
• if θ0 =
3π
,
4
then τ = 1.5268τlin .
The Matlab commands we used to generate Figure 3 are given by
• t = linspace(0, π, 2 ∧ 14);
• p = 1 + sin(t/2). ∧ 2/2;
• for k = (4:2:50); p = p + prod(1:2:k-1) ∧ 2 ∗ sin(t/2). ∧ k/(prod(2:2:k) ∧ 2);end
• plot(t,p); grid
• title(’The plot of τ /τlin ’)
• xlabel(’θ’); ylabel(’τ /τlin ’);print pend
4
The plot of τ/τlin
2.4
2.2
2
τ/τlin
1.8
1.6
1.4
1.2
1
0
0.5
1
1.5
θ
2
2.5
3
3.5
Figure 3: The plot of τ /τlin .
1.1
A Simulink model.
Let us present a Simulink model for the pendulum. Assume that the l = 3. The Simulink
model we used is presented in Figure 2. We set the configuration parameters in Simulink
to: fixed step, fixed step size 0.001 and then ran the model for 40 seconds. In the simout
to work space block we choose the array option. The simout in Matlab contains a vector of
length 40001 which corresponds to the solution θ for the equations of motion in (1.3), while
simout1 in Matlab is a vector of length 40001 which corresponds to the solution φ for the
linear approximation of the equations of motion in (1.4). Notice that the gain block was set
to − 9.8
≈ − gl and the amplitude in the sine function block was also set to − 9.8
≈ − gl . To run
l
l
the Simulink model, we set the initial condition for integrator 1 (that is, θ(0)) and integrator
π
3 (that is, φ(0)) both equal to 12
. Running Simulink generated the graph in Figure 4. (The
initial conditions for integrator and integrator 2 which correspond to θ̇(0) and φ̇(0) were
set equal to zero. Zero is the default setting.) Simulink solves the differential equations in
π
(1.3) and its linear approximation in (1.4) with the initial conditions θ(0) = φ(0) = 12
and
θ̇(0) = φ̇(0) = 0. Since the initial angle is small Figure 4 shows that the plots of θ and its
linear approximation φ are close. To plot this graph we used the Matlab commands:
t = linspace(0, 40, 40001);
plot(t, simout); grid; hold on; plot(t, simout1,′ r′ )
According to (1.6) when the initial condition is small
√
( g )
π
θ(t) ≈ φ(t) = θ(0) cos
t =
cos(1.8074t).
l
12
√
The corresponding frequency in radians is 9.8
= 1.8074. So the period is τlin =
3
3.4764. In other words, the pendulum swings back and forth or cycles
5
40
3.4764
2π
1.8074
=
= 11.5062 times
π
in 40 seconds; see Figure 4. Finally, recall that for θ0 = 12
the actual period of the pendulum
is τ = 1.0043τlin = 3.4914. As expected, the period and frequency of the pendulum and its
π
linear approximation are close when θ0 = 12
.
If one wants to see how the pendulum move in the x-y plane, then in Matlab set
l = 3; x = l sin(simout); y = −l cos(simout)
comet(x, y)
Since simout is the angle θ of the pendulum, Matlab plots the x-y position of the pendulum.
The plot of θ and its approximation with θ(0) = π/12
1
0.8
0.6
0.4
0.2
0
−0.2
−0.4
−0.6
−0.8
−1
0
5
10
15
20
time
25
30
35
40
Figure 4: The plot of θ and its approximation φ with θ(0) =
6
π
.
12
Now let us use Simulink to numerical solve the differential equations in (1.3) and (1.4)
with the initial conditions θ(0) = φ(0) = π3 and θ̇(0) = φ̇(0) = 0. To accomplish this we set
the initial conditions in integrator 1 and integrator 3 both equal to π3 . The initial conditions
in the other two integrators were set equal to zero; see Figure 2. Then we ran Simulink. The
graph of θ and its linear approximation φ is given in Figure 5. Because the initial condition
is not small the two graphs for θ and its linear approximation φ diverge. The solution φ for
the linear approximation or differential equation φ̈ + gl φ = 0 is given by
φ = θ(0) cos
(
√
g )
π
t =
cos(1.8074t).
l
12
40
which runs through 3.4764
= 11.5062 cycles in 40 seconds. The power spectrum for θ, the
actual angle of the pendulum, is given in Figure 6. The power spectrum was obtained
by plotting the inverse fast Fourier transform for θ over the interval [0, 40]. The Matlab
commands we used are given by
a = ifft(simout);
bar((0:50),abs(a(1:51)). ∧ 2); grid
title(’The power spectrum of θ’); ylabel(’|a|2 ’); axis([0, 30, 0, .3])
We see that the main frequency occurs at k = 11. Because the length of the interval is 40, the
fundamental frequency of θ occurs at 11×2π
= 1.7279. The corresponding period determined
40
=
3.6364.
The
frequency
for the linear approximation φ equals 1.8074
experimentally is 40
11
in radians. Since the fundamental frequency for the nonlinear differential equation is 1.7279,
we see that the actual solution for θ has a smaller frequency than its corresponding linear
approximation φ.
Recall that for θ0 = π3 the actual period of the pendulum is τ = 1.0732τlin = 3.7308 and
τlin = 3.4764. Hence the experimental estimate of the period 3.6364 is slightly off the actual
period 3.7308 for the pendulum. For many engineering applications this is close enough.
Finally, it is noted that there are statistical techniques which will give more accurate results.
7
The plot of θ and its approximation with θ(0) = π/3
3
2
1
0
−1
−2
−3
0
5
10
15
20
time
25
30
35
40
Figure 5: The plot of θ and its approximation φ with θ(0) = π3 .
The power spectrum of θ
0.25
|a|
2
0.2
0.15
0.1
0.05
0
0
5
10
15
20
25
30
Figure 6: The power spectrum of θ with θ(0) = π3 .
1.2
Problem
Exercise 1. Derive the solution to the differential equation
φ̈ + ω 2 φ = 0
subject to the initial conditions φ(0) = α and φ̇(0) = β. In the linear approximation for our
pendulum ω 2 = gl .
Exercise 2. Consider the linear approximation for the pendulum given by
g
φ̈ + φ = 0
l
8
√
where l = 3, φ(0) =
For this example the fundamental frequency is ω ≈ 9.8
= 1.8074.
3
Run the Simulink model in Figure 2 to solve this linear differential equation for 40 seconds.
Use the fast Fourier transform to try and estimate the frequency 1.8074.
π
.
3
Exercise 3. Now assume that there is damping on the pendulum. In this case, the equation
of motion becomes:
ml2 θ̈ + mgl sin(θ) = −cθ̇
(1.10)
where c is the damping coefficient. (This follows from Lagrange’s equations of motion with
damping dtd ∂L
− ∂L
= −cq̇.) For small angles its linear approximation θ ≈ φ is given by
∂ q̇
∂q
ml2 φ̈ + mglφ = −cφ̇.
Assume that m = 2, l = 4 and c = 3 with the initial conditions θ(0) = φ(0) =
θ̇(0) = φ̇(0) = 0.
(1.11)
π
2
and
• Modify the Simulink model in Figure 2 to numerically solve the differential equations
of motion in (1.10) and its linear approximation in (1.11). Plot the solutions θ and φ
for these differential equations over the interval [0, 40] on the same graph.
• Which solution θ for the pendulum in (1.10) or its linear approximation φ in (1.11)
has a higher frequency component.
• If one increases the mass does the solution to (1.10) die out faster or slower? Explain
why.
• If one increases the length l of the pendulum does the solution to (1.10) die out faster
or slower? Explain why.
9