Foundations to Frontier
Tests
A. Mathematical Foundations › A3 Calculus and Analysis › Real and functional analysis

Calculus of Variations: Functionals and the Euler–Lagrange Equation

Instead of finding the best number, find the best function: the fastest slide, the shortest path, the shape of a soap film, the trajectory nature actually follows. Setting the first variation of a functional to zero gives the Euler–Lagrange equation, an ODE the optimal function must satisfy. Hamilton's principle of least action derives all of mechanics this way, and optimal control and trajectory optimization for robots and spacecraft are its modern descendants.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

The best shape, not the best number

Which slide gets a marble from the top to a point lower down fastest? Most people guess the straight line, since it’s the shortest. It’s wrong! A curve that dips steeply first lets the marble build speed early and wins the race. Johann Bernoulli posed this puzzle in 1696, and the answer is a curve called a cycloid, the path traced by a point on a rolling wheel.

Here you’re not choosing a number but a whole curve. Rules that give a score to a whole function are called functionals, and finding the best function is the calculus of variations.

Fastest slide: the brachistochrone race
t = 0.000 s
AB
■ straight line: 1.1890 s
■ circle arc: 1.0285 s
■ y ∝ x^0.50: 1.0130 s
■ cycloid: 1.0030 s ← fastest
Theory: the cycloid time is π√(R/g) = 1.0030 s, and no curve beats it.
The straight line is the shortest path but not the fastest: a steep start builds speed early. Too steep (small p) and the bead dives too deep and wastes distance. The optimum, a cycloid, is the solution of the Euler–Lagrange equation for the travel-time functional ∫√(1+y′²)/√(2gy) dx.
Why engineers care

A rocket’s ascent path, a robot arm’s smoothest motion, a satellite’s fuel-optimal transfer orbit: each is “find the best function”. Nature works this way too. Every law of motion can be written as “the path that makes the action stationary”.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The fastest slide between two points at different heights is…
  2. 2. A functional takes ___ and returns ___.
  3. 3. On flat ground, the shortest path between two points is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Functionals

A typical functional is J[y]=∫abL(x,y(x),y′(x)) dxJ[y] = \int_a^bL(x, y(x), y'(x))\,dx, with fixed end values y(a)y(a) and y(b)y(b). The function LL is called the Lagrangian.

Problem Functional Optimal curve
shortest path ∫1+y′2 dx\int\sqrt{1 + y'^2}\,dx straight line
brachistochrone ∫1+y′22gy dx\int\frac{\sqrt{1 + y'^2}}{\sqrt{2gy}}\,dx cycloid
soap film between rings 2π∫y1+y′2 dx2\pi\int y\sqrt{1 + y'^2}\,dx catenoid y=acosh⁡(x/a)y = a\cosh(x/a)
hanging chain (fixed length) potential energy ∫y1+y′2\int y\sqrt{1+y'^2} catenary
least action ∫(kinetic−potential) dt\int(\text{kinetic} - \text{potential})\,dt Newton’s motion

Like functions, functionals have minima. Like derivatives, they have a “derivative” (the first variation). The minimizer must make it zero.

📝 Quick check (Level 1)
0/3 answered
  1. 1. ∫₀¹ y dx for y = x²?
  2. 2. The length of y = x on [0, 1]?
  3. 3. The minimal soap film between two rings is a…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

The Euler–Lagrange equation

Perturb a candidate by y+εηy + \varepsilon\eta, where η(a)=η(b)=0\eta(a) = \eta(b) = 0 so the endpoints stay fixed. Differentiate at ε=0\varepsilon = 0:

δJ=∫ab(Lyη+Ly′η′)dx=∫ab(Ly−ddxLy′)η dx\delta J = \int_a^b\big(L_y\eta + L_{y'}\eta'\big)dx = \int_a^b\Big(L_y - \frac{d}{dx}L_{y'}\Big)\eta\,dx

The second form comes from integrating by parts; the boundary terms vanish. For this to be 0 for every η\eta, the bracket must vanish (the fundamental lemma):

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

Examples:

  • Length. L=1+y′2L = \sqrt{1 + y'^2} has no yy, so Ly′=y′/1+y′2L_{y'} = y'/\sqrt{1 + y'^2} is constant. Then y′y' is constant: a straight line.
  • Least action. L=12my˙2−mgyL = \tfrac12m\dot y^2 - mgy gives my¨+mg=0m\ddot y + mg = 0, Newton’s law for a projectile. In general, L=T−VL = T - V gives ddt∂T∂q˙=−∂V∂q\frac{d}{dt}\frac{\partial T}{\partial\dot q} = -\frac{\partial V}{\partial q}, which is Lagrangian mechanics.
  • A Beltrami shortcut. If LL doesn’t depend on xx, then L−y′Ly′=constL - y'L_{y'} = \text{const}. That gives the catenary and the brachistochrone quickly.
🐍 Exercise 1: Hamilton's principle, numerically
Minimize the discrete action ∫(½ẏ² − gy) dt with fixed endpoints by solving the tridiagonal discrete Euler–Lagrange system. Recover the exact projectile parabola, and check that perturbations raise the action at second order.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The Euler–Lagrange equation is…
  2. 2. L = T − V in Euler–Lagrange gives…
  3. 3. If L has no explicit x, the conserved quantity is…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Derivation, carefully

Let Φ(ε)=J[y+εη]\Phi(\varepsilon) = J[y + \varepsilon\eta]. Differentiating under the integral (smooth LL) gives Φ′(0)=∫(Lyη+Ly′η′)\Phi'(0) = \int(L_y\eta + L_{y'}\eta'). Integrating Ly′η′L_{y'}\eta' by parts gives [Ly′η]ab−∫ηddxLy′[L_{y'}\eta]_a^b - \int\eta\frac{d}{dx}L_{y'}, and the bracket vanishes because η(a)=η(b)=0\eta(a) = \eta(b) = 0.

Fundamental lemma of the calculus of variations. If gg is continuous and ∫gη=0\int g\eta = 0 for every smooth η\eta vanishing at the ends, then g≡0g\equiv0. Otherwise pick η≥0\eta\ge0 as a bump where g>0g > 0, and the integral is positive. ∎

In Hilbert-space language (A3.5-5), g=Ly−ddxLy′g = L_y - \frac{d}{dx}L_{y'} is the gradient of JJ in L2L^2, so Euler–Lagrange says “the gradient is zero”. This viewpoint makes the calculus of variations a direct sibling of A3.5-10’s Fréchet derivatives.

Beltrami identity

If L=L(y,y′)L = L(y, y'), then ddx(L−y′Ly′)=Lyy′+Ly′y′′−y′′Ly′−y′ddxLy′=y′(Ly−ddxLy′)=0\frac{d}{dx}(L - y'L_{y'}) = L_yy' + L_{y'}y'' - y''L_{y'} - y'\frac{d}{dx}L_{y'} = y'\big(L_y - \frac{d}{dx}L_{y'}\big) = 0 on extremals. For the brachistochrone, L=1+y′2/yL = \sqrt{1+y'^2}/\sqrt y gives y(1+y′2)=Cy(1 + y'^2) = C, which is solved by the cycloid.

Minimum, maximum or saddle?

δJ=0\delta J = 0 only gives stationary functions, the analogue of critical points. The second variation decides, through the Legendre condition Ly′y′≥0L_{y'y'}\ge0 (needed for a minimum) and the Jacobi conjugate-point test. “Least” action is really stationary action. Over long times a physical path can stop being a minimum, as on a sphere beyond antipodal points.

Constraints: Lagrange multipliers again

To extremize J[y]J[y] subject to K[y]=cK[y] = c (for example, fixed length), apply Euler–Lagrange to L+λ⋅(constraint integrand)L + \lambda\cdot(\text{constraint integrand}), as in A3.2-9. Dido’s problem, the maximum area with fixed perimeter, gives a circle (Practice Code 5). The hanging chain of fixed length gives a catenary.

Exercise 3.1: Derive the Euler–Lagrange equation for L = ½y′² − ½y² and solve it with y(0) = 0, y(π/2) = 1

Ly′=y′L_{y'} = y' and Ly=−yL_y = -y, so y′′+y=0y'' + y = 0. The solution is y=Acos⁡x+Bsin⁡xy = A\cos x + B\sin x, and the boundary values give A=0A = 0, B=1B = 1, so y=sin⁡xy = \sin x.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The boundary terms vanish in the derivation because…
  2. 2. δJ = 0 guarantees a…
  3. 3. Dido's problem (max area, fixed perimeter) gives a…

Level 4: Expert

★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.

Direct methods: discretize, then optimize

In practice, instead of solving the Euler–Lagrange ODE (a two-point boundary-value problem), you can discretize the functional and optimize the finite-dimensional problem directly. This is direct transcription. It’s how modern trajectory optimizers work:

  • direct collocation (Hargraves and Paris, 1987; Kelly, 2017);
  • pseudospectral methods, which planned NASA’s zero-propellant space-station maneuvers (Bedrossian, Bhatt, Kang and Ross, 2009);
  • multiple shooting.

For the brachistochrone, a polygonal chute’s travel time is exact segment by segment: Δt=2L/(vi+vi+1)\Delta t = 2L/(v_i + v_{i+1}). So optimizing 39 interior heights by BFGS recovers the cycloid (Exercise 2).

🐍 Exercise 2 (research): solve the brachistochrone by direct transcription
Write the exact travel time of a bead on a polygonal chute and its gradient. Optimize the interior heights with BFGS (keeping y > 0), and compare the time and shape with Bernoulli's cycloid and the straight line.

From variations to optimal control and learning

  • Optimal control generalizes the calculus of variations to min⁡∫ℓ(x,u) dt\min\int\ell(x,u)\,dt subject to x˙=f(x,u)\dot x = f(x,u).
    • Pontryagin’s maximum principle (1956) adds costate (adjoint) equations, which are the Euler–Lagrange equations with multipliers. It allows bounded controls, giving bang-bang rocket thrust.
    • The adjoint equations are the continuous-time ancestor of backpropagation (A3.3-5) and of Neural-ODE adjoint training (Chen et al., 2018).
  • Robotics. CHOMP (Ratliff et al., 2009) and TrajOpt (Schulman et al., 2014) optimize trajectory functionals: smoothness ∫‖ẍ‖² plus obstacle cost, using functional gradient descent. Minimum-jerk models of human reaching come from minimizing ∫‖x⃛‖² (Flash and Hogan, 1985).
  • Variational integrators. Discretizing the action rather than the equations gives integrators that conserve momentum and nearly conserve energy for very long simulations of orbits, molecules and multibody robots (Marsden and West, 2001). That’s Exercise 1’s idea taken seriously.
  • Variational inference minimizes a functional (the KL divergence, or the negative ELBO) over distributions. Its stationarity conditions give mean-field updates, the calculus of variations in probability space (Blei, Kucukelbir and McAuliffe, 2017).

References

  1. I. M. Gelfand, S. V. Fomin (1963). Calculus of Variations. Prentice Hall (Dover reprint).
  2. J. Bernoulli (1696). “Problema novum ad cujus solutionem mathematici invitantur.” Acta Eruditorum.
  3. L. Pontryagin, V. Boltyanskii, R. Gamkrelidze, E. Mishchenko (1962). The Mathematical Theory of Optimal Processes. Wiley.
  4. C. Hargraves, S. Paris (1987). “Direct trajectory optimization using nonlinear programming and collocation.” Journal of Guidance, Control, and Dynamics, 10(4).
  5. M. Kelly (2017). “An introduction to trajectory optimization: how to do your own direct collocation.” SIAM Review, 59(4).
  6. N. Bedrossian, S. Bhatt, W. Kang, I. M. Ross (2009). “Zero-propellant maneuver guidance.” IEEE Control Systems Magazine, 29(5).
  7. N. Ratliff, M. Zucker, J. A. Bagnell, S. Srinivasa (2009). “CHOMP: gradient optimization techniques for efficient motion planning.” ICRA.
  8. T. Flash, N. Hogan (1985). “The coordination of arm movements: an experimentally confirmed mathematical model.” Journal of Neuroscience, 5(7).
  9. J. Marsden, M. West (2001). “Discrete mechanics and variational integrators.” Acta Numerica, 10.
  10. D. Blei, A. Kucukelbir, J. McAuliffe (2017). “Variational inference: a review for statisticians.” JASA, 112.