Lagrangian Mechanics: Why Nature Optimises a Functional
Published:
The tension Newton leaves unresolved
Force balance works beautifully in Cartesian coordinates and becomes miserable anywhere else. A bead on a wire, a double pendulum, a rigid body — each needs constraint forces you do not care about and would rather never write down. Change coordinates and $\mathbf{F} = m\mathbf{a}$ changes form; new terms appear that look like forces but are artefacts of the chart.
The variational formulation removes that. You write one scalar function, pick whatever coordinates describe your system with the fewest numbers, and turn a crank.
Action and the stationarity condition
Let $q(t)$ be a trajectory. Define the kinetic energy $T$, the potential energy $V$, the Lagrangian $L(q,\dot q,t) = T - V$, and the action
$S$ is a functional: it eats a whole path and returns a number. The claim is that among all paths with the same endpoints $q(t_1)$ and $q(t_2)$, the physical one makes $S$ stationary — its first variation vanishes.
Deriving Euler–Lagrange
Perturb the path: $q(t) \to q(t) + \varepsilon\,\eta(t)$, where $\eta$ is arbitrary except that it vanishes at both endpoints, $\eta(t_1)=\eta(t_2)=0$, so the endpoints stay fixed. Expanding to first order in $\varepsilon$,
Integrate the second term by parts. The boundary term \(\left[\frac{\partial L}{\partial \dot q}\eta\right]_{t_1}^{t_2}\) vanishes because $\eta$ does, leaving
This must vanish for every admissible $\eta$, which forces the bracket to vanish pointwise — the fundamental lemma of the calculus of variations. Hence the Euler–Lagrange equation:
Note the sign and the order: the time derivative acts on the velocity partial, and the position partial is subtracted.
Checking it reproduces $F = ma$
Take a particle of mass $m$ in one dimension moving in a potential $V(x)$, so $L = \tfrac12 m\dot x^2 - V(x)$. Then
\[\frac{\partial L}{\partial \dot x} = m\dot x, \qquad \frac{d}{dt}\frac{\partial L}{\partial \dot x} = m\ddot x, \qquad \frac{\partial L}{\partial x} = -\frac{dV}{dx}.\]Substituting gives $m\ddot x + \frac{dV}{dx} = 0$, i.e. $m\ddot x = -V’(x) = F$. Newton’s second law falls out, and the minus sign in $L = T - V$ is precisely what turns the potential gradient into a force with the correct direction. Had you written $T+V$, the force would point uphill.
Generalised coordinates: the actual payoff
Now the case where Newton is annoying. A pendulum of mass $m$ and length $\ell$, with $\theta$ measured from the downward vertical. The constraint (fixed length) is absorbed by choosing $\theta$ as the only coordinate — no tension force ever appears.
| quantity | expression |
|---|---|
| kinetic | $T = \tfrac12 m\ell^2\dot\theta^2$ |
| potential | $V = -mg\ell\cos\theta$ |
| Lagrangian | $L = \tfrac12 m\ell^2\dot\theta^2 + mg\ell\cos\theta$ |
| $\partial L/\partial\dot\theta$ | $m\ell^2\dot\theta$ |
| $\partial L/\partial\theta$ | $-mg\ell\sin\theta$ |
Euler–Lagrange gives $m\ell^2\ddot\theta + mg\ell\sin\theta = 0$, so $\ddot\theta = -(g/\ell)\sin\theta$. Three lines, no free-body diagram, no constraint force. A quantity like $m\ell^2\dot\theta$ — the momentum conjugate to $\theta$ — is angular momentum here; in general $p = \partial L/\partial\dot q$ is whatever the coordinate makes it, which is the starting point of Hamiltonian dynamics.
Where this shows up in machine learning
The pattern “define a scalar functional, then take its variation” is everywhere. The ELBO is a functional of a distribution $q$, and setting its variation to zero recovers the optimal $q$ — see entropy and thermodynamics. Gradient descent with vanishing step size is a gradient flow, the steepest-descent path of a functional. Optimal-control views of deep networks treat the layers as a time axis and the loss as a terminal cost, with the adjoint equations of the neural-ODE backward pass playing the role of Euler–Lagrange conditions. And Lagrangian Neural Networks (Cranmer et al., 2020) parameterise $L$ itself with a network, then integrate the Euler–Lagrange equation, so the learned dynamics conserve energy by construction rather than by penalty.
Recap
- Action \(S[q]=\int L\,dt\) with \(L = T - V\); the physical path makes \(\delta S = 0\).
- Euler–Lagrange: \(\frac{d}{dt}\frac{\partial L}{\partial \dot q} - \frac{\partial L}{\partial q} = 0\), derived by integration by parts with fixed endpoints.
- For \(L=\tfrac12 m\dot x^2 - V(x)\) it collapses to \(m\ddot x = -V'(x)\), which is \(F = ma\).
- Generalised coordinates absorb constraints, so constraint forces never appear; the pendulum takes three lines.
- The formulation is portable because \(L\) is a scalar — the same reason ML states objectives as functionals rather than update rules.
References
- Landau, L. D., & Lifshitz, E. M. Mechanics (Course of Theoretical Physics, Vol. 1), 3rd ed. Butterworth-Heinemann, 1976.
- Cranmer, M., Greydanus, S., Hoyer, S., Battaglia, P., Spergel, D., & Ho, S. Lagrangian Neural Networks. ICLR 2020 Workshop on Deep Differential Equations.
- Chen, R. T. Q., Rubanova, Y., Bettencourt, J., & Duvenaud, D. Neural Ordinary Differential Equations. NeurIPS 2018.
