Calculus of Variations
The calculus of variations finds functions (not numbers) that minimise an integral — the shortest path, the fastest slide, the shape of a hanging cable, the path of light. Learn functionals, the first variation, the Euler–Lagrange equation, the Beltrami identity, constraints via Lagrange multipliers, natural boundary conditions, and the link to Hamilton's principle and FEM.
Ordinary calculus asks which x minimises f(x). The calculus of variations asks which curve y(x) minimises J[y] = ∫F(x, y, y′)dx. Setting the 'derivative' of J to zero gives a differential equation — the Euler–Lagrange equation — whose solution is the optimal curve.
Nature seems to optimise: light takes the least-time path (Fermat), mechanical systems follow least action (Hamilton), soap films minimise area, cables hang to minimise potential energy. Engineering uses the same principle for optimal trajectories and finite elements.
An analogy
Imagine wiggling a rope pinned at both ends. The optimal shape is one where any tiny wiggle doesn't change the total cost to first order — just as the bottom of a valley is flat.
Functions of functions
A functional takes a whole curve and returns a number: the length of a path, the time to slide down it, the energy stored in a deflected beam. The question is which curve gives the smallest number.
Deriving Euler–Lagrange
Perturb the optimum: y → y + εη with η(a) = η(b) = 0. Require dJ/dε = 0 at ε = 0. Integrate by parts to move the derivative off η: ∫[∂F/∂y − (∂F/∂y′)′]η dx = 0 for every η, so the bracket must vanish — the Euler–Lagrange equation.
Classic results
Each is one Euler–Lagrange solution:
- Shortest path in a plane → straight line
- Brachistochrone → cycloid
- Hanging cable (minimum potential energy with fixed length) → catenary y = c·cosh(x/c)
- Minimal surface of revolution → catenoid
- Beam energy ½∫EI(w″)² − ∫qw → EI w⁗ = q
Optimal control and numerical methods
Optimal control (rocket trajectories, minimum-energy motion) generalises the calculus of variations via Pontryagin's principle. Numerically, functionals are minimised directly: Ritz/FEM discretise y, and direct transcription methods turn trajectory problems into large nonlinear programs. Second-variation (Legendre) conditions distinguish minima from saddles.
Formulas
- Functional:
J[y] = ∫ₐᵇ F(x, y, y′) dx - Euler–Lagrange equation:
∂F/∂y − d/dx (∂F/∂y′) = 0 - Beltrami identity (F has no x):
F − y′ ∂F/∂y′ = constant - Shortest path:
F = √(1 + y′²) → y″ = 0 (straight line) - Brachistochrone time:
T = ∫ √(1 + y′²) / √(2g y) dx → cycloid - Isoperimetric constraint:
Minimise ∫F dx subject to ∫G dx = L: use F + λG - Hamilton's principle:
δ∫(T − V) dt = 0 → Lagrange's equations of motion
Worked example: Shortest path
Given: F = √(1 + y′²)
Find: Extremal.
- ∂F/∂y = 0 → ∂F/∂y′ = const
- y′/√(1 + y′²) = C → y′ = const
Answer: y = mx + c (straight line)
Worked example: Beam equation from energy
Given: J = ∫[½EI(w″)² − qw] dx
Find: Governing ODE.
- For F(w, w″): ∂F/∂w + d²/dx²(∂F/∂w″) = 0
- −q + (EI w″)″ = 0
Answer: EI w⁗ = q
Worked example: Brachistochrone timing
Given: Drop 2 m over π m horizontally
Find: Cycloid vs straight time.
- Cycloid T = π√(a/g) = 1.003 s
- Line T = L√(2/(gh)) = 3.724 × 0.319 = 1.189 s
Answer: Cycloid ≈ 16% faster
Brachistochrone: cycloid versus straight ramp
import numpy as np
g = 9.81
# End point reached by a cycloid with a = 1 after half a turn: (pi, 2) below start
a = 1.0
x_end, y_end = np.pi * a, 2 * a # y measured downward
# Cycloid descent time (exact): T = pi * sqrt(a / g)
T_cyc = np.pi * np.sqrt(a / g)
# Straight ramp from rest: acceleration g*sin(theta) along length L
L = np.hypot(x_end, y_end)
T_line = np.sqrt(2 * L**2 / (g * y_end))
# Numerical check of the cycloid time via the functional T = int ds / v
th = np.linspace(1e-6, np.pi, 200_001)
dx, dy = a * (1 - np.cos(th)), a * np.sin(th) # derivatives wrt theta
ds = np.hypot(dx, dy)
v = np.sqrt(2 * g * a * (1 - np.cos(th)))
T_num = np.trapezoid(ds / v, th)
print(f"cycloid T = {T_cyc:.4f} s (numerical {T_num:.4f} s)")
print(f"straight T = {T_line:.4f} s -> cycloid is {100*(1 - T_cyc/T_line):.1f}% faster")
# cycloid T = 1.0030 s (numerical 1.0030 s)
# straight T = 1.1890 s -> cycloid is 15.6% fasterThe cycloid is faster than the shortest path because it drops steeply first, gaining speed early. The functional evaluated numerically along the cycloid matches the closed-form time.
Common mistakes
- Wrong: Forgetting boundary terms when ends are free. — Right: Free ends give natural BCs: ∂F/∂y′ = 0 there.
- Wrong: Assuming every extremal is a minimum. — Right: Check the second variation (Legendre condition).
- Wrong: Using Beltrami when F depends on x. — Right: Beltrami needs ∂F/∂x = 0.
Applications
- Structures: Cables, arches and minimum-weight design.
- Mechanics: Lagrangian dynamics of robots and mechanisms.
- Trajectory optimisation: Rockets, drones and minimum-time paths.
- Optics & FEM: Fermat's principle; energy-based finite elements.
Key takeaways
- Functionals map curves to numbers.
- δJ = 0 → Euler–Lagrange ODE.
- Line, cycloid, catenary are classic extremals.
- Energy principles connect to mechanics and FEM.
Going further
- Pontryagin's principle: Optimal control with bounded inputs.
- Noether's theorem: Symmetries of the Lagrangian give conservation laws.
- Direct methods: Minimising sequences and existence of minimisers.