# The Kahn Chaotic Pendulum

J. Donald Tillman
May 2020

Some time ago, back in the mid 90s, my family and I were visiting The Exploratorium in San Francisco. A wonderful experience, of course. But while there, I came across the Chaotic Pendulum exhibit. And it made a big impression on me. I ended up staring at the thing for about half an hour. The family was getting concerned.

Chaotic pendulums are usually in the form of a Double Pendulum, one pendulum dangling from another. And while the motion of a single pendulum is simple and predictable, the motion of the double pendulum is chaotic. And while the math behind the single pendulum is simple, the math behind the double pendulum is much more complex.

But this chaotic pendulum is different. It is an elegant work by San Francisco Bay area environmental artist and sculptor Ned Kahn. This is a quadruple pendulum, where a T-shaped bar pivots at the juncture, and three regular pendulums pivot off from its endpoints. The whole thing is encased in an acrylic frame so nobody gets their fingers stuck or heads bonked. And a knob lets the visitor crank the main T-shaped bar.

This simple structure is capable of some remarkable movements. A dance of sorts. Expressing a palette of behaviors.

I thought it would be interesting to simulate Kahn Quadruple Chaotic Pendulum in JavaScript. Please enjoy!

### The Simulation

Use the mouse to give it a spin...

(This is a first pass; I'll improve things later. No, I have not compared the dimensions, masses, and time constants of this with the real pendulum. If you'd like to look at the code, it's here. About 6 pages.)

### Why is the movement of this device so fascinating?

Normally mechanical devices operate on individual axes. Like on a robot; each servo motor has the responsibility of positioning a particular piece to an intended angle, and it goes about doing that job, meeting that spec, and applying power to get that peice to that angle.

Here there are no servo motors. Instead energy is being transferred between potential energy and kinetic energy, with the total kinetic + potential energy remaining constant. The potential energy is due to the height of the masses. The kinetic energy is due to the speed of the masses.

It turns out that this is very similar to the way human and mobile animals move around. We naturally minimize the energy we use to get a particular task done. And robots typically don't do that.

### Derivation

The system is described with four angles, the angular position of the T Bar and the three small pendulums. And the derivatives of those. We'll number them; 0 is the T Bar on top, and 1, 2, and 3 are the smaller pendulums, left to right.

We'll be using the Lagrange approach; calculating the kinetic and potential energies of the system, and finding the accelerations. This is pretty straightforward, but the math is error-prone as all hell, so I'm writing it out here to keep things straight.

Here are the x,y positions of the endpoints of the T Bar:

\begin{align} (x,y)_{left} & = (-l_0 \cos \theta_0, -l_0 \sin \theta_0) \\ (x,y)_{bottom} & = (l_0 \sin \theta_0, -l_0 \cos \theta_0) \\ (x,y)_{right} & = (l_0 \cos \theta_0, l_0 \sin \theta_0) \\ \end{align}

Calculate the kinetic energy, T, and the potential energy, V, (those are traditional Lagrange variable names) of all four parts, and add them up.

$$T = T_0 + T_1 + T_2 + T_3$$ $$T_i = \frac{1}{2} m_i v_i^2$$ $$V = V_0 + V_1 + V_2 + V_3$$ $$V_i = -g m_i y_i$$ \begin{align} T_0 & = \frac{1}{2} m_0 l_0^2 \dot{\theta_0^2} \\ V_0 & = - g m_0 l_0 \cos \theta_0 \\ T_1 & = \frac{1}{2} m_1 ( l_0^2 \dot{\theta_0^2} + l_1^2 \dot{\theta_1^2} + 2 l_0 l_1 \dot\theta_0 \dot\theta_1 \sin( \theta_0 - \theta_1 )) \\ V_1 & = - g m_1 ( l_0 \sin \theta_0 + l_1 \cos \theta_1) \\ T_2 & = \frac{1}{2} m_2 ( l_0^2 \dot{\theta_0^2} + l_2^2 \dot{\theta_2^2} + 2l_0 l_2 \dot\theta_0 \dot\theta_2 \cos( \theta_0 - \theta_2 ) ) \\ V_2 & = - g m_2 (l_0 \cos \theta_0 + l_2 \cos \theta_2) \\ T_3 & = \frac{1}{2} m_3 ( l_0^2 \dot{\theta_0^2} + l_3^2 \dot{\theta_3^2} - 2 l_0 l_3 \dot\theta_0 \dot\theta_3 \sin( \theta_0 - \theta_3 ) ) \\ V_3 & = - g m_3 (-l_0 \sin \theta_0 + l_3 \cos \theta_3) \\ \end{align}

Find the total kinetic energy, T:

\begin{align} T = & \frac{1}{2} (m_0 + m_1 + m_2 + m_3) l_0^2 \dot{\theta_0^2} \\ & + \frac{1}{2} m_1 l_1^2 \dot{\theta_1^2} + m_1 l_0 l_1 \dot\theta_0 \dot\theta_1 \sin( \theta_0 - \theta_1 ) \\ & + \frac{1}{2} m_2 l_2^2 \dot{\theta_2^2} + m_2 l_0 l_2 \dot\theta_0 \dot\theta_2 \cos( \theta_0 - \theta_2 ) \\ & + \frac{1}{2} m_3 l_3^2 \dot{\theta_3^2} - m_3 l_0 l_3 \dot\theta_0 \dot\theta_3 \sin( \theta_0 - \theta_3 ) \\ \end{align}

Find the total potential energy, V:

\begin{align} V = & -g (l_0 (m_0 + m_2) \cos \theta_0 + l_0 (m_1 - m_3) \sin \theta_0 + m_1 l_1 \cos \theta_1 + m_2 l_2 \cos \theta_2 + m_3 l_3 \cos \theta_3) \end{align}

Calculate the Lagrange:

$$L = T - V$$ \begin{align} L & = \frac{1}{2} (m_0 + m_1 + m_2 + m_3) l_0^2 \dot{\theta_0^2} \\ & + \frac{1}{2} m_1 l_1^2 \dot{\theta_1^2} + m_1 l_0 l_1 \dot\theta_0 \dot\theta_1 \sin( \theta_0 - \theta_1 ) \\ & + \frac{1}{2} m_2 l_2^2 \dot{\theta_2^2} + m_2 l_0 l_2 \dot\theta_0 \dot\theta_2 \cos( \theta_0 - \theta_2 ) \\ & + \frac{1}{2} m_3 l_3^2 \dot{\theta_3^2} - m_3 l_0 l_3 \dot\theta_0 \dot\theta_3 \sin( \theta_0 - \theta_3 ) \\ & +g ( l_0 (m_0 + m_2) \cos \theta_0 + l_0 (m_1 - m_3) \sin \theta_0 + m_1 l_1 \cos \theta_1 + m_2 l_2 \cos \theta_2 + m_3 l_3 \cos \theta_3) \end{align}

Find the partial derivatives of L over the angles:

\begin{align} \frac{\partial L}{\partial \theta_0} = & m_1 l_0 l_1 \dot\theta_0 \dot\theta_1 \cos(\theta_0 - \theta_1) \\ & - m_2 l_0 l_2 \dot\theta_0 \dot\theta_2 \sin(\theta_0 - \theta_2) \\ & - m_3 l_0 l_3 \dot\theta_0 \dot\theta_3 \cos(\theta_0 - \theta_3) \\ & - g l_0 ( m_0 + m_2 ) \sin \theta + g l_0 ( m1 - m3 ) \cos \theta_0 \\ \frac{\partial L}{\partial \theta_1} = & - m_1 l_0 l_1 \dot\theta_0 \dot\theta_1 \cos( \theta_0 - \theta_1) - g m_1 l_1 \sin \theta_1 \\ \frac{\partial L}{\partial \theta_2} = & m_2 l_0 l_2 \dot\theta_0 \dot\theta_2 \sin( \theta_0 - \theta_2) - g m_2 l_2 \sin \theta_2 \\ \frac{\partial L}{\partial \theta_3} = & m_3 l_0 l_3 \dot\theta_0 \dot\theta_3 \cos( \theta_0 - \theta_3) - g m_3 l_3 \sin \theta_3 \\ \end{align}

Find the partial derivatives of L over the angular velocities:

\begin{align} \frac{\partial L}{\partial \dot\theta_0} = & (m_0 + m_1 + m_2 + m_3) l_0^2 \dot\theta_0 \\ & + m_1 l_0 l_1 \dot\theta_1 \sin( \theta_0 - \theta_1 ) + m_2 l_0 l_2 \dot\theta_2 \cos( \theta_0 - \theta_2 ) - m_3 l_0 l_3 \dot\theta_3 \sin( \theta_0 - \theta_3 ) \\ \frac{\partial L}{\partial \dot\theta_1} = & m_1 l_1^2 \dot{\theta_1} + m_1 l_0 l_1 \dot{\theta_0} \sin(\theta_0 - \theta_1) \\ \frac{\partial L}{\partial \dot\theta_2} = & m_2 l_2^2 \dot{\theta_2} + m_2 l_0 l_2 \dot{\theta_0} \cos(\theta_0 - \theta_2) \\ \frac{\partial L}{\partial \dot\theta_3} = & m_3 l_3^2 \dot{\theta_3} - m_3 l_0 l_3 \dot{\theta_0} \sin(\theta_0 - \theta_3) \\ \end{align}

Now, take the time derivative of those:

\begin{align} \frac{d}{dt} (\frac{\partial L}{\partial \dot\theta_0}) = & (m_0 + m_1 + m_2 + m_3) l_0^2 \ddot{\theta_0} \\ & + m_1 l_0 l_1 \ddot\theta_1 \sin(\theta_0 - \theta_1) + m_1 l_0 l_1 (\dot\theta_0 - \dot\theta_1) \dot\theta_1 \cos(\theta_0 - \theta_1) \\ & + m_2 l_0 l_2 \ddot\theta_2 \cos(\theta_0 - \theta_2) - m_2 l_0 l_2 (\dot\theta_0 - \dot\theta_2) \dot\theta_2 \sin(\theta_0 - \theta_2) \\ & - m_3 l_0 l_3 \ddot\theta_3 \sin(\theta_0 - \theta_3) - m_3 l_0 l_3 (\dot\theta_0 - \dot\theta_3) \dot\theta_3 \cos(\theta_0 - \theta_3) \\ \frac{d}{dt} (\frac{\partial L}{\partial \dot\theta_1}) = & m_1 l_1^2 \ddot{\theta_1} + m_1 l_0 l_1 \ddot\theta_0 \sin(\theta_0 - \theta_1) + m_1 l_0 l_1 \dot\theta_0 (\dot\theta_0 - \dot\theta_1) \cos(\theta_0 - \theta_1) \\ \frac{d}{dt} (\frac{\partial L}{\partial \dot\theta_2}) = & m_2 l_2^2 \ddot{\theta_2} + m_2 l_0 l_2 \ddot\theta_0 \cos(\theta_0 - \theta_2) - m_2 l_0 l_2 \dot\theta_0 (\dot\theta_0 - \dot\theta_2) \sin(\theta_0 - \theta_2) \\ \frac{d}{dt} (\frac{\partial L}{\partial \dot\theta_3}) = & m_3 l_3^2 \ddot{\theta_3} - m_3 l_0 l_3 \ddot\theta_0 \sin(\theta_0 - \theta_3) - m_3 l_0 l_3 \dot\theta_0 (\dot\theta_0 - \dot\theta_3) \cos(\theta_0 - \theta_3) \end{align}

Now, bring them together, with the double dotted angles on the left and everthing else on the right.

$$\frac{d}{dt} (\frac{\partial L}{\partial \dot\theta_i}) = \frac{\partial L}{\partial \theta_i}$$
$$\begin{multline} (m_0 + m_1 + m_2 + m_3) l_0^2 \ddot{\theta_0} + m_1 l_0 l_1 \sin(\theta_0 - \theta_1) \ddot\theta_1 + m_2 l_0 l_2 \cos(\theta_0 - \theta_2) \ddot\theta_2 - m_3 l_0 l_3 \sin(\theta_0 - \theta_3) \ddot\theta_3 = \\ \shoveright - m_1 l_0 l_1 (\dot\theta_0 - \dot\theta_1) \dot\theta_1 \cos(\theta_0 - \theta_1) + m_2 l_0 l_2 (\dot\theta_0 - \dot\theta_2) \dot\theta_2 \sin(\theta_0 - \theta_2) + m_3 l_0 l_3 (\dot\theta_0 - \dot\theta_3) \dot\theta_3 \cos(\theta_0 - \theta_3) \\ \shoveright + m_1 l_0 l_1 \dot\theta_0 \dot\theta_1 \cos(\theta_0 - \theta_1) - m_2 l_0 l_2 \dot\theta_0 \dot\theta_2 \sin(\theta_0 - \theta_2) - m_3 l_0 l_3 \dot\theta_0 \dot\theta_3 \cos(\theta_0 - \theta_3) \\ - g l_0 ( m_0 + m_2 ) \sin \theta_0 + g l_0 ( m1 - m3 ) \cos \theta_0 \\ \end{multline}$$ \begin{align} m_1 l_0 l_1 \sin( \theta_0 - \theta_1 ) \ddot\theta_0 + m_1 l_1^2 \ddot\theta_1 & = - m_1 l_0 l_1 \dot\theta_0 ( \dot\theta_0 - \dot\theta_1 ) \cos( \theta_0 - \theta_1 ) - m_1 l_0 l_1 \dot\theta_0 \dot\theta_1 \cos( \theta_0 - \theta_1) - g m_1 l_1 \sin \theta_1 \\ m_2 l_0 l_2 \cos(\theta_0 - \theta_2) \ddot\theta_0 + m_2 l_2^2 \ddot\theta_2 & = m_2 l_0 l_2 \dot\theta_0 (\dot\theta_0 - \dot\theta_2) \sin(\theta_0 - \theta_2) + m_2 l_0 l_2 \dot\theta_0 \dot\theta_2 \sin( \theta_0 - \theta_2) - g m_2 l_2 \sin \theta_2 \\ -m_3 l_0 l_3 \sin(\theta_0 - \theta_3) \ddot\theta_0 + m_3 l_3^2 \ddot\theta_3 & = m_3 l_0 l_3 \dot\theta_0 (\dot\theta_0 - \dot\theta_3) \cos(\theta_0 - \theta_3) + m_3 l_0 l_3 \dot\theta_0 \dot\theta_3 \cos( \theta_0 - \theta_3) - g m_3 l_3 \sin \theta_3 \\ \end{align}

Simplify

$$\begin{multline} (m_0 + m_1 + m_2 + m_3) l_0^2 \ddot{\theta_0} + m_1 l_0 l_1 \sin(\theta_0 - \theta_1) \ddot\theta_1 + m_2 l_0 l_2 \cos(\theta_0 - \theta_2) \ddot\theta_2 - m_3 l_0 l_3 \sin(\theta_0 - \theta_3) \ddot\theta_3 = \\ \shoveright + m_1 l_0 l_1 \dot\theta_1^2 \cos(\theta_0 - \theta_1) - m_2 l_0 l_2 \dot\theta_2^2 \sin(\theta_0 - \theta_2) - m_3 l_0 l_3 \dot\theta_3^2 \cos(\theta_0 - \theta_3) \\ \shoveright - g l_0 ( m_0 + m_2 ) \sin \theta_0 + g l_0 ( m1 - m3 ) \cos \theta_0 \\ \end{multline}$$ \begin{align} m_1 l_0 l_1 \sin( \theta_0 - \theta_1 ) \ddot\theta_0 + m_1 l_1^2 \ddot\theta_1 & = - m_1 l_0 l_1 \dot\theta_0^2 \cos( \theta_0 - \theta_1 ) - g m_1 l_1 \sin \theta_1 \\ m_2 l_0 l_2 \cos(\theta_0 - \theta_2) \ddot\theta_0 + m_2 l_2^2 \ddot\theta_2 & = m_2 l_0 l_2 \dot\theta_0^2 \sin(\theta_0 - \theta_2) - g m_2 l_2 \sin \theta_2 \\ -m_3 l_0 l_3 \sin(\theta_0 - \theta_3) \ddot\theta_0 + m_3 l_3^2 \ddot\theta_3 & = m_3 l_0 l_3 \dot\theta_0^2 \cos(\theta_0 - \theta_3) - g m_3 l_3 \sin \theta_3 \\ \end{align}

Simplify some more

$$\begin{multline} (m_0 + m_1 + m_2 + m_3) l_0 \ddot{\theta_0} + m_1 l_1 \sin(\theta_0 - \theta_1) \ddot\theta_1 + m_2 l_2 \cos(\theta_0 - \theta_2) \ddot\theta_2 - m_3 l_3 \sin(\theta_0 - \theta_3) \ddot\theta_3 = \\ \shoveright + m_1 l_1 \dot\theta_1^2 \cos(\theta_0 - \theta_1) - m_2 l_2 \dot\theta_2^2 \sin(\theta_0 - \theta_2) - m_3 l_3 \dot\theta_3^2 \cos(\theta_0 - \theta_3) \\ \shoveright - g ( m_0 + m_2 ) \sin \theta_0 + g ( m1 - m3 ) \cos \theta_0 \\ \end{multline}$$ \begin{align} l_0 \sin( \theta_0 - \theta_1 ) \ddot\theta_0 + l_1 \ddot\theta_1 & = - l_0 \dot\theta_0^2 \cos( \theta_0 - \theta_1 ) - g \sin \theta_1 \\ l_0 \cos(\theta_0 - \theta_2) \ddot\theta_0 + l_2 \ddot\theta_2 & = l_0 \dot\theta_0^2 \sin(\theta_0 - \theta_2) - g \sin \theta_2 \\ -l_0 \sin(\theta_0 - \theta_3) \ddot\theta_0 + l_3 \ddot\theta_3 & = l_0 \dot\theta_0^2 \cos(\theta_0 - \theta_3) - g \sin \theta_3 \\ \end{align}

And from here we can use a little matrix math to solve for the four accelerations given the four positions and four velocities.