Skip to content
scipython.com

The Kapitza pendulum

Posted on

The Kapitza pendulum is a rigid pendulum whose pivot is driven to oscillate vertically; if the pivot oscillates fast enough, the inverted position (with the bob directly above the pivot) is stable. This post derives the pendulum's equation of motion using Lagrangian mechanics, solves it with SciPy and explains the stability of the inverted position with an effective potential.

Andrew Stephenson showed in 1908 that a rapid vertical oscillation of a pendulum's pivot can make its inverted position stable [Stephenson, Philosophical Magazine 15, 233 (1908), doi:10.1080/14786440809463763]; the Kapitza pendulum is named after Pyotr Kapitza, who explained this stability in 1951 [Kapitza, Uspekhi Fizicheskikh Nauk 44, 7 (1951), doi:10.3367/UFNr.0044.195105b.0007]. As in the earlier posts on the spring pendulum, the double pendulum and the harmonically driven pendulum, its motion is described here using Lagrangian mechanics

Equation of motion

The pendulum is a bob of mass \(m\) on a rigid rod of length \(l\) and negligible mass. Its pivot oscillates vertically with amplitude \(a\) and angular frequency \(\omega\): in a coordinate system with the \(y\)-axis pointing upwards, the pivot is at \((0, a\cos\omega t)\). The position and velocity of the bob are then

\[\begin{align*} x &= l\sin\theta, & \dot{x} &= l\dot{\theta}\cos\theta,\\ y &= a\cos\omega t - l\cos\theta, & \dot{y} &= l\dot{\theta}\sin\theta - a\omega\sin\omega t, \end{align*}\]

where \(\theta\) is the angle of the rod, anticlockwise from the downward vertical: \(\theta = 0\) is the hanging position and \(\theta = \pi\) the inverted one. The kinetic energy, \(T = \tfrac{1}{2}m(\dot{x}^2 + \dot{y}^2)\), and the potential energy, \(V = mgy\), are therefore

\[\begin{align*} T &= \frac{m}{2}\left[l^2\dot{\theta}^2 + a^2\omega^2\sin^2\omega t - 2la\omega\dot{\theta}\sin\theta\sin\omega t\right],\\ V &= mg\left[a\cos\omega t - l\cos\theta\right]. \end{align*}\]

Substituting the Lagrangian, \(\mathcal{L} = T - V\), into the Euler–Lagrange equation,

\[\frac{\mathrm{d}}{\mathrm{d}t}\frac{\partial\mathcal{L}}{\partial\dot{\theta}} = \frac{\partial\mathcal{L}}{\partial\theta},\]

and dividing by \(m\) gives

\[l^2\ddot{\theta} - la\omega(\omega\sin\theta\cos\omega t + \dot{\theta}\cos\theta\sin\omega t) = -la\omega\dot{\theta}\cos\theta\sin\omega t - gl\sin\theta,\]

and hence the equation of motion:

\[\ddot{\theta} = -\frac{g - a\omega^2\cos\omega t}{l}\sin\theta.\]

This is the equation of motion of a simple pendulum, with the acceleration due to gravity, \(g\), replaced by \(g + \ddot{y}_\mathrm{p} = g - a\omega^2\cos\omega t\), where \(\ddot{y}_\mathrm{p}\) is the acceleration of the pivot: in the pivot's frame of reference, gravity appears stronger while the pivot accelerates upwards and weaker while it accelerates downwards.

Stability

If the pivot oscillates rapidly, the pendulum's motion is the sum of a slow motion, \(\bar\theta(t)\), and a small, rapid oscillation at the pivot's frequency. Averaging over the period of the rapid oscillation [Landau and Lifshitz, Mechanics, 3rd edition (Pergamon, 1976), §30] shows that the slow motion is that of a pendulum in the effective potential

\[V_\mathrm{eff}(\bar\theta) = -mgl\cos\bar\theta + \tfrac{1}{4}ma^2\omega^2\sin^2\bar\theta,\]

in which the second term is the mean kinetic energy of the rapid oscillation. Both \(\bar\theta = 0\) and \(\bar\theta = \pi\) are stationary points of \(V_\mathrm{eff}\), and the inverted position is a minimum, and therefore stable, if

\[a^2\omega^2 > 2gl.\]

Small oscillations about the inverted and hanging positions then have the angular frequencies

\[\Omega_\pi = \sqrt{\frac{a^2\omega^2}{2l^2} - \frac{g}{l}} \quad \text{and} \quad \Omega_0 = \sqrt{\frac{a^2\omega^2}{2l^2} + \frac{g}{l}},\]

so the pivot's oscillation also makes the hanging pendulum oscillate faster than a simple pendulum, whose angular frequency is \(\sqrt{g/l}\). The approximation holds if the pivot's oscillation is rapid and small: \(\omega \gg \sqrt{g/l}\) and \(a \ll l\).

Code

The program below solves the equation of motion with SciPy's solve_ivp function, for \(l = 1\,\mathrm{m}\), \(a = 0.2\,\mathrm{m}\) and \(\omega = 40\,\mathrm{rad\,s^{-1}}\) (a frequency of 6.4 Hz). These values satisfy the stability condition, since \(a^2\omega^2 = 64\,\mathrm{m^2\,s^{-2}}\) and \(2gl = 19.6\,\mathrm{m^2\,s^{-2}}\); \(a/l = 0.2\) is not much smaller than 1, which makes the rapid oscillation easy to see. The pendulum is released from rest 0.5 rad from the upward vertical (\(\theta_0 = \pi - 0.5\)) and, for comparison, 0.5 rad from the downward vertical (\(\theta_0 = 0.5\)). The program plots \(\theta\) against time for both and animates the first in real time. The tolerances of solve_ivp, rtol and atol, are reduced to \(10^{-8}\): with their default values, the calculated angle is in error by up to 0.02 rad after 5 s.

python
"""The Kapitza pendulum: a rigid pendulum whose pivot oscillates vertically.

The equation of motion is solved for a pendulum released from rest 0.5 rad
from the upward vertical and for one released 0.5 rad from the downward
vertical. The angle is plotted against time for both, and the first is
animated in real time.
"""

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
from scipy.integrate import solve_ivp

# Rod length (m), amplitude (m) and angular frequency (rad/s) of the pivot's
# oscillation, and acceleration due to gravity (m/s2).
l, a, w, g = 1, 0.2, 40, 9.81
# Time step (s): 1/(10w) gives 63 time points per period of the pivot.
dt = 1 / w / 10
# Radius of the bob, as drawn (m), and the colours of the animation.
R_BOB = 0.05
COLOURS = {"rod": "k", "bob": "tab:red", "track": "0.85"}


def deriv(t, y):
    """Return the time derivatives of y = (theta, dtheta/dt)."""
    theta, thetadot = y
    thetadotdot = (a * w**2 * np.cos(w * t) - g) * np.sin(theta) / l
    return thetadot, thetadotdot


def solve(theta0, t):
    """Return theta at times t for a pendulum released from rest at theta0."""
    sol = solve_ivp(deriv, (t[0], t[-1]), (theta0, 0), t_eval=t,
                    rtol=1e-8, atol=1e-8)
    return sol.y[0]


def plot_theta(t, thetas):
    """Plot theta against t, in one panel for each item of the dict thetas."""
    fig, axes = plt.subplots(len(thetas), 1, sharex=True, layout="constrained")
    for ax, (title, theta) in zip(axes, thetas.items()):
        ax.plot(t, theta)
        ax.set_title(title, loc="left")
        ax.set_ylabel(r"$\theta$ / rad")
    axes[-1].set_xlabel(r"$t$ / s")
    return fig


def animate(t, theta, fps=50, slowdown=1, colours=COLOURS):
    """Return an animation of the pendulum at fps frames per second.

    The animation runs slowdown times slower than real time.
    """
    # The number of time points per frame.
    step = round(1 / (fps * dt * slowdown))
    fig = plt.figure(figsize=(4.2, 5))
    ax = fig.add_axes((0, 0, 1, 1))
    ax.set_xlim(-l - R_BOB, l + R_BOB)
    ax.set_ylim(-l - a - R_BOB, l + a + R_BOB)
    ax.set_aspect("equal")
    ax.axis("off")
    # The pivot's track, the rod, the pivot and the bob.
    ax.plot((0, 0), (-a, a), color=colours["track"], lw=6, solid_capstyle="round")
    rod, = ax.plot([], [], color=colours["rod"], lw=2)
    pivot = ax.add_patch(plt.Circle((0, 0), R_BOB / 2, color=colours["rod"], zorder=3))
    bob = ax.add_patch(plt.Circle((0, 0), R_BOB, color=colours["bob"], zorder=3))
    clock = ax.text(0.04, 0.96, "", transform=ax.transAxes, va="top")

    def update(i):
        yp = a * np.cos(w * t[i])
        x, y = l * np.sin(theta[i]), yp - l * np.cos(theta[i])
        rod.set_data((0, x), (yp, y))
        pivot.center = 0, yp
        bob.center = x, y
        clock.set_text(f"$t = {t[i]:.2f}$ s")
        return rod, pivot, bob, clock

    return FuncAnimation(fig, update, frames=range(0, len(t), step),
                         interval=1000 / fps, blit=True)


if __name__ == "__main__":
    t = np.arange(0, 5, dt)
    theta_inverted, theta_hanging = solve(np.pi - 0.5, t), solve(0.5, t)
    plot_theta(t, {r"$\theta_0 = \pi - 0.5$": theta_inverted,
                   r"$\theta_0 = 0.5$": theta_hanging})
    anim = animate(t, theta_inverted)
    plt.show()

To save the animation as a GIF image instead of displaying it, replace plt.show() with anim.save("kapitza.gif", writer="pillow", fps=50). A GIF image stores the duration of each frame as a whole number of hundredths of a second, and web browsers show a frame whose duration is 0 or 0.01 s for 0.1 s instead, so 50 frames per second is the highest frame rate at which a GIF image plays at its intended speed in a browser. The slowdown argument of animate slows the animation down by the factor given: the second animation below was made with fps=20 and slowdown=10.

Results

The animations below show the inverted pendulum in real time and slowed down by a factor of 10. The pendulum swings slowly from side to side about the upward vertical, and the pivot's oscillation adds a small, rapid oscillation to its angle.

Animation of a pendulum balanced upside down on a pivot that vibrates rapidly up and down. The rod swings slowly from side to side, up to about 30 degrees from the vertical, without falling.
The Kapitza pendulum with \(l = 1\,\mathrm{m}\), \(a = 0.2\,\mathrm{m}\) and \(\omega = 40\,\mathrm{rad\,s^{-1}}\), released from rest at \(\theta_0 = \pi - 0.5\), in real time. The grey bar is the pivot's track.
The same animation slowed down by a factor of 10. The pivot moves up and down nine times while the rod swings from right to left and back again.
The first 1.41 s of the same motion, slowed down by a factor of 10: nine periods of the pivot's oscillation, during which the pendulum makes about one complete swing.

The graph below compares this motion with that of the pendulum released from rest at \(\theta_0 = 0.5\). Averaged over the pivot's oscillation, the pendulum oscillates about \(\theta = \pi\) with an amplitude of 0.40 rad and a period of 1.38 s, and about \(\theta = 0\) with an amplitude of 0.61 rad and a period of 1.03 s. The amplitudes are not 0.5 rad, because the rapid oscillation is at its maximum displacement, about 0.1 rad, at the moment of release. For small amplitudes, the effective potential gives periods of \(2\pi/\Omega_\pi = 1.33\,\mathrm{s}\) and \(2\pi/\Omega_0 = 0.97\,\mathrm{s}\); at the simulated amplitudes, it gives periods about 2% longer than the simulated ones. Without the pivot's oscillation, the hanging pendulum would oscillate with a period of \(2\pi\sqrt{l/g} = 2.01\,\mathrm{s}\), and the inverted one would fall.

Two graphs of the angle θ against time t, from 0 to 5 s. In the upper graph, θ oscillates between π − 0.5 and π + 0.5 radians with a period of about 1.4 s; in the lower graph, it oscillates between about −0.75 and 0.75 radians with a period of about 1.0 s. Both curves have small ripples at the pivot's frequency.
The angle \(\theta\) against time for the Kapitza pendulum released from rest at \(\theta_0 = \pi - 0.5\) (top) and at \(\theta_0 = 0.5\) (bottom).

Comments

Leave a comment

Optional, and never shown: only the moderator sees it.

Comments are written in Markdown (code between ``` lines) and appear once approved. Your name and comment are published; your email address, if you give one, is seen only by the moderator.