# Some more Lagrangian Problems…

This the continuation to the first set of Lagrangian problems/solutions. While it might be a bit foolish to solve such problems, there are a few reasons why they were done:

• Its good practice to solve some problems that are a little bit different from the norm. It’s good to be forced to think in different ways and remember some math that one may have long forgotten about from years ago.
• Again, this is a continuation of the first set of Lagrangian based problems. That is, these problems are a stepping stone for something slightly more complicated that may or may not eventually happen.
• The job market for solving differential equations on paper by hand and then coding them up is so tremendous. So this is good preparation if that was true.
• When I initially took a classical mechanics course a while ago, the professor would solve some problems to the point of having a set of differential equations. He would never proceeded onwards with those equations; the thought of using a computer and simulating them was completely foreign to him (I guess he did not know anything about computers). So simulating these simple problems is satisfying a curiosity I had a lot time ago.
• Finally, I like classical mechanics. Sometimes I think it would be great to be stuck on an island somewhere with a pad of paper, a pen, and one of the more famous classical mechanics books out there (like this one). Other days I think it might not be the best idea.

So in this project, three more problems were solved: 1) a simple pendulum on a wheel; 2) spring-cart-pendulum system; and 3) the triple pendulum.

#### Simple Pendulum on a Wheel

This problem is what the title says, a simple pendulum that is attached to a rotating wheel (that is rotating at a constant velocity). Note, to keep things easy, inertia is not considered in the wheels motion.

The math is pretty easy since it’s just a single degree of freedom problem. First, the angle (\phi) of where the pendulum’s pivot is on the wheel is at time t is: \phi = \phi_0 + \omega t

Where \phi_0 is the initial angle and \omega is the angular speed of the rotating wheel.

The position of the pendulum’s pivot is then:x_{\mathsf{pivot}} = r \cos \omega t \qquad\qquad y_{\mathsf{pivot}} = r \sin \omega t

The pendulum’s mass position is:x_{\mathsf{pend}} = \ell \sin \theta \qquad\qquad y_{\mathsf{pend}} = -\ell \cos \theta

Therefore the final/total position of the pendulum is:

\begin{aligned} x &= x_{\mathsf{pivot}} + x_{\mathsf{pend}} = r \cos \omega t + \ell \sin \theta \\ y &= y_{\mathsf{pivot}} + y_{\mathsf{pend}} = r \sin \omega t – \ell \cos \theta \end{aligned}

Now the velocities will be found to make the kinetic energy calculations a little bit easier to determine.

\begin{aligned} \dot{x} &= -r\omega \sin\omega t + \ell \cos \theta \dot{\theta} \\ \dot{y} &= r\omega \cos \omega t + \ell \sin \theta \dot{\theta} \end{aligned}

Now computing the kinetic energy:

\begin{aligned} T &= \frac{1}{2} mv^2 = \frac{1}{2} m \left[ \vphantom{\frac{1}{2}} \dot{x}^2 + \dot{y}^2 \right] \\ &= \frac{1}{2} m \left[ \vphantom{\frac{1}{2}} (-r\omega \sin\omega t + \ell \cos \theta \dot{\theta})^2 + (r\omega \cos \omega t + \ell \sin \theta \dot{\theta})^2 \right] \\ &= \frac{1}{2} m \left[ \vphantom{\frac{1}{2}} r^2 \omega^2 \sin^2 \omega t \ -\ 2r\ell \omega \cos\theta\sin\omega t \dot{\theta}\ +\ \ell^2\cos^2\theta \dot{\theta}^2 \right.\\ & \qquad\quad \left. + r^2\omega^2 \cos^2\omega t\ +\ 2r\ell\omega\sin\theta\cos\omega t\dot{\theta} + \ell^2\sin^2\theta \dot{\theta}^2 \vphantom{\frac{1}{2}}\right]\\ &= \frac{1}{2} m r^2\omega^2 + \frac{1}{2} m\ell^2 \dot{\theta}^2 + mr\ell\omega \sin(\theta – \omega t)\dot{\theta} \end{aligned}

Next, the potential energy:

V = mgh = mgr \sin \omega t – mg \ell \cos \theta

So the Lagrangian becomes:

\begin{aligned} \mathcal{L} &= T\ -\ V\\ &= \frac{1}{2} m r^2\omega^2 + \frac{1}{2} m\ell^2 \dot{\theta}^2 + mr\ell\omega \sin(\theta – \omega t)\dot{\theta} – mgr \sin \omega t + mg \ell \cos \theta \end{aligned}

Now taking some derivatives so that the equation of motion can be found:

\begin{aligned} \frac{\partial \mathcal{L}}{\partial \dot{\theta}} &= m\ell^2 \dot{\theta}\ +\ mr\ell\omega \sin (\theta – \omega t) \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}} \right) &= m\ell^2 \ddot{\theta}\ +\ mr\ell\omega \cos (\theta – \omega t)\cdot(\dot{\theta} – \omega) \\ &= m\ell^2 \ddot{\theta}\ +\ mr\ell\omega \cos (\theta – \omega t)\dot{\theta}\ -\ mr\ell\omega^2 \cos (\theta – \omega t) \\ \frac{\partial \mathcal{L}}{\partial \theta} &= mr\ell\omega \cos (\theta – \omega t)\dot{\theta}\ -\ mg\ell\sin\theta \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}} \right)\ -\ \frac{\partial \mathcal{L}}{\partial \theta} &= m\ell^2 \ddot{\theta}\ -\ mr\ell\omega^2 \cos(\theta – \omega t) + mg\ell\sin\theta \end{aligned}

Then after dividing everything by m\ell^2, the final equation of motion becomes:

\ddot{\theta}\ -\ \frac{r\omega^2}{\ell} \cos(\theta – \omega t)\ +\ \frac{g}{\ell}\sin \theta\ =\ 0

From the final equation of motion, there are two things to note: 1) the mass does not matter; 2) if r or \omega are 0, then the system reduces to a simple pendulum. Below is a small simulation of the system.

Click here to view in a separate tab.

#### Spring-Cart-Pendulum System

Classic problem involving a spring, pendulum, and horizontal motion. It is popular in the classroom, but I haven’t seen too many demos of it so I decided to make one here.

There are two things that are moving: the cart and the pendulum.

For the cart we have:

For the pendulum we have:

\begin{aligned} \mathsf{Pendulum\ Position:}\ x &= \ell \sin \theta \\ y &= -\ell \cos \theta \\ \mathsf{Pendulum\ Velocity:}\ \dot{x} &= \ell \cos \theta \cdot \dot{\theta} \\ \dot{y} &= \ell \sin \theta \cdot \dot{\theta} \end{aligned}

Note that since the pendulum is attached to the cart it can move horizontally.  Therefore, the total pendulum x velocity becomes:

\begin{aligned} \dot{x}_{\mathsf{total}} &= \dot{x}_{\mathsf{cart}} + \dot{x}_{\mathsf{pendulum}} \\ &= \dot{x} + \ell \cos \theta \cdot \dot{\theta} \end{aligned}

The kinetic energy is then:

\begin{aligned} T &= \frac{1}{2} mv^2 \\ &= \left(\frac{1}{2} mv^2\right)_{\mathsf{cart}} + \left(\frac{1}{2} mv^2\right)_{\mathsf{pendulum}} \\ &= \frac{1}{2} m_1 \dot{x}^2 +\ \frac{1}{2} m_2 \left[ \left( \dot{x} + \ell\cos\theta\cdot\dot{\theta} \right)^2 + \left(\ell\sin\theta\cdot\dot{\theta}\right)^2\right] \\ &= \frac{1}{2} m_1 \dot{x}^2 + \frac{1}{2} m_2 \left[ \dot{x}^2 + 2\ell\cos\theta\dot{x}\dot{\theta} + \ell^2\cos^2\theta\dot{\theta}^2 + \ell^2\sin^2\theta\dot{\theta}^2 \right] \\ &= \frac{1}{2} (m_1 + m_2) \dot{x}^2\ +\ m_2\ell\cos\theta\dot{x}\dot{\theta}\ +\ \frac{1}{2}m_2\ell^2\dot{\theta}^2 \end{aligned}

The potential energy is:

\begin{aligned} V &= V_{\mathsf{cart}} + V_{\mathsf{pendulum}} \\ &= \frac{1}{2}k(\mathsf{Cart\ Position})^2\ +\ mg (\mathsf{Pendulum}\ y\ \mathsf{Position}) \\ &= \frac{1}{2}kx^2\ +\ mg (-\ell \cos \theta) \\ &= \frac{1}{2}kx^2\ -\ m_2 g \ell \cos \theta \end{aligned}

The Lagrangian becomes:

\begin{aligned} L &= T\ -\ V \\ &= \frac{1}{2} (m_1 + m_2) \dot{x}^2\ +\ m_2\ell\cos\theta\dot{x}\dot{\theta}\ +\ \frac{1}{2}m_2\ell^2\dot{\theta}^2 -\ \frac{1}{2}kx^2\ +\ m_2 g \ell \cos \theta \end{aligned}

Since we have two variables (x\ \text{and}\ \theta), we will have two equations of motion. Solving for x first:

\begin{aligned} \frac{\partial \mathcal{L}}{\partial \dot{x}} &= (m_1 + m_2)\dot{x}\ +\ m_2\ell\cos\theta\dot{\theta} \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{x}} \right) &= (m_1 + m_2)\ddot{x}\ +\ m_2\ell\cos\theta\ddot{\theta} \ -\ m_2\ell\sin\theta\dot{\theta}^2 \\ \frac{\partial \mathcal{L}}{\partial x} &= – kx \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{x}} \right)\ -\ \frac{\partial \mathcal{L}}{\partial x} &= (m_1 + m_2)\ddot{x}\ +\ m_2\ell\cos\theta\ddot{\theta}\ -\ m_2\ell\sin\theta\dot{\theta}^2\ +\ kx \end{aligned}

Now dealing with \theta:

\begin{aligned} \frac{\partial \mathcal{L}}{\partial \dot{\theta}} &= m_2\ell\cos\theta\dot{x} + m_2\ell^2\dot{\theta} \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}} \right) &= m_2\ell\cos\theta\ddot{x} – m_2\ell\sin\theta\dot{x}\dot{\theta} + m_2\ell^2\ddot{\theta} \\ \frac{\partial \mathcal{L}}{\partial \theta} &= -m_2\ell\sin\theta\dot{x}\dot{\theta} – m_2g\ell\sin\theta \\ &= – \left[ m_2\ell\sin\theta\dot{x}\dot{\theta} + m_2g\ell\sin\theta \right] \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}} \right)\ -\ \frac{\partial \mathcal{L}}{\partial \theta} &= m_2\ell\cos\theta\ddot{x}\ -\ m_2\ell\sin\theta\dot{x}\dot{\theta}\ +\ m_2\ell^2\ddot{\theta} \\ &\qquad +\ m_2\ell\sin\theta\dot{x}\dot{\theta}\ +\ m_2g\ell\sin\theta \\ &= m_2\ell\cos\theta\ddot{x}\ +\ m_2\ell^2\ddot{\theta}\ +\ m_2g\ell\sin\theta \\ \end{aligned}

Therefore, the final equations of motion are:

\begin{aligned} (m_1 + m_2)\ddot{x}\ +\ m_2\ell\cos\theta\ddot{\theta}\ -\ m_2\ell\sin\theta\dot{\theta}^2\ +\ kx &= 0 \\ m_2\ell\cos\theta\ddot{x}\ +\ m_2\ell^2\ddot{\theta}\ +\ m_2g\ell\sin\theta &= 0 \end{aligned}

Solving using some matrix magic:

\begin{aligned} \left[ \begin{array}{cc} m_1 + m_2 & m_2\ell\cos\theta \\ m_2\ell\cos\theta & m_2\ell^2 \end{array} \right] \left[ \begin{array}{c} \ddot{x} \\ \ddot{\theta} \end{array} \right] &= \left[ \begin{array}{c} m_2\ell\sin\theta\dot{\theta}^2\ -\ kx \\ -m_2g\ell\sin\theta \end{array} \right] \\ \left[ \begin{array}{c} \ddot{x} \\ \ddot{\theta} \end{array} \right] &= \left[ \begin{array}{cc} m_1 + m_2 & m_2\ell\cos\theta \\ m_2\ell\cos\theta & m_2\ell^2 \end{array} \right]^{-1} \left[ \begin{array}{c} m_2\ell\sin\theta\dot{\theta}^2\ -\ kx \\ -m_2g\ell\sin\theta \end{array} \right] \end{aligned}

The final equations are then used when numerically solving the system. Below is a simple simulation of the using the above equations.

#### Triple Pendulum

Here the triple pendulum is solved, since I have already solved the simple and double pendulum problems. Perhaps in the future, I will tackle the n-link pendulum problem (oh to dare to dream).

The geometry of the pendulum in this video is slightly different than the one in my solution, however the video is ridiculous (I can’t believe that I search youtube for such things).

The math is not hard, just lengthy. So first looking at the positions of the masses:

\begin{aligned} x_1 &= \ell_1 \sin \theta_1 \\ y_1 &= -\ell_1 \cos \theta_1 \\ x_2 &= \ell_1 \sin \theta_1 + \ell_2 \sin \theta_2 = x_1 + \ell_2 \sin \theta_2 \\ y_2 &= -\ell_1 \cos \theta_1 – \ell_2 \cos \theta_2 = y_2 – \ell_2 \cos \theta_2 \\ x_3 &= \ell_1 \sin \theta_1 + \ell_2 \sin \theta_2 + \ell_3 \sin \theta_3 = x_2 + \ell_3 \sin \theta_3 \\ y_3 &= -\ell_1 \cos \theta_1 – \ell_2 \cos \theta_2 – \ell_3 \cos \theta_3 = y_2 – \ell_3 \cos \theta_3 \end{aligned}

Note that succeeding positions can be found using the previous position; this makes writing the code a bit easier. Then the speeds of the masses can be found by taking the derivatives:

\begin{aligned} \dot{x}_1 &= \ell_1 \cos \theta_1 \cdot \dot{\theta}_1 \\ \dot{y}_1 &= \ell_1 \sin \theta_1 \cdot \dot{\theta}_1 \\ \dot{x}_2 &= \ell_1 \cos \theta_1 \cdot \dot{\theta}_1 + \ell_2 \cos \theta_2 \cdot \dot{\theta}_2 \\ \dot{y}_2 &= \ell_1 \sin \theta_1 \cdot \dot{\theta}_1 + \ell_2 \sin \theta_2 \cdot \dot{\theta}_2 \\ \dot{x}_3 &= \ell_1 \cos \theta_1 \cdot \dot{\theta}_1 + \ell_2 \cos \theta_2 \cdot \dot{\theta}_2 + \ell_3 \cos \theta_3 \cdot \dot{\theta}_3 \\ \dot{y}_3 &= \ell_1 \sin \theta_1 \cdot \dot{\theta}_1 + \ell_2 \sin \theta_2 \cdot \dot{\theta}_2 + \ell_3 \sin \theta_3 \cdot \dot{\theta}_3 \end{aligned}

Now solving for the kinetic energy:

The potential energy is:

\begin{aligned} V = mgh &= m_1 g y_1 + m_2 g y_2 + m_3 g y_3 \\ &= m_1 g \left( -\ell_1 \cos \theta_1 \right) + m_2 g \left( -\ell_1 \cos \theta_1 – \ell_2 \cos \theta_2 \right) + m_3 g \left( -\ell_1 \cos \theta_1 – \ell_2 \cos \theta_2 – \ell_3 \cos \theta_3 \right) \\ &= -1 \left[ \vphantom{\frac{1}{1}} (m_1 + m_2 + m_3)g \ell_1 \cos \theta_1 + (m_2 + m_3) g \ell_2 \cos \theta_2 + m_3 g \ell_3 \cos \theta_3 \right] \\ \end{aligned}

Now computing the Lagrangian:

\begin{aligned} \mathcal{L} &= T – V \\ &= \left[ \frac{1}{2} \left( m_1 + m_2 + m_3 \right) \ell_1^2 \dot{\theta}_1^2 + \frac{1}{2} \left( m_2 + m_3 \right) \ell_2^2 \dot{\theta}_2^2 + \frac{1}{2} m_3 \ell_3^2 \dot{\theta}_3^2 \right. \\ & \qquad \left. + \left( m_2 + m_3 \right) \ell_1\ell_2\dot{\theta}_1\dot{\theta}_2 \cos (\theta_1 – \theta_2) + m_3 \ell_1\ell_3\dot{\theta}_1\dot{\theta}_3 \cos(\theta_1 – \theta_3) + m_3 \ell_2\ell_3\dot{\theta}_2\dot{\theta}_3 \cos(\theta_2 – \theta_3) \vphantom{\frac{1}{1}} \right] \\ & \qquad – (-1) \left[ \vphantom{\frac{1}{1}} (m_1 + m_2 + m_3)g \ell_1 \cos \theta_1 + (m_2 + m_3) g \ell_2 \cos \theta_2 + m_3 g \ell_3 \cos \theta_3 \right] \\ &= \frac{1}{2} \left( m_1 + m_2 + m_3 \right) \ell_1^2 \dot{\theta}_1^2 + \frac{1}{2} \left( m_2 + m_3 \right) \ell_2^2 \dot{\theta}_2^2 + \frac{1}{2} m_3 \ell_3^2 \dot{\theta}_3^2 \\ & \qquad + \left( m_2 + m_3 \right) \ell_1\ell_2\dot{\theta}_1\dot{\theta}_2 \cos (\theta_1 – \theta_2) + m_3 \ell_1\ell_3\dot{\theta}_1\dot{\theta}_3 \cos(\theta_1 – \theta_3) + m_3 \ell_2\ell_3\dot{\theta}_2\dot{\theta}_3 \cos(\theta_2 – \theta_3) \\ & \qquad + (m_1 + m_2 + m_3)g \ell_1 \cos \theta_1 + (m_2 + m_3) g \ell_2 \cos \theta_2 + m_3 g \ell_3 \cos \theta_3 \\ \end{aligned}

There are a three degrees of freedom, that is \theta_1, \theta_2,\ \text{and}\ \theta_3.  So to determine the equations of motions, we need to compute:

\frac{d}{dt}\left( \frac{\partial\mathcal{L}}{\partial \dot{\theta}_1} \right) – \frac{\partial\mathcal{L}}{\partial \theta_1} = 0 \quad\quad \frac{d}{dt}\left( \frac{\partial\mathcal{L}}{\partial \dot{\theta}_2} \right) – \frac{\partial\mathcal{L}}{\partial \theta_2} = 0 \quad\quad \frac{d}{dt}\left( \frac{\partial\mathcal{L}}{\partial \dot{\theta}_3} \right) – \frac{\partial\mathcal{L}}{\partial \theta_3} = 0

Solving for \theta_1:

\begin{aligned} \frac{\partial \mathcal{L}}{\partial \dot{\theta}_1} &= (m_1 + m_2 + m_3)\ell_1^2 \dot{\theta}_1 + (m_2 + m_3)\ell_1\ell_2 \cos(\theta_1 – \theta_2)\dot{\theta}_2 + m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3)\dot{\theta}_3 \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}_1} \right) &= (m_1 + m_2 + m_3)\ell_1^2 \ddot{\theta}_1 \\ & \qquad + (m_2 + m_3)\ell_1\ell_2 \cos(\theta_1 – \theta_2)\ddot{\theta}_2 – (m_2 + m_3)\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_2\left(\dot{\theta}_1 – \dot{\theta}_2 \right) \\ & \qquad + m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3)\ddot{\theta}_3 – m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3)\dot{\theta}_3 \left( \dot{\theta}_1 – \dot{\theta}_3 \right) \\ &= (m_1 + m_2 + m_3)\ell_1^2 \ddot{\theta}_1 + (m_2 + m_3)\ell_1\ell_2 \cos(\theta_1 – \theta_2)\ddot{\theta}_2 + m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3)\ddot{\theta}_3 \\ & \qquad – (m_2 + m_3)\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_1\dot{\theta}_2 + (m_1 + m_3)\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_2^2 \\ & \qquad – m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3)\dot{\theta}_1\dot{\theta}_3 + m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3)\dot{\theta}_3^2 \\ \frac{\partial \mathcal{L}}{\partial \theta_1} &= – (m_2 + m_3)\ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1 \dot{\theta}_2 – m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1\dot{\theta}_3 – (m_1 + m_2 + m_3) g \ell_1 \sin \theta_1 \\ &= -1 \left[ \vphantom{\frac{1}{2}} (m_2 + m_3)\ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1 \dot{\theta}_2 + m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1\dot{\theta}_3 + (m_1 + m_2 + m_3) g \ell_1 \sin \theta_1 \right] \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}_1} \right) – \frac{\partial \mathcal{L}}{\partial \theta_1} &= (m_1 + m_2 + m_3)\ell_1^2 \ddot{\theta}_1 + (m_2 + m_3)\ell_1\ell_2 \cos(\theta_1 – \theta_2)\ddot{\theta}_2 + m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3)\ddot{\theta}_3 \\ & \qquad – (m_1 + m_3)\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_1\dot{\theta}_2 + (m_2 + m_3)\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_2^2 \\ & \qquad – m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3)\dot{\theta}_1\dot{\theta}_3 + m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3)\dot{\theta}_3^2 \\ & \qquad – (-1) \left[ \vphantom{\frac{1}{2}} (m_2 + m_3)\ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1 \dot{\theta}_2 + m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1\dot{\theta}_3 + (m_1 + m_2 + m_3) g \ell_1 \sin \theta_1 \right] \\ &= (m_1 + m_2 + m_3)\ell_1^2 \ddot{\theta}_1 + (m_2 + m_3)\ell_1\ell_2 \cos(\theta_1 – \theta_2)\ddot{\theta}_2 + m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3)\ddot{\theta}_3 \\ & \qquad + (m_2 + m_3)\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_2^2 + m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3)\dot{\theta}_3^2 + (m_1 + m_2 + m_3) g \ell_1 \sin \theta_1 \\ \end{aligned}

Now dealing with \theta_2:

\begin{aligned} \frac{\partial \mathcal{L}}{\partial \dot{\theta}_2} &= (m_2 + m_3) \ell_2^2 \dot{\theta}_2 + (m_2 + m_3) \ell_1 \ell_2 \cos (\theta_1 – \theta_2) \dot{\theta}_1 + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \dot{\theta}_3 \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}_2} \right) &= (m_2 + m_3) \ell_2^2 \ddot{\theta}_2 \\ & \qquad + (m_2 + m_3) \ell_1 \ell_2 \cos (\theta_1 – \theta_2) \ddot{\theta}_1 + (m_2 + m_3) \ell_1 \ell_2 (-1)\sin (\theta_1 – \theta_2) \dot{\theta}_1 (\dot{\theta_1} – \dot{\theta_2}) \\ & \qquad + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_3 + m_3 \ell_2 \ell_3 (-1)\sin (\theta_2 – \theta_3) \dot{\theta}_3 (\dot{\theta_2} – \dot{\theta_3}) \\ &= (m_2 + m_3) \ell_2^2 \ddot{\theta}_2 + (m_2 + m_3) \ell_1 \ell_2 \cos (\theta_1 – \theta_2) \ddot{\theta}_1 + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_3 \\ & \qquad – (m_2 + m_3) \ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1^2 + (m_2 + m_3) \ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1\dot{\theta_2} \\ & \qquad – m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2\dot{\theta}_3 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_3^2 \\ \frac{\partial \mathcal{L}}{\partial \theta_2} &= \left( m_2 + m_3 \right) \ell_1\ell_2\dot{\theta}_1\dot{\theta}_2(-1)\sin (\theta_1 – \theta_2)(-1) + m_3 \ell_2\ell_3\dot{\theta}_2\dot{\theta}_3 (-1)\sin(\theta_2 – \theta_3) + (m_2 + m_3) g \ell_2 (-1)\sin \theta_2 \\ &= -1 \left[ \vphantom{\frac{1}{2}} -\left( m_2 + m_3 \right) \ell_1\ell_2\dot{\theta}_1\dot{\theta}_2\sin (\theta_1 – \theta_2) + m_3 \ell_2\ell_3\dot{\theta}_2\dot{\theta}_3 \sin(\theta_2 – \theta_3) + (m_2 + m_3) g \ell_2 \sin \theta_2 \right] \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}_2} \right) – \frac{\partial \mathcal{L}}{\partial \theta_2} &= (m_2 + m_3) \ell_2^2 \ddot{\theta}_2 + (m_2 + m_3) \ell_1 \ell_2 \cos (\theta_1 – \theta_2) \ddot{\theta}_1 + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_3 \\ & \qquad – (m_2 + m_3) \ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1^2 + (m_2 + m_3) \ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1\dot{\theta_2} \\ & \qquad – m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2\dot{\theta}_3 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_3^2 \\ & \qquad – (-1) \left[ \vphantom{\frac{1}{2}} -\left( m_2 + m_3 \right) \ell_1\ell_2\dot{\theta}_1\dot{\theta}_2\sin (\theta_1 – \theta_2) + m_3 \ell_2\ell_3\dot{\theta}_2\dot{\theta}_3 \sin(\theta_2 – \theta_3) + (m_2 + m_3) g \ell_2 \sin \theta_2 \right] \\ &= (m_2 + m_3) \ell_1 \ell_2 \cos (\theta_1 – \theta_2) \ddot{\theta}_1 + (m_2 + m_3) \ell_2^2 \ddot{\theta}_2 + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_3 \\ & \qquad – (m_2 + m_3) \ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1^2 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_3^2 + (m_2 + m_3) g \ell_2 \sin \theta_2 \end{aligned}

And finally \theta_3:

\begin{aligned} \frac{\partial \mathcal{L}}{\partial \dot{\theta}_3} &= m_3 \ell_3^2 \dot{\theta}_3 + m_3 \ell_1 \ell_3 \dot{\theta}_1 \cos (\theta_1 – \theta_3) + m_3 \ell_2 \ell_3 \dot{\theta}_2 \cos (\theta_2 – \theta_3) \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}_3} \right) &= m_3 \ell_3^2 \ddot{\theta}_3 \\ & \qquad + m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3) \ddot{\theta}_1 + m_3 \ell_1 \ell_3 \dot{\theta}_1 (-1) \sin (\theta_1 – \theta_3) (\dot{\theta}_1 – \dot{\theta}_3) \\ & \qquad + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_2 + m_3 \ell_2 \ell_3 \dot{\theta}_2 (-1) \sin (\theta_2 – \theta_3) (\dot{\theta}_2 – \dot{\theta}_3) \\ &= m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3) \ddot{\theta}_1 + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_2 + m_3 \ell_3^2 \ddot{\theta}_3 \\ & \qquad – m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1^2 + m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1 \dot{\theta}_3 \\ & \qquad – m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2^2 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2 \dot{\theta}_3 \\ \frac{\partial \mathcal{L}}{\partial \theta_3} &= m_3 \ell_1 \ell_3 \dot{\theta}_1 \dot{\theta}_3 (-1) \sin ( \theta_1 – \theta_3) (-1) + m_3 \ell_2 \ell_3 \dot{\theta}_2 \dot{\theta}_3 (-1) \sin (\theta_2 – \theta_3) (-1) + m_3 g \ell_3 (-1) \sin \theta_3 \\ &= m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1 \dot{\theta}_3 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2 \dot{\theta}_3 – m_3 g \ell_3 \sin \theta_3 \\ \frac{d}{dt} \left( \frac{\partial \mathcal{L}}{\partial \dot{\theta}_3} \right) – \frac{\partial \mathcal{L}}{\partial \theta_3} &= m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3) \ddot{\theta}_1 + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_2 + m_3 \ell_3^2 \ddot{\theta}_3 \\ & \qquad – m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1^2 + m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1 \dot{\theta}_3 \\ & \qquad – m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2^2 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2 \dot{\theta}_3 \\ & \qquad – \left[ \vphantom{\frac{1}{2}} m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1 \dot{\theta}_3 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2 \dot{\theta}_3 – m_3 g \ell_3 \sin \theta_3 \right] \\ &= m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3) \ddot{\theta}_1 + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_2 + m_3 \ell_3^2 \ddot{\theta}_3 \\ & \qquad – m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1^2 – m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2^2 \\ & \qquad + m_3 g \ell_3 \sin \theta_3 \\ \end{aligned}

Therefore, the equations of motion (or governing equations) are:

\begin{aligned} (m_1 + m_2 + m_3)\ell_1^2 \ddot{\theta}_1 &+ (m_2 + m_3)\ell_1\ell_2 \cos(\theta_1 – \theta_2)\ddot{\theta}_2 + m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3)\ddot{\theta}_3 \\ &+ (m_2 + m_3)\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_2^2 + m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3)\dot{\theta}_3^2 \\ &+ (m_1 + m_2 + m_3) g \ell_1 \sin \theta_1 = 0 \\ (m_2 + m_3) \ell_1 \ell_2 \cos (\theta_1 – \theta_2) \ddot{\theta}_1 &+ (m_2 + m_3) \ell_2^2 \ddot{\theta}_2 + m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_3 \\ &- (m_2 + m_3) \ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1^2 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_3^2 \\ &+ (m_2 + m_3) g \ell_2 \sin \theta_2 = 0 \\ m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3) \ddot{\theta}_1 &+ m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \ddot{\theta}_2 + m_3 \ell_3^2 \ddot{\theta}_3 \\ &- m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1^2 – m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2^2 \\ &+ m_3 g \ell_3 \sin \theta_3 = 0 \end{aligned}

Two quick checks, if m_2, m_3, \ell_1, \text{and}\ \ell_3 are all 0, then the equations should reduce to a single pendulum; and if m_3 \text{and}\ \ell_3 are 0 then the system should reduce to a double pendulum.

Check 1, if m_2, m_3, \ell_1, \text{and}\ \ell_3 are 0, then we only have one equation:

m_1\ell_1^2 \ddot{\theta}_1\ +\ m_1 g \ell_1 \sin\theta_1 = 0 \quad \Rightarrow \quad \ddot{\theta}_1\ +\ \frac{g}{\ell_1}\sin \theta_1 = 0

And this describes a simple pendulum.

Check 2, if m_3\ \text{and} \ell_3 are 0 then, we have two equations:

\begin{aligned} (m_1 + m_2)\ell_1^2 \ddot{\theta}_1 + m_2\ell_1\ell_2 \cos(\theta_1 – \theta_2)\ddot{\theta}_2 + m_2\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_2^2 + (m_1 + m_2)g \ell_1 \sin \theta_1 &= 0 \\ m_2 \ell_1 \ell_2 \cos (\theta_1 – \theta_2) \ddot{\theta}_1 + m_2 \ell_2^2 \ddot{\theta}_2 – m_2 \ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1^2 + m_2 g \ell_2 \sin \theta_2 &= 0 \\ \end{aligned}

Divide equation 1 by \ell_1 and equation 2 by m_2\ \text{and}\ \ell_2 and we have the equations for a double pendulum:

\begin{aligned} (m_1 + m_2)\ell_1 \ddot{\theta}_1 + m_2\ell_2 \cos(\theta_1 – \theta_2)\ddot{\theta}_2 + m_2\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_2^2 + (m_1 + m_2)g \sin \theta_1 &= 0 \\ \ell_1 \cos (\theta_1 – \theta_2) \ddot{\theta}_1 + \ell_2 \ddot{\theta}_2 – \ell_1 \sin (\theta_1 – \theta_2) \dot{\theta}_1^2 + g \sin \theta_2 &= 0 \\ \end{aligned}

Looking back at the equations of motion for the triple pendulum, a little linear algebra can be used to obtain an ‘easy’ solution.

\left[ A \right] \left[ \ddot{\theta}_i \right] = \left[ B \right] \quad \Rightarrow \quad \left[ \ddot{\theta}_i \right] = \left[ A \right]^{-1} \left[ B \right]

So arranging the solution equations into matrices we have:

\begin{aligned} \left[ \begin{array}{ccc} (m_1 + m_2 + m_3)\ell_1^2 & (m_2 + m_3)\ell_1\ell_2 \cos(\theta_1 – \theta_2) & m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3) \\ (m_2 + m_3) \ell_1 \ell_2 \cos (\theta_1 – \theta_2) & (m_2 + m_3) \ell_2^2 & m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \\ m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3) & m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) & m_3 \ell_3^2 \end{array}\right] \left[ \begin{array}{ccc} \ddot{\theta}_1 \\ \ddot{\theta}_2 \\ \ddot{\theta}_3 \end{array}\right] = \\ \left[ \begin{array}{ccc} -(m_2 + m_3)\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_2^2 – m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3)\dot{\theta}_3^2 – (m_1 + m_2 + m_3) g \ell_1 \sin \theta_1 \\ (m_2 + m_3) \ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1^2 – m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_3^2 – (m_2 + m_3) g \ell_2 \sin \theta_2 \\ m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1^2 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2^2 – m_3 g \ell_3 \sin \theta_3 \end{array}\right] \end{aligned}

So then,

\begin{aligned} \left[ \begin{array}{ccc} \ddot{\theta}_1 \\ \ddot{\theta}_2 \\ \ddot{\theta}_3 \end{array}\right] = \left[ \begin{array}{ccc} (m_1 + m_2 + m_3)\ell_1^2 & (m_2 + m_3)\ell_1\ell_2 \cos(\theta_1 – \theta_2) & m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3) \\ (m_2 + m_3) \ell_1 \ell_2 \cos (\theta_1 – \theta_2) & (m_2 + m_3) \ell_2^2 & m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) \\ m_3 \ell_1 \ell_3 \cos (\theta_1 – \theta_3) & m_3 \ell_2 \ell_3 \cos (\theta_2 – \theta_3) & m_3 \ell_3^2 \end{array}\right]^{-1} \\ \times \left[ \begin{array}{ccc} -(m_2 + m_3)\ell_1\ell_2 \sin(\theta_1 – \theta_2)\dot{\theta}_2^2 – m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3)\dot{\theta}_3^2 – (m_1 + m_2 + m_3) g \ell_1 \sin \theta_1 \\ (m_2 + m_3) \ell_1 \ell_2 \sin (\theta_1 – \theta_2) \dot{\theta}_1^2 – m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_3^2 – (m_2 + m_3) g \ell_2 \sin \theta_2 \\ m_3 \ell_1 \ell_3 \sin (\theta_1 – \theta_3) \dot{\theta}_1^2 + m_3 \ell_2 \ell_3 \sin (\theta_2 – \theta_3) \dot{\theta}_2^2 – m_3 g \ell_3 \sin \theta_3 \end{array}\right] \end{aligned}

Finally, simulating the results…

Click here to view in a separate tab.

#### Code

All the code was written in Javascript and the visual components were done using the Html Canvas element and is available here. The math was originally done with just pen and paper, and the code written using vi (or more precisely vim). A Latex version of the math (with not too many errors) has also been made available.

#### Future

Maybe in the future more Lagrangian problems will be looked at including spherical pendulums (and the Foucault pendulum) and possibly n-link pendulums.