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:

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

Worked example: Shortest path

Given: F = √(1 + y′²)

Find: Extremal.

Answer: y = mx + c (straight line)

Worked example: Beam equation from energy

Given: J = ∫[½EI(w″)² − qw] dx

Find: Governing ODE.

Answer: EI w⁗ = q

Worked example: Brachistochrone timing

Given: Drop 2 m over π m horizontally

Find: Cycloid vs straight time.

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% faster

The 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

Applications

Key takeaways

Going further