
# Lagrangian Mechanics

> Newton tells you what happens *at each instant*: add up the forces, divide by the mass. Lagrange
> asks a stranger, deeper question: of all conceivable histories between two fixed moments, which
> one does nature actually choose? The answer — the path of stationary action — eliminates
> constraint forces, hands out conservation laws, and (as Feynman later showed) is the shadow of a
> quantum sum over every path at once. A cat stalking a sunbeam knew it all along.

## Learning Objectives

After this lesson you will be able to:

1. Reformulate mechanical problems in **generalized coordinates**, counting **degrees of freedom** and bypassing **constraint forces**.
2. Derive the **Euler–Lagrange equation** from stationarity of the **action** $S = \int L\,dt$ via the **calculus of variations**.
3. Construct **Lagrangians** $L = T - V$ and obtain equations of motion for the oscillator, the pendulum, and central potentials.
4. Identify **cyclic coordinates** and extract **conserved conjugate momenta** — Noether's theorem in miniature.
5. Explain why the action controls quantum amplitudes through the phase $e^{iS/\hbar}$ and the **stationary-phase** argument.
6. Classify constraints as **holonomic** or **non-holonomic** and **scleronomic** or **rheonomic**, and state **d'Alembert's principle**.
7. Derive conservation of **energy**, **momentum** and **angular momentum** from the homogeneity of time, the homogeneity of space and the isotropy of space.

---

## Intuition

Newtonian mechanics is *local and forceful*: at every instant, tally the forces and integrate. It
works, but for constrained systems it makes you compute forces you never cared about — the tension
in a pendulum rod, the normal force from a wire — just to eliminate them again.

The Lagrangian view is *global and economical*. Assign every conceivable path $q(t)$ between fixed
endpoints a single number, the action $S[q]$. The physical path is the one where $S$ is
*stationary*: wiggling the path changes $S$ only at second order. Constraint forces never appear
(they do no work along allowed motions), any convenient coordinates work, and symmetries hand you
conservation laws. Quantum mechanics will explain *why* nature grades paths this way: every path
contributes an amplitude of phase $S/\hbar$, and only near the stationary path do the phases agree
and add up.

---

## Theory

### Newton in one paragraph

For a particle of mass $m$, Newton's second law is $m\ddot{\mathbf r} = \mathbf F$. A force is
**conservative** if $\mathbf F = -\nabla V$ for some potential $V(\mathbf r)$; then energy is
conserved: $\frac{d}{dt}\big(\tfrac12 m\dot{\mathbf r}^2\big) = m\ddot{\mathbf r}\cdot\dot{\mathbf r} = -\nabla V\cdot\dot{\mathbf r} = -\frac{dV}{dt}$,
so $\frac{d}{dt}(T + V) = 0$. This framework is
complete in principle — the trouble is practical.

That energy calculation hides a contrast worth seeing once. Under a constant force the momentum
grows at the fixed rate $dp/dt = F$, but the kinetic energy grows at
$dT/dt = \mathbf F\cdot\dot{\mathbf r}$, which rises with the speed:

```qm-demo constant-acceleration-energy

```

### Where Newton gets awkward

A pendulum bob in Cartesian coordinates obeys $m\ddot{\mathbf r} = m\mathbf g + \mathbf T_{\text{rod}}$,
where the rod tension $\mathbf T_{\text{rod}}$ is an unknown **constraint force**: you must solve
for it and then eliminate it, even though the motion is fully described by one angle $\theta$. A
bead on a bent wire is worse — the normal force changes direction along the wire. Newton forces
you to (i) carry unknown constraint forces and (ii) work in coordinates that ignore the geometry.
Both problems have one cure.

### Generalized coordinates

A **holonomic constraint** is a relation $f(\mathbf r_1, \dots, \mathbf r_N, t) = 0$ among
coordinates. A system of $N$ particles with $k$ independent holonomic constraints has
$n = 3N - k$ **degrees of freedom**, and can be described by $n$ independent **generalized
coordinates** $q_1, \dots, q_n$ — any variables that smoothly parametrize the allowed
configurations: the pendulum's $\theta$ ($n = 1$), arc length along the wire, two angles for a
double pendulum. Velocities $\dot q_i$ are their time derivatives; the pair $(q, \dot q)$ fixes
the instantaneous state.

### The action and the Euler–Lagrange equation

A **functional** assigns a number to a whole function. The **action** of a path $q(t)$ between
fixed endpoints $q(t_1) = q_a$, $q(t_2) = q_b$ is

$$
S[q] = \int_{t_1}^{t_2} L\big(q(t), \dot q(t), t\big)\,dt ,
$$

with $L$ the **Lagrangian**. **Hamilton's principle:** the physical path makes $S$ stationary,
$\delta S = 0$. To extract the consequence, deform the path: $q(t) \to q(t) + \epsilon\,\eta(t)$
where $\eta$ is arbitrary and smooth with $\eta(t_1) = \eta(t_2) = 0$ (endpoints pinned). Then
$S(\epsilon)$ is an ordinary function, and stationarity means $dS/d\epsilon|_{\epsilon=0} = 0$ for
*every* $\eta$. Differentiating under the integral with the chain rule,

$$
\frac{dS}{d\epsilon}\bigg|_{0}
= \int_{t_1}^{t_2}\left(\frac{\partial L}{\partial q}\,\eta + \frac{\partial L}{\partial\dot q}\,\dot\eta\right)dt .
$$

Integrate the second term by parts:

$$
\int_{t_1}^{t_2}\frac{\partial L}{\partial\dot q}\,\dot\eta\,dt
= \underbrace{\left[\frac{\partial L}{\partial\dot q}\,\eta\right]_{t_1}^{t_2}}_{=\,0 \text{ since } \eta(t_{1,2})=0}
- \int_{t_1}^{t_2}\frac{d}{dt}\!\left(\frac{\partial L}{\partial\dot q}\right)\eta\,dt ,
$$

so that

$$
\frac{dS}{d\epsilon}\bigg|_0 = \int_{t_1}^{t_2}\left[\frac{\partial L}{\partial q}
- \frac{d}{dt}\!\left(\frac{\partial L}{\partial\dot q}\right)\right]\eta(t)\,dt = 0
\quad\text{for all admissible }\eta .
$$

Now the **fundamental lemma of the calculus of variations**: if $\int_{t_1}^{t_2} M(t)\eta(t)\,dt = 0$
for every smooth $\eta$ vanishing at the endpoints, and $M$ is continuous, then $M \equiv 0$.
(If $M(t^*) > 0$, continuity gives an interval where $M > 0$; a smooth positive bump $\eta$
supported there makes the integral positive — contradiction.) Hence

$$
\boxed{\;\frac{d}{dt}\!\left(\frac{\partial L}{\partial\dot q_i}\right) - \frac{\partial L}{\partial q_i} = 0\;}
\qquad i = 1, \dots, n,
$$

one **Euler–Lagrange equation** per coordinate (for several $q_i$, vary each independently).

> **Caution.** In $\partial L/\partial\dot q$, the symbols $q$ and $\dot q$ are **independent
> slots** of the function $L(q, \dot q, t)$: differentiate treating $\dot q$ as a variable in its
> own right, *then* evaluate along the trajectory. Only the outer $d/dt$ is a total derivative
> along the motion. Conflating the two is the single most common Lagrangian error.

Stationary is all the principle asks for, and the word matters. Below, every path joins the same two
endpoints for the oscillator $L = \tfrac12\dot x^2 - \tfrac12 x^2$; bend one with the bumps
$\eta = \sin(n\pi t/T)$ and watch $S(\epsilon)$ stay flat to first order at the true path. For a
short trip every bump raises $S$, so the true path is a minimum. Let the trip last longer than half a
period, $T > \pi$, and the $n = 1$ bump lowers $S$: the true path is then a saddle of the action,
and still the path the particle takes.

```qm-demo least-action-paths

```

### $L = T - V$ recovers Newton

For a particle in a conservative potential, take $L = T - V = \tfrac12 m\dot{\mathbf r}^2 - V(\mathbf r)$.
Then $\partial L/\partial\dot x_i = m\dot x_i$ and $\partial L/\partial x_i = -\partial V/\partial x_i$,
so Euler–Lagrange gives $m\ddot x_i = -\partial V/\partial x_i$ — exactly $m\ddot{\mathbf r} = -\nabla V$.
Hamilton's principle with $L = T - V$ *is* Newtonian mechanics, repackaged.

> **Caution.** $L = T - V$ is **not** a law of nature. It holds for velocity-independent
> potentials; a charged particle in a magnetic field needs the generalized potential
> $L = \tfrac12 m\mathbf v^2 - q\phi + q\,\mathbf v\cdot\mathbf A$, and dissipative forces like
> friction have no Lagrangian at all. What survives universally is Hamilton's principle itself —
> with the *appropriate* $L$.

### Classifying constraints

Generalized coordinates presupposed holonomic constraints. In general, constraints are sorted
along two independent axes, and both matter later.

**Holonomic or not.** A constraint is holonomic when it is an equation among the coordinates and
possibly time, $f(\mathbf r_1, \dots, \mathbf r_N, t) = 0$; each one removes a degree of freedom. A
particle confined to the surface $z = g(x, y)$ keeps two coordinates. Differentiating along the
motion gives a relation among velocities, $\dot z - g_x\dot x - g_y\dot y = 0$, but an *integrable*
one: it is the time derivative of the holonomic equation. A **non-holonomic** constraint admits no
such equation, and comes in two kinds:

- **Non-integrable velocity constraints**, $f(q, \dot q, t) = 0$. The standard example is a coin of
  radius $R$ rolling upright without slipping on a table. Its configuration needs four coordinates:
  the contact point $(x, y)$, the heading $\varphi$ and the rotation angle $\psi$. Rolling imposes
  $\dot x = R\dot\psi\cos\varphi$ and $\dot y = R\dot\psi\sin\varphi$, and these cannot be integrated
  into relations among $x, y, \varphi, \psi$: by rolling along suitable paths the coin reaches *every*
  configuration (E6). The velocities are restricted; the configurations are not, so no coordinate
  can be eliminated.
- **Inequalities**: molecules confined to a box, $0 \le x \le L$, or a particle sliding on the
  outside of a sphere, $r \ge a$, which may fly off. They bind only on part of the motion, and the
  problem has to be solved piecewise.

Non-holonomic constraints need extra machinery (Lagrange multipliers, [Gold] §2.4). Every system in
this term is holonomic.

**Time-dependent or not.** A constraint with no explicit time dependence is **scleronomic**: a
bead on a fixed wire. One with explicit $t$ is **rheonomic**: a bead on a wire turned by a motor
(Example 2 below), or a pendulum whose support is driven up and down. The distinction decides, in
[P.1.4](04-hamiltonian-mechanics.md), whether the Hamiltonian equals the energy.

**Why constraint forces drop out.** A **virtual displacement** $\delta\mathbf r_i$ is an infinitesimal
change of configuration allowed by the constraints *frozen at one instant* $t$. Ideal constraints,
such as frictionless surfaces, rigid rods and rolling without slipping, exert forces that do no work in
any virtual displacement: a normal force is perpendicular to every displacement along its surface.
Newton's law $\mathbf F_i = m_i\ddot{\mathbf r}_i$, with $\mathbf F_i$ split into applied and constraint
parts, then collapses to **d'Alembert's principle**:

$$
\sum_i\big(\mathbf F_i^{(\text{applied})} - m_i\ddot{\mathbf r}_i\big)\cdot\delta\mathbf r_i = 0 .
$$

Expanding $\delta\mathbf r_i = \sum_j(\partial\mathbf r_i/\partial q_j)\,\delta q_j$ in independent
$\delta q_j$, and using the two identities
$\partial\dot{\mathbf r}_i/\partial\dot q_j = \partial\mathbf r_i/\partial q_j$ and
$\frac{d}{dt}(\partial\mathbf r_i/\partial q_j) = \partial\dot{\mathbf r}_i/\partial q_j$, the
acceleration term becomes $\frac{d}{dt}\frac{\partial T}{\partial\dot q_j} - \frac{\partial T}{\partial q_j}$,
so

$$
\frac{d}{dt}\!\left(\frac{\partial T}{\partial\dot q_j}\right) - \frac{\partial T}{\partial q_j} = Q_j,
\qquad Q_j \equiv \sum_i\mathbf F_i^{(\text{applied})}\cdot\frac{\partial\mathbf r_i}{\partial q_j} ,
$$

with $Q_j$ the **generalized force** conjugate to $q_j$. When the applied forces derive from a
potential, $Q_j = -\partial V/\partial q_j$, and this is the Euler–Lagrange equation for $L = T - V$
derived above from Hamilton's principle, now reached by a completely independent route
([Gold] §1.4). Note the word *virtual*: a moving constraint can do real work, as the motor turning
the wire in Example 2 does, but never virtual work, because a virtual displacement freezes the
constraint.

### Three worked systems

**Harmonic oscillator.** $L = \tfrac12 m\dot x^2 - \tfrac12 kx^2$. Euler–Lagrange:
$\frac{d}{dt}(m\dot x) = -kx$, i.e. $\ddot x = -\omega^2 x$ with $\omega = \sqrt{k/m}$; solution
$x = A\cos(\omega t + \varphi)$.

Here $\omega$ is an *angular* frequency; the cycles per second are $f = \omega/2\pi$. The damping
slider goes beyond $L = T - V$ (friction has no Lagrangian, as the caution above warns), but it
shows what the ideal oscillator's constant amplitude is being compared against:

```qm-demo mass-spring-oscillation

```

**Simple pendulum** (length $\ell$, mass $m$). One generalized coordinate $\theta$:
$x = \ell\sin\theta$, $y = -\ell\cos\theta$, so $T = \tfrac12 m\ell^2\dot\theta^2$ and
$V = -mg\ell\cos\theta$:

$$
L = \tfrac12 m\ell^2\dot\theta^2 + mg\ell\cos\theta
\quad\Longrightarrow\quad
m\ell^2\ddot\theta = -mg\ell\sin\theta
\quad\Longrightarrow\quad
\ddot\theta = -\frac{g}{\ell}\sin\theta .
$$

This is the **exact** equation — no rod tension ever appeared. For small angles
$\sin\theta \approx \theta$ and the pendulum is an oscillator with $\omega = \sqrt{g/\ell}$.

Put the two systems side by side under one gravity slider. Hang the spring vertically and $mg$
only shifts its equilibrium, leaving $\omega = \sqrt{k/m}$ untouched; for the pendulum, gravity
*is* the restoring force:

```qm-demo hanging-spring-equilibrium

```

**Particle in a central potential** (plane polar coordinates $r, \theta$). With
$T = \tfrac12 m(\dot r^2 + r^2\dot\theta^2)$,

$$
L = \tfrac12 m\big(\dot r^2 + r^2\dot\theta^2\big) - V(r):
\qquad
m\ddot r = mr\dot\theta^2 - V'(r), \qquad
\frac{d}{dt}\big(mr^2\dot\theta\big) = 0 .
$$

The $\theta$ equation says $p_\theta = mr^2\dot\theta$ is **conserved** — the angular momentum
(this is Kepler's second law: equal areas in equal times). This conserved $p_\theta$ is the seed
of the quantum theory of angular momentum in
[P.6.1](../c06-angular-momentum/01-central-potentials-angular-momentum.md).

Conserving $p_\theta$ is not conserving $\mathbf p$: $L$ does not depend on $\theta$, but written in
$x$ and $y$ it depends on both. On a circular orbit at constant speed the angular momentum stays
fixed while the linear momentum turns continuously:

```qm-demo circular-momentum

```

### Cyclic coordinates and conservation

Define the **conjugate (canonical) momentum** $p_i = \partial L/\partial\dot q_i$. If $L$ does not
depend on some $q_j$ — a **cyclic** coordinate — Euler–Lagrange collapses to $\dot p_j = 0$:
**the conjugate momentum of a cyclic coordinate is conserved**. Free particle: $x$ cyclic,
$p = m\dot x$ conserved. Central potential: $\theta$ cyclic, $p_\theta$ conserved. This is
**Noether's theorem** in its simplest form — each continuous symmetry of $L$ (here, invariance
under shifting $q_j$) produces a conservation law. In quantum mechanics the same logic returns as
"observables commuting with the Hamiltonian are conserved"
([1.1.3](../../term-1-quantum-mechanics/c01-postulates/03-evolution-postulate.md)).

The full statement is worth having. **Noether's theorem:** if the action is unchanged by a
continuous family of transformations ($L$ unchanged, or changed only by a total time derivative),
then some quantity is conserved along every solution. Shifting every position along a direction
$\hat{\mathbf n}$ conserves the total momentum along $\hat{\mathbf n}$; rotating about an axis
conserves the angular momentum about that axis; shifting time, $\partial L/\partial t = 0$,
conserves the energy function $h = \sum_i \dot q_i\,\partial L/\partial \dot q_i - L$. The
hypothesis is a symmetry of the *action*. A transformation that only maps solutions to solutions,
such as rescaling $x \to \lambda x$ for the oscillator, whose equation of motion is linear,
multiplies $L$ by $\lambda^2$ and yields no conserved quantity. None of the three laws is
automatic: each holds exactly as long as its symmetry does.

```qm-demo noether-symmetries

```

### The three classic symmetries, derived

Every isolated system has three symmetries, which follow from the properties classical mechanics
assumes for space and time. Each can be turned into its conservation law by hand. Take $N$ particles
with $L = \sum_a\tfrac12 m_a\dot{\mathbf r}_a^2 - V(\mathbf r_1, \dots, \mathbf r_N)$, and write
$\mathbf p_a = \partial L/\partial\dot{\mathbf r}_a$, so that Euler–Lagrange reads
$\dot{\mathbf p}_a = \partial L/\partial\mathbf r_a$.

**Homogeneity of time → energy.** If no instant is special, $L$ has no explicit time dependence.
Along a motion, the chain rule and Euler–Lagrange give

$$
\frac{dL}{dt} = \sum_i\Big(\frac{\partial L}{\partial q_i}\dot q_i + \frac{\partial L}{\partial\dot q_i}\ddot q_i\Big) + \frac{\partial L}{\partial t}
= \sum_i\frac{d}{dt}\Big(\dot q_i\frac{\partial L}{\partial\dot q_i}\Big) + \frac{\partial L}{\partial t},
\quad\text{so}\quad
\frac{dh}{dt} = -\frac{\partial L}{\partial t},
\qquad h \equiv \sum_i\dot q_i\frac{\partial L}{\partial\dot q_i} - L .
$$

With $\partial L/\partial t = 0$ the **energy function** $h$ is conserved. To see that $h$ is the
energy, use **Euler's theorem on homogeneous functions**: if $f(\lambda\mathbf x) = \lambda^kf(\mathbf x)$,
differentiating in $\lambda$ at $\lambda = 1$ gives $\sum_i x_i\,\partial f/\partial x_i = kf$. When
the constraints are scleronomic, $T$ is a homogeneous quadratic ($k = 2$) in the velocities, so
$\sum_i\dot q_i\,\partial T/\partial\dot q_i = 2T$, and with a velocity-independent $V$,
$h = 2T - (T - V) = T + V$. The bead on the rotating wire (Example 2) is the instructive exception:
rheonomic, so $h$ is conserved but is *not* $T + V$.

**Homogeneity of space → momentum.** If no place is special, shifting every particle by the same
infinitesimal $\epsilon\hat{\mathbf n}$ ($\delta\mathbf r_a = \epsilon\hat{\mathbf n}$, velocities
unchanged) leaves $L$ unchanged. That is automatic when $V$ depends only on the separations
$\mathbf r_a - \mathbf r_b$. Then
$0 = \delta L = \epsilon\,\hat{\mathbf n}\cdot\sum_a\partial L/\partial\mathbf r_a$ for every
$\hat{\mathbf n}$, so $\sum_a\partial L/\partial\mathbf r_a = \sum_a\dot{\mathbf p}_a = 0$:

$$
\mathbf P = \sum_a m_a\dot{\mathbf r}_a = \text{constant}.
$$

Since $\partial L/\partial\mathbf r_a$ is the force on particle $a$, the same line says the internal
forces sum to zero. Newton's third law is a consequence of the homogeneity of space.

**Isotropy of space → angular momentum.** If no direction is special, rotating the whole system by
an infinitesimal angle $\delta\phi$ about $\hat{\mathbf n}$, which moves positions *and* velocities,
$\delta\mathbf r_a = \delta\phi\,\hat{\mathbf n}\times\mathbf r_a$ and
$\delta\dot{\mathbf r}_a = \delta\phi\,\hat{\mathbf n}\times\dot{\mathbf r}_a$, leaves $L$ unchanged.
Using Euler–Lagrange and the cyclic rule $\mathbf a\cdot(\hat{\mathbf n}\times\mathbf b) = \hat{\mathbf n}\cdot(\mathbf b\times\mathbf a)$,

$$
0 = \delta L = \delta\phi\sum_a\big[\dot{\mathbf p}_a\cdot(\hat{\mathbf n}\times\mathbf r_a)
+ \mathbf p_a\cdot(\hat{\mathbf n}\times\dot{\mathbf r}_a)\big]
= \delta\phi\,\hat{\mathbf n}\cdot\frac{d}{dt}\sum_a\mathbf r_a\times\mathbf p_a .
$$

Since $\hat{\mathbf n}$ is arbitrary, the total angular momentum
$\mathbf J = \sum_a\mathbf r_a\times\mathbf p_a$ is conserved. (It is written $\mathbf J$ here only
to keep it apart from the Lagrangian $L$; P.1.4 and P.6 call it $\mathbf L$.)

These are the **seven additive integrals of motion** of an isolated system: the energy, three
components of momentum and three of angular momentum, each the sum of its values over
non-interacting parts ([LL] §§6–9). External fields remove exactly the laws whose symmetries they
break. Near the Earth's surface gravity singles out the vertical, so $P_x$ and $P_y$ survive but $P_z$
does not (E1), and only $J_z$ survives. A fixed central force singles out a point, so $\mathbf P$ is
lost while all three components of $\mathbf J$ survive (the central-potential example above).

### Why the action matters for quantum mechanics

Feynman's path-integral formulation of quantum mechanics (plain statement — the machinery comes
much later): a quantum particle going from $a$ to $b$ takes **every** path, and each path
contributes a complex amplitude of unit magnitude and phase $S[\text{path}]/\hbar$; the total
amplitude is $\sum_{\text{paths}} e^{iS/\hbar}$. When $S \gg \hbar$, the phase spins wildly as the
path is deformed, and contributions from neighboring paths cancel — *except* near a path where $S$
is stationary, where nearby paths share the same phase and interfere constructively. Classical
mechanics is the **stationary-phase limit** of quantum mechanics: Hamilton's principle is not an
axiom but an interference pattern. Note $\hbar$ has units of action (J·s) — it is precisely the
scale that decides whether $S$ counts as "large". The waves being superposed here are amplitudes
over *paths*, the same superposition logic as
[P.1.1](01-waves-and-the-wave-equation.md).

---

## Worked Examples

### Example 1 — Atwood's machine

Masses $m_1 = 3.00$ kg and $m_2 = 5.00$ kg hang from an inextensible string over a massless,
frictionless pulley. One degree of freedom: let $x$ be the downward displacement of $m_2$ (so
$m_1$ rises by $x$). Then $T = \tfrac12(m_1 + m_2)\dot x^2$ and $V = -m_2gx + m_1gx$, so

$$
L = \tfrac12(m_1 + m_2)\dot x^2 + (m_2 - m_1)gx
\quad\Longrightarrow\quad
(m_1 + m_2)\ddot x = (m_2 - m_1)g .
$$

Hence $\ddot x = g(m_2 - m_1)/(m_1 + m_2) = 9.81 \times 2.00/8.00 = 2.45$ m/s². The string tension
— which Newton's approach must introduce and eliminate — never appeared. (If wanted afterwards:
$T_{\text{str}} = m_1(g + \ddot x) = 36.8$ N.)

### Example 2 — Bead on a uniformly rotating wire

A bead slides without friction on a straight horizontal wire forced to rotate at constant angular
speed $\Omega$ about a vertical axis. Using the distance $r$ from the axis, the bead's position is
$(r\cos\Omega t,\ r\sin\Omega t)$, so $T = \tfrac12 m(\dot r^2 + r^2\Omega^2)$ and $V = 0$:
$L = \tfrac12 m(\dot r^2 + \Omega^2 r^2)$. Euler–Lagrange: $m\ddot r = m\Omega^2 r$, i.e.
$\ddot r = \Omega^2 r$ — the "centrifugal" term emerged automatically from the kinematics. With
$r(0) = r_0$, $\dot r(0) = 0$: $r(t) = r_0\cosh(\Omega t)$. For $\Omega = 2.00$ rad/s,
$r_0 = 0.100$ m: $r(1\,\text{s}) = 0.100\cosh 2 = 0.376$ m — the bead is flung outward. Its kinetic
energy grows (the motor turning the wire does work): energy is *not* conserved here, a subtlety the
Hamiltonian framework will diagnose cleanly in [P.1.4](04-hamiltonian-mechanics.md).

Below, the bead spirals out while its energy $E$ climbs. The flat line beside it is
$h = \dot r\,\partial L/\partial \dot r - L$, conserved because $L$ has no explicit $t$; P.1.4
will call it the Hamiltonian.

```qm-demo h-vs-energy

```

---

## Hands-on (Python)

```python
import numpy as np

# --- The true path is stationary: discretized action for the oscillator ---
# m = k = 1, endpoints x(0) = 0, x(Tf) = 1 with Tf = 1 (< pi => a minimum).
# True solution of xdd = -x through these endpoints: x(t) = sin(t)/sin(1).
m = k = 1.0; Tf = 1.0; N = 2001
t = np.linspace(0.0, Tf, N); dt = t[1] - t[0]

def action(x):
    v  = np.diff(x)/dt                   # velocities on interval midpoints
    xm = 0.5*(x[1:] + x[:-1])            # positions on interval midpoints
    return np.sum(0.5*m*v**2 - 0.5*k*xm**2)*dt

x_true = np.sin(t)/np.sin(1.0)
S0 = action(x_true)
print(f"S_true = {S0:.4f}")              # 0.3210  (analytic: sin(2)/(4 sin^2 1))

# one random smooth perturbation, exactly zero at both endpoints:
rng = np.random.default_rng(0)
modes = np.arange(1, 6)
eta = (rng.normal(size=5)[:, None]*np.sin(np.outer(modes, np.pi*t/Tf))).sum(0)
for eps in (0.01, 0.05, 0.10, 0.20):
    dS = action(x_true + eps*eta) - S0
    print(f"eps = {eps:4.2f}   S - S_true = {dS:+.6f}   dS/eps^2 = {dS/eps**2:.3f}")
# Expected: every dS > 0 and dS/eps^2 = 27.268 for ALL eps -- the first-order
# variation vanishes identically: the true path is stationary (here a minimum).
```

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

# --- Full pendulum vs small-angle solution ---
g, ell = 9.81, 1.0
w0 = np.sqrt(g/ell)                       # small-angle frequency, period 2.006 s
rhs = lambda t, y: [y[1], -(g/ell)*np.sin(y[0])]

t = np.linspace(0, 10, 2000)
fig, axes = plt.subplots(2, 1, figsize=(8, 6))
for th0, ax in zip((0.10, 2.50), axes):
    sol = solve_ivp(rhs, (0, 10), [th0, 0.0], t_eval=t, rtol=1e-9)
    ax.plot(t, sol.y[0], label="exact")
    ax.plot(t, th0*np.cos(w0*t), "--", label="small-angle")
    ax.set(title=f"theta0 = {th0} rad", ylabel="theta (rad)"); ax.legend()
axes[1].set_xlabel("t (s)"); plt.tight_layout(); plt.show()
# Expected: theta0 = 0.10 -> the two curves are indistinguishable.
# theta0 = 2.50 -> exact period ~ 3.29 s (elliptic integral), so the exact
# curve drifts steadily out of phase with the 2.006 s small-angle cosine.
```

---

## Exercises

**E1 (easy).** Write the Lagrangian of a projectile in a vertical plane,
$L = \tfrac12 m(\dot x^2 + \dot y^2) - mgy$, derive both equations of motion, and identify the
conserved momentum.

<details><summary>Solution</summary>

Euler–Lagrange: $\frac{d}{dt}(m\dot x) = 0$ and $\frac{d}{dt}(m\dot y) = -mg$, i.e. $\ddot x = 0$,
$\ddot y = -g$ — projectile motion. $x$ is cyclic, so $p_x = m\dot x$ is conserved (horizontal
translation symmetry).
</details>

**E2 (easy).** A mass hangs from a vertical spring; let $x$ be the downward displacement from the
spring's natural length, so $L = \tfrac12 m\dot x^2 - \tfrac12 kx^2 + mgx$. Find the motion.

<details><summary>Solution</summary>

Euler–Lagrange: $m\ddot x = -kx + mg$. Substituting $u = x - mg/k$: $m\ddot u = -ku$ — simple
harmonic motion at $\omega = \sqrt{k/m}$ about the *shifted* equilibrium $x_{\text{eq}} = mg/k$.
Gravity relocates the center of oscillation but leaves the frequency alone.
</details>

**E3 (medium).** Show that $L' = L + \frac{dF}{dt}$ for any smooth $F(q, t)$ yields the same
Euler–Lagrange equations as $L$.

<details><summary>Solution</summary>

$S'[q] = S[q] + \int_{t_1}^{t_2}\frac{dF}{dt}\,dt = S[q] + F(q_b, t_2) - F(q_a, t_1)$. The added
term depends only on the *fixed* endpoints, so it is the same constant for every admissible path:
$\delta S' = \delta S$, and the stationary paths — hence the equations of motion — coincide. The
Lagrangian of a given system is therefore not unique (a "gauge" freedom).
</details>

**E4 (medium).** Use the Euler–Lagrange equation to prove the shortest path between two points in
a plane is a straight line, starting from the arc-length functional
$J[y] = \int_{x_1}^{x_2}\sqrt{1 + y'^2}\,dx$.

<details><summary>Solution</summary>

Here $x$ plays "time" and $L(y, y') = \sqrt{1 + y'^2}$ has no explicit $y$: $y$ is cyclic, so
$\partial L/\partial y' = y'/\sqrt{1 + y'^2}$ is constant. That forces $y' = \text{const}$, i.e.
$y = ax + b$ — a straight line. The variational machinery is indifferent to what the independent
variable means physically.
</details>

**E5 (hard).** A block of mass $m$ slides on the frictionless face (angle $\alpha$) of a wedge of
mass $M$ that itself slides on a frictionless floor. Find the accelerations of both.

<details><summary>Solution</summary>

Coordinates: wedge position $X$; block displacement $s$ down the incline. The block's position is
$(X + s\cos\alpha,\ h - s\sin\alpha)$, so

$$
T = \tfrac12 M\dot X^2 + \tfrac12 m\big[(\dot X + \dot s\cos\alpha)^2 + \dot s^2\sin^2\alpha\big],
\qquad V = -mgs\sin\alpha .
$$

$X$ is cyclic: $\frac{d}{dt}\big[(M + m)\dot X + m\dot s\cos\alpha\big] = 0$ (total horizontal
momentum), so $(M+m)\ddot X = -m\ddot s\cos\alpha$. The $s$ equation:
$m(\ddot s + \ddot X\cos\alpha) = mg\sin\alpha$. Substituting $\ddot X$:

$$
\ddot s = \frac{(M + m)g\sin\alpha}{M + m\sin^2\alpha}, \qquad
\ddot X = -\frac{mg\sin\alpha\cos\alpha}{M + m\sin^2\alpha}.
$$

Checks: $M \to \infty$ gives $\ddot s \to g\sin\alpha$, $\ddot X \to 0$ ✓. For $M = 2.00$ kg,
$m = 1.00$ kg, $\alpha = 30°$: $\ddot s = 6.54$ m/s², $\ddot X = -1.89$ m/s². Two Newtonian
constraint forces (normal forces on two surfaces) were never computed.
</details>

**E6 (medium).** Classify each constraint as holonomic or non-holonomic and as scleronomic or
rheonomic, and give the number of degrees of freedom where that makes sense: (a) a bead on a fixed
circular hoop; (b) a bead on a circular hoop spinning at constant $\Omega$ about its vertical
diameter; (c) a pendulum whose string is drawn up through a hole at a constant rate,
$\ell(t) = \ell_0 - ct$; (d) a particle sliding on the outside of a fixed sphere of radius $a$;
(e) the upright coin rolling without slipping. For (e), show that every configuration
$(x, y, \varphi, \psi)$ can be reached, so the rolling conditions cannot be integrated.

<details><summary>Solution</summary>

(a) Holonomic ($x^2 + y^2 = R^2$, $z = 0$), scleronomic; one degree of freedom, the angle on the hoop.
(b) Holonomic, rheonomic: the hoop's plane is at azimuth $\varphi = \Omega t$, which contains $t$
explicitly. One degree of freedom, the polar angle $\theta$; its $h$ is conserved but is not the
energy, just like the rotating wire of Example 2. (c) Holonomic, rheonomic
($x^2 + y^2 = \ell(t)^2$); one degree of freedom. (d) The inequality $r \ge a$ is non-holonomic.
While the particle is on the sphere it acts as $r = a$ (two degrees of freedom); it leaves where the
normal force needed to hold it would turn negative, and then it has three. The motion must be solved
piecewise. (e) Non-holonomic and scleronomic. To see non-integrability: rolling along a suitable
curve brings the contact point to any $(x, y)$ with any heading $\varphi$. Then roll once around a
full circle of radius $\rho$: $x$, $y$ and $\varphi$ return to their values, while $\psi$ advances by
$2\pi\rho/R$, which can be anything since $\rho$ is free. Every configuration is therefore reachable,
so no relation $F(x, y, \varphi, \psi) = 0$ restricts them: four coordinates are needed, though at
any instant only two velocities ($\dot\psi$ and $\dot\varphi$) are free.
</details>

---

## Checkpoint

1. What is a generalized coordinate, and which two Newtonian headaches does it cure?
2. Sketch the derivation of the Euler–Lagrange equation. Where exactly is $\eta(t_1) = \eta(t_2) = 0$ used?
3. When is $L = T - V$ valid, and what is a standard counterexample?
4. What is a cyclic coordinate, and what conservation law follows? Give two examples.
5. In the path-integral picture, why do classical paths dominate when $S \gg \hbar$?
6. Why does a non-holonomic constraint not reduce the number of generalized coordinates? What does "virtual" mean in d'Alembert's principle?
7. Which symmetry gives which conservation law, and what extra condition makes the conserved $h$ equal to $T + V$?

<details><summary>Answers</summary>

1. Any variable smoothly parametrizing allowed configurations (one per degree of freedom). It
   eliminates constraint forces and lets you work in coordinates adapted to the geometry.
2. Perturb $q \to q + \epsilon\eta$, expand $S$ to first order, integrate the $\dot\eta$ term by
   parts, and invoke the fundamental lemma. The endpoint conditions kill the boundary term
   $[\,(\partial L/\partial\dot q)\eta\,]_{t_1}^{t_2}$ from the integration by parts.
3. For velocity-independent (conservative) potentials. Counterexample: magnetic forces, which need
   $L = \tfrac12 m\mathbf v^2 - q\phi + q\mathbf v\cdot\mathbf A$; friction has no Lagrangian.
4. A coordinate absent from $L$; its conjugate momentum $p = \partial L/\partial\dot q$ is
   conserved. Free particle ($x$ → linear momentum); central potential ($\theta$ → angular
   momentum $mr^2\dot\theta$).
5. Each path contributes $e^{iS/\hbar}$; away from stationary points of $S$ the phase varies
   rapidly between neighboring paths and contributions cancel, while paths near the stationary
   (classical) one share a phase and add constructively.
6. It restricts velocities, not configurations: every configuration stays reachable (the rolling
   coin), so no coordinate can be eliminated. A virtual displacement is one allowed by the
   constraints frozen at a single instant; ideal constraint forces do no work in such
   displacements, even when a moving constraint does real work.
7. Homogeneity of time gives energy (the conserved $h = \sum\dot q\,\partial L/\partial\dot q - L$),
   homogeneity of space gives momentum, isotropy of space gives angular momentum. $h = T + V$ needs
   scleronomic constraints (so $T$ is quadratic in the velocities, by Euler's theorem) and a
   velocity-independent $V$.

</details>

---

## Further Reading

- **[Gold]** Goldstein, Poole & Safko, Ch. 1–2 — constraints, generalized coordinates, and variational principles; the definitive treatment.
- **[LL]** Landau & Lifshitz, *Mechanics*, §§1–9 — the principle of least action and the conservation laws derived from the symmetries of space and time, famously compact.
- **[Sha]** Shankar, §2.1 — the principle of least action, written with quantization in mind.
- **[Sak]** Sakurai & Napolitano, §2.6 — propagators and Feynman path integrals: $e^{iS/\hbar}$ made precise.

---

← Prev: [Waves & the Wave Equation](01-waves-and-the-wave-equation.md) · Up: [Pre-Term](../README.md) · Next: [Hamiltonian Mechanics](04-hamiltonian-mechanics.md) →
