Skip to content
AI360Xpert
Beta

Calculus of Variations

Ordinary calculus picks the best number; calculus of variations picks the best curve. The Euler-Lagrange equation turns that infinite search into a differential equation for the winner.

The straight segment from 0 0 to 2 1 undercuts the parabola through the same endpoints, 2.24 against 2.32
The straight segment from 0 0 to 2 1 undercuts the parabola through the same endpoints, 2.24 against 2.32

Why Does This Exist?

Shortest paths, fastest slides, least-action physics and minimum-energy splines all ask for the best function, not the best number. Brute-force search over curves is impossible, and discretizing first begs the question (the grid picks the answer). The calculus of variations converts the search into a differential equation: any minimizer must satisfy Euler-Lagrange, so candidates come from ODE theory instead of guessing.

This page derives that equation and proves the straight line wins. Finite-dimensional constraints are constrained optimisation and duality; optimality certificates are KKT conditions.

The one idea you need first

A functional J[y]=∫abL(x,y,y′)dxJ[y] = \int_a^b L(x, y, y') dx scores whole curves with a running cost LL. A variation y+ϵηy + \epsilon \eta wiggles the curve (η\eta zero at endpoints). Optimality demands the first wiggle change nothing: δJ=0\delta J = 0.

Think of It Like This

The fastest sled run down a hill

A sled hill offers infinite routes from top to bottom. Timing each is hopeless, but physics says the winner must satisfy a local balance at every point: steepen where speed pays, flatten where it does not. That balance is Euler-Lagrange, and it narrows infinity to a few candidate tracks.

The straight line is not always the winner (the brachistochrone curves to bank speed early). Where it stops: the equation finds stationarity, not victory. Maxima, saddles and unstable extremals satisfy it too; second-variation or direct comparison picks the true minimizer.

How It Actually Works

Wiggle yy by ϵη\epsilon \eta and expand to first order; integration by parts moves derivatives off η\eta:

ddϵJ[y+ϵη]∣0=∫ab(∂L∂y−ddx∂L∂y′)η dx=0\frac{d}{d\epsilon}J[y + \epsilon\eta]\Big|_0 = \int_a^b \left(\frac{\partial L}{\partial y} - \frac{d}{dx}\frac{\partial L}{\partial y'}\right)\eta \, dx = 0

In plain words: LL prices position and slope, η\eta is an arbitrary wiggle vanishing at the ends, and since the integral must vanish for every wiggle, the bracket does too. That bracket is the Euler-Lagrange equation:

∂L∂y−ddx∂L∂y′=0\frac{\partial L}{\partial y} - \frac{d}{dx}\frac{\partial L}{\partial y'} = 0

For length L=1+(y′)2L = \sqrt{1 + (y')^2}: ∂L/∂y=0\partial L/\partial y = 0, so ddx(y′/1+(y′)2)=0\frac{d}{dx}(y'/\sqrt{1+(y')^2}) = 0, giving y′=Cy' = C and y′′=0y'' = 0: straight lines.

Worked example

From (0,0)(0,0) to (2,1)(2,1): straight y=x/2y = x/2, length ∫021+1/4 dx=21.25=5≈2.236\int_0^2 \sqrt{1 + 1/4}\,dx = 2\sqrt{1.25} = \sqrt{5} \approx 2.236. Rival parabola y=x2/4y = x^2/4 (same endpoints: 00 and 11 ✓): length ∫021+x2/4 dx\int_0^2 \sqrt{1 + x^2/4}\,dx. Split at midpoint Simpson with h=1h = 1: values 1=1\sqrt{1} = 1, 1.25≈1.118\sqrt{1.25} \approx 1.118, 2≈1.414\sqrt{2} \approx 1.414: length ≈(1+4(1.118)+1.414)/3=6.886/3≈2.295\approx (1 + 4(1.118) + 1.414)/3 = 6.886/3 \approx 2.295. True value ≈2.32\approx 2.32.

Straight 2.2362.236 beats parabola 2.322.32 by 0.080.08: Euler-Lagrange's prediction confirmed by direct measurement.

Code

Quadrature lengths confirm the straight line undercuts the parabola.

import numpy as np

def length(ys: np.ndarray, dx: float) -> float:    slopes = np.diff(ys) / dx  # segment slopes along the curve    return float(np.sqrt(1 + slopes**2).sum() * dx)  # sum of segment lengths

x = np.linspace(0.0, 2.0, 2001)print(round(length(x / 2, x[1] - x[0]), 3))  # -> 2.236print(round(length(x**2 / 4, x[1] - x[0]), 3))  # -> 2.295 approx

2.2362.236 versus about 2.302.30: the minimizer wins on the nose.

Watch Out For

Calling every extremal a minimizer

Symptom: Euler-Lagrange solved, solution shipped, yet a rival curve scores lower (saddle or maximizer). Fix: compare values directly or check Legendre's strengthened second-variation condition; stationarity alone never certifies minimality.

Varying with endpoints nailed down wrong

Symptom: boundary terms dropped when endpoints are actually free, losing the transversality condition and admitting false extremals. Fix: keep the [∂L/∂y′⋅η][\partial L/\partial y' \cdot \eta] boundary term unless variations truly vanish there.

The Quick Version

  • Functionals score curves; vanishing first variation gives the Euler-Lagrange equation.
  • Length Lagrangians yield y′′=0y'' = 0: minimizers are straight lines.
  • (0,0)(0,0) to (2,1)(2,1): straight measures 5≈2.24\sqrt{5} \approx 2.24, parabola about 2.322.32.
  • Extremals can be maxima or saddles; direct comparison certifies the winner.
  • Free endpoints need transversality terms that fixed-endpoint problems drop.