Search

Search papers and lessons

Calculus of Variations

Level 3 · 15 min read

Calculus of variations finds the whole function that makes a total quantity smallest or largest, by requiring that no small wiggle of it changes that quantity to first order.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Optimization
  • Sign in to see your progress

TL;DR

Ordinary calculus finds the number xx that makes a function f(x)f(x) smallest. Calculus of variations finds the whole function y(x)y(x) that makes a total quantity, called a functional, smallest. The key test is that if yy is optimal, then nudging it slightly in any direction must not change the total to first order. Applying that test gives a differential equation, the Euler–Lagrange equation, that the best curve must satisfy.

Where you'll see it: in finding the shortest path between two points on a curved surface, in classical mechanics where a path minimises the action, and in optimal control, where a controller is chosen to minimise a cost over time.

Intuition

Suppose you want the fastest route for a ball to roll from a high point to a lower one. The answer is not a single number. It is a whole shape, a curve that falls steeply at first and then flattens. You need to compare entire candidate curves, and the quantity you compare is an integral: the total time along the curve.

Calculus of variations is the standard tool for that. Its objects are curves, and the thing being optimised is a total value that depends on the whole curve. Such a total is called a functional, because it takes a function as input and returns a number.

The figure below shows three candidate curves between the same two endpoints, (0,0)(0,0) and (1,1)(1,1). Each one gives a different total, and the variational problem is to find the one that gives the smallest. Its shape is not obvious in advance, which is why the method is needed.

00.20.40.60.8100.20.40.60.81xy(x)
  • y = x
  • y = x^2
  • y = sinh(x)/sinh(1)
Three curves joining (0,0) to (1,1). Each has its own total value. For the functional in worked example 2, the sinh curve gives the smallest total of the three, and it is not a straight line.

The idea behind the method is simple. At a minimum of an ordinary function, the slope is zero, so a tiny step in any direction changes the value only to second order. The same must hold for a curve. If yy is the best curve, then for any small wiggle added to it, the total must not change to first order. That single requirement is enough to pin down the answer.

The math

The functional

Let y(x)y(x) be a function on an interval [a,b][a, b] with fixed endpoints y(a)=Ay(a) = A and y(b)=By(b) = B. Let F(x,y,p)F(x, y, p) be a known function of three variables, and define the functional

J[y]=∫abF(x, y(x), y′(x)) dx.J[y] = \int_a^b F\big(x,\, y(x),\, y'(x)\big)\, dx.

Here y′(x)y'(x) is the derivative of yy with respect to xx, and the square brackets around yy are the usual notation for "a functional of the function yy". The task is to find the yy that makes J[y]J[y] as small as possible among all curves that satisfy the endpoint conditions.

The first variation

Pick any smooth function η(x)\eta(x) with η(a)=η(b)=0\eta(a) = \eta(b) = 0. This is a wiggle that does not move the endpoints. For a small number ε\varepsilon, define the perturbed curve yε(x)=y(x)+ε η(x)y_\varepsilon(x) = y(x) + \varepsilon\,\eta(x). It still satisfies the endpoint conditions.

Define Φ(ε)=J[y+εη]\Phi(\varepsilon) = J[y + \varepsilon \eta]. If yy is optimal, then Φ\Phi has a minimum at ε=0\varepsilon = 0, so Φ′(0)=0\Phi'(0) = 0. Compute that derivative. Differentiating under the integral sign, and using the chain rule from Partial Derivative for the dependence of FF on its second and third arguments, gives

Φ′(0)=∫ab(Fy(x,y,y′) η(x)+Fp(x,y,y′) η′(x)) dx.\Phi'(0) = \int_a^b \Big( F_y(x, y, y')\,\eta(x) + F_p(x, y, y')\,\eta'(x) \Big)\, dx.

Here FyF_y and FpF_p are the partial derivatives of FF with respect to its second and third arguments. The condition Φ′(0)=0\Phi'(0) = 0 must hold for every admissible η\eta.

Removing the derivative of the wiggle

The second term contains η′\eta', which is inconvenient because we want a condition on η\eta itself. Integrate it by parts, which is exactly the move in Integration by Parts. Take u=Fpu = F_p and dv=η′ dxdv = \eta'\,dx, so v=ηv = \eta:

∫abFp η′ dx=[Fp η]ab−∫abddx(Fp) η dx.\int_a^b F_p\,\eta'\,dx = \Big[F_p\,\eta\Big]_a^b - \int_a^b \frac{d}{dx}\big(F_p\big)\,\eta\,dx.

The boundary term vanishes because η(a)=η(b)=0\eta(a) = \eta(b) = 0. Substitute back and collect:

Φ′(0)=∫ab(Fy−ddxFp) η(x) dx=0.\Phi'(0) = \int_a^b \Big( F_y - \frac{d}{dx}F_p \Big)\,\eta(x)\,dx = 0.

The Euler–Lagrange equation

Since η\eta is arbitrary, the only way this integral vanishes for every η\eta is that the bracket is zero everywhere on [a,b][a, b]. That gives the Euler–Lagrange equation:

∂F∂y−ddx(∂F∂y′)=0.\frac{\partial F}{\partial y} - \frac{d}{dx}\left(\frac{\partial F}{\partial y'}\right) = 0.

Any extremal curve, a candidate minimum or maximum, must satisfy it. It is a second-order ordinary differential equation for yy in general, so its solutions form a family, and the endpoint conditions select one member.

The equation is necessary, not sufficient. A solution might be a maximum, or a saddle. When FF is convex in (y,y′)(y, y'), which holds for the examples here, any solution is the global minimum.

Worked examples

Example
The shortest path

The arc length of a curve y(x)y(x) on [a,b][a, b] is J[y]=∫ab1+y′2 dxJ[y] = \int_a^b \sqrt{1 + y'^2}\,dx. Here F(x,y,p)=1+p2F(x, y, p) = \sqrt{1 + p^2} does not depend on yy or xx.

  1. The partial derivative with respect to yy is Fy=0F_y = 0.
  2. The partial derivative with respect to p=y′p = y' is Fp=p1+p2F_p = \dfrac{p}{\sqrt{1+p^2}}.
  3. The Euler–Lagrange equation becomes 0−ddx(y′1+y′2)=00 - \dfrac{d}{dx}\left(\dfrac{y'}{\sqrt{1+y'^2}}\right) = 0.
  4. So y′1+y′2\dfrac{y'}{\sqrt{1+y'^2}} is a constant, call it cc.
  5. Solving p1+p2=c\dfrac{p}{\sqrt{1+p^2}} = c for pp gives p2=c21−c2p^2 = \dfrac{c^2}{1-c^2}, which is constant. So y′=ky' = k for a constant kk.
  6. Integrating gives y=kx+my = kx + m, a straight line.

The equation recovers the obvious answer: the shortest path between two points in a flat plane is a straight line. The method works without knowing that answer in advance.

Example
A quadratic functional with numbers

Minimise J[y]=∫01(y′2+y2) dxJ[y] = \int_0^1 \big(y'^2 + y^2\big)\,dx subject to y(0)=0y(0) = 0 and y(1)=1y(1) = 1.

  1. Here F(x,y,p)=p2+y2F(x, y, p) = p^2 + y^2, so Fy=2yF_y = 2y and Fp=2pF_p = 2p.
  2. The Euler–Lagrange equation is 2y−ddx(2y′)=02y - \dfrac{d}{dx}(2y') = 0, which simplifies to y′′=yy'' = y.
  3. The general solution is y(x)=Acosh⁡x+Bsinh⁡xy(x) = A\cosh x + B\sinh x.
  4. The condition y(0)=0y(0) = 0 gives A=0A = 0. The condition y(1)=1y(1) = 1 gives Bsinh⁡1=1B\sinh 1 = 1, so B=1/sinh⁡1B = 1/\sinh 1.
  5. Numerically, sinh⁡1≈1.1752\sinh 1 \approx 1.1752, so y(x)=sinh⁡x/sinh⁡1y(x) = \sinh x / \sinh 1. At x=0.5x = 0.5, sinh⁡0.5≈0.5211\sinh 0.5 \approx 0.5211, so y(0.5)≈0.4434y(0.5) \approx 0.4434.
  6. For the minimal value, use ∫y′2 dx=[y y′]01−∫y y′′ dx=[y y′]01−∫y2 dx\int y'^2\,dx = [y\,y']_0^1 - \int y\,y''\,dx = [y\,y']_0^1 - \int y^2\,dx, which holds because y′′=yy'' = y. Then J=[y y′]01=y(1) y′(1)−y(0) y′(0)=y′(1)J = [y\,y']_0^1 = y(1)\,y'(1) - y(0)\,y'(0) = y'(1).
  7. Since y′(x)=cosh⁡x/sinh⁡1y'(x) = \cosh x / \sinh 1, Jmin⁡=cosh⁡1/sinh⁡1=coth⁡1≈1.3130J_{\min} = \cosh 1 / \sinh 1 = \coth 1 \approx 1.3130.

Compare this to the straight line y=xy = x, which satisfies both endpoint conditions. Its value is ∫01(1+x2) dx=4/3≈1.3333\int_0^1 (1 + x^2)\,dx = 4/3 \approx 1.3333, which is larger than 1.31301.3130. The curve that bends below the line does better, as the Plot above shows.

Tradeoffs and failure modes

Calculus of variations is the right tool when the unknown is a function and the objective is an integral. For other problems, other tools are better.

SituationProblemBetter choice
The curve is smooth and FF is simpleSolving the Euler–Lagrange ODE may be hard, but tractableSolve the ODE analytically, as in example 2
The ODE has no closed formAnalytic solution is out of reachParameterise yy with a few unknowns and minimise numerically (the Ritz method)
There is a constraint such as a fixed lengthThe Euler–Lagrange equation alone ignores itAdd a multiplier term; the constrained problem gives an extended Euler–Lagrange equation
An endpoint is freeNo endpoint condition is fixedUse the natural boundary condition Fp=0F_p = 0 at the free end
The problem is a control problem with dynamicsThe state evolves by an ODE and the input is freeUse optimal control and Pontryagin's principle (see Optimal Control)
The curve is not smoothEuler–Lagrange assumes differentiabilityUse a weak or relaxed formulation

A practical warning: finding a solution of the Euler–Lagrange equation does not prove it is the minimum. In a gradient-based numerical search, the same caveat appears as a local minimum. Check convexity or the second variation before trusting a candidate.

History

Johann Bernoulli posed the brachistochrone problem, the curve of fastest descent between two points under gravity, in 1696 and challenged the mathematicians of Europe to solve it. Newton, Leibniz, Jakob Bernoulli and others produced solutions, and the cycloid turned out to be the answer. These solutions were ad hoc, each using its own geometry, and the problem stimulated the search for a general method.

In the 1740s Leonhard Euler systematised the approach and gave the general condition that now carries his name. The variation method, using the small perturbation η\eta and the first-variation argument, is usually credited to Joseph-Louis Lagrange in the 1750s, who worked out the notation that is still used. The equation became central to classical mechanics: Lagrange's formulation of mechanics expresses the equations of motion as the stationarity of an action functional.

It caught on because it turned many separate problems into one procedure, and because the same condition describes both the shortest path in geometry and the trajectory of a physical system.

Check yourself

QuestionWhy must the variation η\eta vanish at the endpoints aa and bb?Show answer

The endpoint values of the optimal curve are fixed by the problem, y(a)=Ay(a) = A and y(b)=By(b) = B. The perturbed curve y+εηy + \varepsilon\eta must satisfy the same conditions to be an admissible competitor. If η(a)≠0\eta(a) \neq 0, the perturbation would move the fixed endpoint, and the comparison would not be between valid candidates. The vanishing also kills the boundary term produced by the integration by parts.

QuestionFor the functional J[y]=∫01y2 dxJ[y] = \int_0^1 y^2\,dx with F=y2F = y^2 and no derivative term, write down the Euler–Lagrange equation and solve it.Show answer

The equation is ∂F/∂y−ddx(∂F/∂y′)=0\partial F/\partial y - \dfrac{d}{dx}\big(\partial F/\partial y'\big) = 0. Here ∂F/∂y=2y\partial F/\partial y = 2y and ∂F/∂y′=0\partial F/\partial y' = 0, so the equation is 2y=02y = 0, giving y(x)=0y(x) = 0 for all xx. With endpoint conditions y(0)=y(1)=0y(0)=y(1)=0, the minimum is J=0J = 0, attained by the zero function. This is an edge case: the equation has no derivative term, so the solution is an algebraic constraint rather than a differential equation.

QuestionIn example 1, the shortest path came out to be a straight line without any endpoint-specific computation. Why does the method not need the endpoints to find the shape, and where do they enter?Show answer

The Euler–Lagrange equation is an ODE, and its general solution for the shortest-path problem is a family of straight lines y=kx+my = kx + m. The shape (straightness) is fixed by the structure of FF. The endpoints enter only when you fix the two constants kk and mm using y(a)=Ay(a) = A and y(b)=By(b) = B. So the endpoints choose which line, but not the fact that it is a line.

QuestionA chemical plant needs to choose a temperature profile T(t)T(t) over an hour to minimise a cost integral. Why is the Euler–Lagrange equation alone not enough, and what extra structure does the problem need?Show answer

The cost depends on T(t)T(t) and possibly its rate of change, and it is an integral, so calculus of variations applies in principle. But a real plant has dynamics: the state evolves according to an ODE driven by the control, and the temperature is often bounded. The Euler–Lagrange equation ignores both. The problem needs optimal control, with a Hamiltonian and Pontryagin's principle, which generalises the first-variation argument to controls with constraints. The basic variational idea remains the foundation.

Sources