ponderance / anmol
← Marginalia

physics · math

Lagrangian mechanics is just saying δS = 0 and seeing what falls out

The action principle in one line, then the derivation that shows why Euler-Lagrange is the only equation you need.

2026-05-14

The action is the integral of the Lagrangian over time:

S=t1t2L(q,q˙,t)dtS = \int_{t_1}^{t_2} L(q, \dot{q}, t) \, dt

The principle of least action says: the physical path is the one where δS=0\delta S = 0 — small variations around the true path produce no first-order change in SS.

The derivation

Let q(t)q(t) be the true path and q(t)+ϵη(t)q(t) + \epsilon \eta(t) be a variation, where η(t1)=η(t2)=0\eta(t_1) = \eta(t_2) = 0 (the endpoints are fixed). Then:

δS=ddϵϵ=0t1t2L(q+ϵη,q˙+ϵη˙,t)dt=0\delta S = \frac{d}{d\epsilon}\bigg|_{\epsilon=0} \int_{t_1}^{t_2} L(q + \epsilon\eta,\, \dot{q} + \epsilon\dot{\eta},\, t)\, dt = 0

Differentiating under the integral:

t1t2(Lqη+Lq˙η˙)dt=0\int_{t_1}^{t_2} \left( \frac{\partial L}{\partial q}\eta + \frac{\partial L}{\partial \dot{q}}\dot{\eta} \right) dt = 0

Integrate the second term by parts (boundary terms vanish because η\eta is zero at endpoints):

t1t2(LqddtLq˙)ηdt=0\int_{t_1}^{t_2} \left( \frac{\partial L}{\partial q} - \frac{d}{dt}\frac{\partial L}{\partial \dot{q}} \right) \eta \, dt = 0

Since this must hold for all η\eta, the integrand itself must vanish — the Euler-Lagrange equation:

ddtLq˙Lq=0\frac{d}{dt}\frac{\partial L}{\partial \dot{q}} - \frac{\partial L}{\partial q} = 0

A concrete example: the simple pendulum

For a pendulum of length \ell and mass mm, take q=θq = \theta (the angle). Kinetic energy is T=12m2θ˙2T = \frac{1}{2}m\ell^2\dot{\theta}^2, potential energy is V=mgcosθV = -mg\ell\cos\theta (setting V=0V=0 at the pivot). The Lagrangian:

L=TV=12m2θ˙2+mgcosθL = T - V = \frac{1}{2}m\ell^2\dot{\theta}^2 + mg\ell\cos\theta

Applying E-L:

m2θ¨+mgsinθ=0    θ¨+gsinθ=0m\ell^2\ddot{\theta} + mg\ell\sin\theta = 0 \implies \ddot{\theta} + \frac{g}{\ell}\sin\theta = 0

The same equation you’d get from Newton’s second law, but without drawing a single free-body diagram.

Numerical integration

Here’s the small-angle pendulum integrated two ways — the Euler-Lagrange ODE and the equivalent Newtonian form — to confirm they agree:

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

def lagrangian_pendulum(t, y, g=9.81, L=1.0):
    """State: y = [theta, theta_dot]. Returns dy/dt via E-L."""
    theta, theta_dot = y
    return [theta_dot, -(g / L) * np.sin(theta)]

t_span = (0, 10)
y0 = [np.pi / 6, 0.0]  # 30° initial angle, at rest

sol = solve_ivp(lagrangian_pendulum, t_span, y0,
                max_step=0.01, dense_output=True)

t = np.linspace(*t_span, 1000)
theta = sol.sol(t)[0]

plt.plot(t, np.degrees(theta))
plt.xlabel("t (s)")
plt.ylabel("θ (°)")
plt.title("Pendulum: θ(t) from Euler-Lagrange")
plt.tight_layout()
plt.savefig("pendulum.png", dpi=150)

The same physics, in Rust with a hand-rolled RK4:

fn pendulum_rhs(theta: f64, omega: f64, g: f64, l: f64) -> (f64, f64) {
    (omega, -(g / l) * theta.sin())
}

fn rk4_step(theta: f64, omega: f64, dt: f64, g: f64, l: f64) -> (f64, f64) {
    let (k1t, k1o) = pendulum_rhs(theta, omega, g, l);
    let (k2t, k2o) = pendulum_rhs(theta + 0.5*dt*k1t, omega + 0.5*dt*k1o, g, l);
    let (k3t, k3o) = pendulum_rhs(theta + 0.5*dt*k2t, omega + 0.5*dt*k2o, g, l);
    let (k4t, k4o) = pendulum_rhs(theta + dt*k3t, omega + dt*k3o, g, l);

    let new_theta = theta + dt * (k1t + 2.0*k2t + 2.0*k3t + k4t) / 6.0;
    let new_omega = omega + dt * (k1o + 2.0*k2o + 2.0*k3o + k4o) / 6.0;
    (new_theta, new_omega)
}

fn main() {
    let (mut theta, mut omega) = (std::f64::consts::PI / 6.0, 0.0_f64);
    let dt = 0.01_f64;
    for i in 0..1000 {
        (theta, omega) = rk4_step(theta, omega, dt, 9.81, 1.0);
        if i % 100 == 0 {
            println!("t={:.2}s  θ={:.4}°", i as f64 * dt, theta.to_degrees());
        }
    }
}

Both converge to the same trajectory for small angles. For θ020°\theta_0 \lesssim 20°, sinθθ\sin\theta \approx \theta and the period is T2π/gT \approx 2\pi\sqrt{\ell/g} — independent of amplitude, which is the famous isochronous result Galileo observed.

Why this matters for ML

The path-integral formulation of quantum mechanics is a direct generalization: the probability amplitude for a particle to travel from AA to BB is a sum over all paths, weighted by eiS/e^{iS/\hbar}. The Lagrangian framing unifies classical mechanics, field theory, and quantum theory in a single notation. Once you see the world through δS=0\delta S = 0, the equations of motion for everything — electrodynamics, general relativity, the Standard Model — follow from the same one-line principle.

← back to the index