This is devoted to the fasinated topic---pendulum equations.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the first course APMA0330
Return to the main page for the second course APMA0340
Return to Part III of the course APMA0340
Introduction to Linear Algebra with Mathematica

Pendulum Equations

A simple pendulum consists of a single point of mass m (bob) attached to a rod (or wire) of length \( \ell \) and of negligible weight. We denote by θ the angle measured between the rod and the vertical axis, which is assumed to be positive in counterclockwise direction. By applying the Newton’s law of dynamics, we obtain the equation of motion
\[ m\ell^2 \ddot{\theta} + mg\ell \,\sin \theta =0 . \]
It can be simplified by putting \( \omega = \sqrt{g/\ell} : \)
\[ \ddot{\theta} + \omega^2 \sin \theta =0 . \]
Further simplification is available by normalization, which leads to \( \omega = 1 \) and we get
\[ \ddot{\theta} + \sin \theta =0 . \]
In practice, it is easier to study an ordinary differential equation as a system of equations involving only the first derivatives.
\[ \dot{x} = y, \qquad \dot{y} = -\sin x . \]
The variables x and y can be interpreted geometrically. Indeed, the angle x = θ corresponds to a point on a circle whereas the velocity \( y = \dot{\theta} \) corresponds to a point on a real line. Therefore, the set of all states (x ,y) can be represented by a cylinder, the product of a circle by a line. More formally, the phase space of the pendulum is the cylinder \( S^1 \times \mathbb{R} , \) its elements are couples (position,velocity).

Thus, at each point (x ,y) in the phase space, there is an attached vector \( (\dot{x}, \dot{y} ) = (y, - \sin x) . \) This can be geometrically represented as a vector field on the cylindrical phase space.


Example: The swinging mass m has a kinetic energy of \( m \ell^2 \left( {\text d}\theta /{\text d}t \right)^2 /2 \) and a potential energy of \( mg\ell\left( 1 - \cos \theta \right) ; \) the potential energy is zero for θ = 0. Let θM denote the maximum amplitude of the pendulum. Since dθ/dt = 0 at θ = θM, conservation of energy gives

\[ \frac{1}{2} \,m\ell^2 \left( \frac{{\text d}\theta}{{\text d}t} \right)^2 = mg\ell\,\cos \theta - mg\ell\,\cos \theta_M . \]
Solving for the velocity dθ/dt, we obtain
\[ \frac{{\text d}\theta}{{\text d}t} = \pm \left( \frac{2g}{\ell} \right)^{1/2} \left( \cos \theta - mg\ell\,\cos \theta_M \right)^{1/2} , \]
with the mass m canceling out. We take t to be zero, when θ = 0 and dθ/dt > 0. An integration from θ = 0 t0 θM yields
\begin{equation} \int_0^{\theta_M} \left( \cos \theta - mg\ell\,\cos \theta_M \right)^{-1/2} {\text d}\theta = \left( \frac{2g}{\ell} \right)^{1/2} \int_0^t {\text d}t = \left( \frac{2g}{\ell} \right)^{1/2} t . \label{pendulum.1} \end{equation}
This is one-fourth of a cycle, and therefore the time t is one-fourth of the period, T. We note that θ < θM, and with a bit of clairvoyance we try the half-angle substitution
\[ \sin \frac{\theta}{2} = \sin \left( \frac{\theta_M}{2} \right) \sin \phi . \]
With this, Eq.\eqref{pendulum.1} becomes
\begin{equation} T = 2\pi \left( \frac{\ell}{g} \right)^{1/2} \int_0^{\pi} \left[ 1 - \sin^2 \left( \frac{\theta_M}{2} \right) \sin^2 \phi \right]^{-1/2} {\text d}\phi . \label{pendulum.2} \end{equation}
Although not an obvious improvement over Eq.\eqref{pendulum.1}, the integral \eqref{pendulum.2} now defines the complete elliptic integral of the first kind,\( K \left( \sin^2 \theta_M /2 \right) . \) From the series expansion, the period of our pendulum may be developed as a power series—powers of sin θM/2:
\[ T = 2\pi \left( \frac{\ell}{g} \right)^{1/2} \left\{1 + \frac{1}{4}\,\sin^2 \frac{\theta_M}{2} + \frac{9}{64}\,\sin^4 \frac{\theta_M}{2} + \cdots \right\} . \]


Pendulum Equation with Resistance


We convert the pendulum equation with resistance
\[ m\ell^2 \ddot{\theta} + c\,\dot{\theta} + mg\ell \,\sin \theta =0 . \]
to a system of two first order equations by letting \( x= \theta \quad\mbox{and} \quad y = \dot{\theta} : \)
\[ \frac{{\text d} x}{{\text d}t} = y , \qquad \frac{{\text d} y}{{\text d}t} = -\omega^2 \sin x - \gamma \,y . \]
Here \( \gamma = c/(m\,\ell ) , \ \omega^2 = g/\ell \) are positive constants. Therefore, the above system of differential equations is autonomous. Setting \( \gamma = 0.25 \quad\mbox{and}\quad \omega^2 =1 , \) we ask Mathematica to provide a phase portrait for the pendulum equation with resistance:


Spherical Pendulum

Consider the motion under gravity of a bob of mass m attached to a fixed point by an inextensible massless rod of length ℓ. The bob is free to move on a sphere of radius ℓ. Using spherical coordinates (angles) θ and ϕ as the generalized coordinates, the kinetic and potential energies become
\begin{align*} \mbox{K} &= \frac{m}{2}\,\ell^2 \left( \dot{\theta}^2 + \dot{\phi}^2 \sin^2 \theta \right) , \\ \Pi &= mg\ell \left( 1- \cos \theta \right) . \end{align*}
This allows us to derive the Euler--Lagrange equations for the corresponding Lagrangian:
\[ \frac{\text d}{{\text d}t} \left( \frac{\partial {\cal L}}{\partial \dot{\theta}} \right) - \frac{\partial {\cal L}}{\partial \theta} = 0 , \qquad \frac{\text d}{{\text d}t} \left( \frac{\partial {\cal L}}{\partial \dot{\phi}} \right) - \frac{\partial {\cal L}}{\partial \phi} = 0 . \]
Substituting the expressions for the kinetic and potential energies, we obtain two coupled equations
\[ \begin{split} \ddot{\theta} + \frac{g}{\ell} \,\sin\theta - \frac{1}{2} \,\dot{\phi}^2 \sin 2\theta &= 0, \\ \ddot{\phi}\,\sin\theta + 2\dot{\phi} \dot{\theta}\,\cos\theta &= 0. \end{split} \]
The last equation is a first order differential equation with respect to the derivative of ϕ, so it can be integrated
\[ \dot{\phi} \sin^2 \theta = c, \quad \mbox{a constant}. \]
Using this equation, we obtain the following differential equation for nagle θ:
\[ \dot{\theta} + \frac{g}{\ell} \,\sin\theta - \frac{c^2 \cos\theta}{\sin^3 \theta} = 0. \]



Example 2: Consider a pendulum with constant torque T. Its motion is governed by the differential equation
\[ \ddot{\theta} + \frac{g}{\ell}\,\sin\theta = \frac{T}{m\ell^2} . \]
Its equilibria are determined by solving the algebraic equation
\[ \sin\theta = \frac{T}{mg\ell} . \]
For real roots, \( \displaystyle \frac{T}{mg\ell} < 1, \) illustrating fold or saddle-node bifurcation Its first integral is
\[ \frac{y^2}{2} - \frac{g}{\ell}\,\cos x - \frac{T}{m \ell^2}\, x = \mbox{constant}. \]
Example 3: Consider a pendulum in a plane that is rotating about a vertical axis with angular velocity ω. Its motion is governed by the differential equation
\[ \ddot{\theta} + \frac{g}{\ell}\,\sin\theta - \omega^2 \sin x \,\cos x = 0. \]
Equilibria: y = 0, x = 0, π, and also \( \displaystyle \cos x = \frac{g}{\omega^2 \ell} . \) For real roots, \( \displaystyle \frac{g}{\omega^2 \ell} < 1, \) illustrating a pitchfort bifurcation. The first integral:
\[ \frac{y^2}{2} - \frac{g}{\ell} \,\cos x + \frac{\omega^2}{4}\.\cos 2x = \mbox{constant}. \]
We consider a periodic movement described by the equation
\[ \dot{x} = -y^3 , \qquad \dot{y} = x^3 . \]
F[x_, y_] := -y^3;
G[x_, y_] := x^3;
sol = NDSolve[{x'[t] == F[x[t], y[t]], y'[t] == G[x[t], y[t]],
x[0] == 1, y[0] == 0}, {x, y}, {t, 0, 3*Pi},
WorkingPrecision -> 20]
ParametricPlot[Evaluate[{x[t], y[t]}] /. sol, {t, 0, 3*Pi}]

{{x -> InterpolatingFunction[{{0, 9.4247779607693797154}}, <>],
    y -> InterpolatingFunction[{{0, 9.4247779607693797154}}, <>]}}
X[t_] := Evaluate[x[t] /. sol]
Y[t_] := Evaluate[y[t] /. sol]
fns[t_] := {X[t], Y[t]};
len := Length[fns[t]];
Plot[Evaluate[fns[t]], {t, 0, 3*Pi}]


  1. Vitt, A. (Aleksandr Adolʹfovich) and Gorelik, G. (Gabriel Simonovich), Oscillations of an Elastic Pendulum as an Example of the Oscillations of Two Parametrically Coupled Linear Systems, Journal of Technical Physics, 1933, vol. 3, pp. 294–307.
    Its translation from the Russian in English by Lisa Shields with an introduction by Peter Lynch is available on the web:
  2. P. Pokorny, Stability condition for vertical oscillation of 3-dim heavy spring elastic pendulum, Regular and Chaotic Dynamics, June 2008, Volume 13, Issue 3, pp 155--165.
  3. Pendulum Wikipedia
  4. Pendulum Physics
  5. Lumen Physics: Pendulum
  6. Predicting the Future – An Intro to Models Described by Time Dependent Differential Equations by Christian J Howard.
  7. Salas, A.H. and Castillo, J.E., Exact Solution to Duffing Equation and the Pendulum Equation, Applied Mathematical Sciences, Vol. 8, 2014, no. 176, 8781 - 8789;
  8. M. G. Olsson, Why does a mass on a spring sometimes misbehave?, American Journal of Physics, 44, Issue 12, 1211 (1976);
  9. Casey, J., Geometrical derivation of Lagrange’s equations for a system of particles, American Journal of Physics, 62(9) 836–847 (1994).
  10. Corey Zammit, Nirantha Balagopal, Zijun Li, Shenghao Xia, and Qisong Xiao, The dynamic of the elastic pendulum, Arizona.
  11. Qisong Xiao; Shenghao Xia; Corey Zammit; Nirantha Balagopal; Zijun Li, Dynamics of the Elastic Pendulum, Arizona.
  12. C. Madigan, The Spring Pendulum, MapleSoft.
  13. K. Craig, Pring-pendulum dynamic system, NYU, 2001.


Return to Mathematica page
Return to the main page (APMA0340)
Return to the Part 1 Matrix Algebra
Return to the Part 2 Linear Systems of Ordinary Differential Equations
Return to the Part 3 Non-linear Systems of Ordinary Differential Equations
Return to the Part 4 Numerical Methods
Return to the Part 5 Fourier Series
Return to the Part 6 Partial Differential Equations
Return to the Part 7 Special Functions