Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lagrange gallery — 4. Double pendulum, actuated at the shoulder joint

ISAE-SUPAERO

Independently re-derived in Python/sympy, following the physical setup described in doublePendulumForced/ of Kelly’s Lagrange_Mechanics_Derivations: the same double pendulum as notebook 3, but now with an external torque applied at the first (shoulder) joint. This is the worked example for the non-conservative generalized-force term QiQ_i introduced in Chapter 9/10’s theory: ddt(∂L/∂q˙i)−∂L/∂qi=Qi\frac{d}{dt}(\partial L/\partial\dot q_i)-\partial L/\partial q_i=Q_i.

import numpy as np
import matplotlib.pyplot as plt
import sympy as sp
from scipy.integrate import solve_ivp

plt.rcParams["figure.figsize"] = (7, 4.0)
plt.rcParams["axes.grid"] = True


def lagrange_equations(L, qs, t, Q=None):
    if Q is None:
        Q = [0] * len(qs)
    eqs = []
    for qi, Qi in zip(qs, Q):
        qid = sp.diff(qi, t)
        eqs.append(sp.expand(sp.diff(sp.diff(L, qid), t) - sp.diff(L, qi) - Qi))
    return eqs


def solve_for_accelerations(eqs, qs, t):
    qdd = [sp.diff(qi, t, 2) for qi in qs]
    M = sp.Matrix([[sp.diff(eq, a) for a in qdd] for eq in eqs])
    f = sp.Matrix([eq.subs({a: 0 for a in qdd}) for eq in eqs])
    sol = M.solve(-f)
    return M, f, sol

Setup

Same T,VT,V as the free double pendulum, plus a prescribed torque τ(t)\tau(t) applied about the shoulder joint: since θ1\theta_1 is the shoulder’s rotation angle, τ(t)\tau(t) enters exactly as the generalized force Qθ1=τ(t)Q_{\theta_1}=\tau(t) (and Qθ2=0Q_{\theta_2}=0 — no actuator at the elbow).

t = sp.symbols("t")
m, l, g = sp.symbols("m l g", positive=True)
tau = sp.Function("tau")(t)
th1 = sp.Function("theta1")(t)
th2 = sp.Function("theta2")(t)

x1, y1 = l * sp.sin(th1), -l * sp.cos(th1)
x2, y2 = x1 + l * sp.sin(th2), y1 - l * sp.cos(th2)

T = (sp.Rational(1, 2) * m * (sp.diff(x1, t) ** 2 + sp.diff(y1, t) ** 2)
     + sp.Rational(1, 2) * m * (sp.diff(x2, t) ** 2 + sp.diff(y2, t) ** 2))
V = m * g * y1 + m * g * y2
L = sp.simplify(T - V)

eqs = [sp.simplify(e) for e in lagrange_equations(L, [th1, th2], t, Q=[tau, 0])]
M_sym, f_sym, qdd_sol = solve_for_accelerations(eqs, [th1, th2], t)

Resonant pumping near the linear natural frequency

Chapter 10 found the linearized in-phase mode at ω1=(2−2)g/l\omega_1=\sqrt{(2-\sqrt2)g/l}. Let’s drive the shoulder with τ(t)=τ0cos⁡(Ωt)\tau(t)=\tau_0\cos(\Omega t) at Ω≈ω1\Omega\approx\omega_1, starting from rest at the bottom, and watch the (nonlinear) response amplitude build up — the same resonance phenomenon as Chapter 2’s SDOF Bode peak, now in a coupled nonlinear multi-body system.

tau_sym = sp.symbols("tau_num")
th1dd_expr = qdd_sol[0].subs(tau, tau_sym)
th2dd_expr = qdd_sol[1].subs(tau, tau_sym)
args = (th1, th2, sp.diff(th1, t), sp.diff(th2, t), tau_sym, m, l, g)
th1dd_f = sp.lambdify(args, th1dd_expr, "numpy")
th2dd_f = sp.lambdify(args, th2dd_expr, "numpy")

m_val, l_val, g_val = 1.0, 1.0, 9.81
w1_lin = np.sqrt((2 - np.sqrt(2)) * g_val / l_val)
tau0 = 0.05


def deriv(tt, y, Omega):
    a1, a2, w1, w2 = y
    tq = tau0 * np.cos(Omega * tt)
    return [w1, w2, th1dd_f(a1, a2, w1, w2, tq, m_val, l_val, g_val),
            th2dd_f(a1, a2, w1, w2, tq, m_val, l_val, g_val)]


tt = np.linspace(0, 60, 6000)
fig, ax = plt.subplots()
for Omega, label in [(w1_lin, r"$\Omega=\omega_1$ (resonant)"),
                      (1.6 * w1_lin, r"$\Omega=1.6\,\omega_1$ (off-resonance)")]:
    sol = solve_ivp(deriv, [tt[0], tt[-1]], [0, 0, 0, 0], t_eval=tt, args=(Omega,),
                     max_step=0.01, rtol=1e-8, atol=1e-8)
    ax.plot(tt, np.rad2deg(sol.y[0]), label=label)

ax.set_xlabel("t [s]"); ax.set_ylabel(r"$\theta_1$ [deg]")
ax.set_title(r"Shoulder-torque-driven double pendulum: resonant vs. off-resonant forcing")
ax.legend()
plt.show()
<Figure size 700x400 with 1 Axes>