BetaFree coursewareRewritten from MIT OpenCourseWareCC BY-NC-SA 4.0
Open CosmologyPhysics & cosmology, from high school to a graduate year

Lagrange multipliers

To minimise or maximise f when the variables satisfy a constraint g = c, look where the level curves of f and g are tangent: there the gradients are parallel, ∇f = λ∇g. Together with g = c this gives as many equations as unknowns. On the hyperbola xy = 3 the points closest to the origin are (√3, √3) and (−√3, −√3), with λ = 2. The method works because the directional derivative of f is zero in every direction along g = c. It does not say whether a solution is a minimum or a maximum; compare values. A pyramid of least surface area puts its top above the incenter of its base.

You need this first

Full reading path (12 pages)
  1. Vectors (8.01)
  2. Vectors and the dot product (18.02)
  3. Determinants and the cross product (18.02)
  4. Planes through three points, and matrices (18.02)
  5. Equations of planes and square systems (18.02)
  6. Parametric equations of lines and the cycloid (18.02)
  7. Velocity, acceleration and Kepler's second law (18.02)
  8. Functions of two variables and partial derivatives (18.02)
  9. Tangent planes, critical points and least squares (18.02)
  10. The second derivative test (18.02)
  11. Differentials and the chain rule (18.02)
  12. The gradient and directional derivatives (18.02)
On this page · 7 sections
  1. An example: closest to the origin
  2. The Lagrange equations
  3. Solving the equations
  4. Why the method works
  5. Minimum or maximum?
  6. An advanced example: the cheapest pyramid
  7. Summary

So far the variables of a min/max problem were independent. Often they are not: they are tied by a relation g(x,y,z)=cg(x, y, z) = c, the constraint, and ff is to be minimised or maximised only among the points that satisfy it (transcript, p. 1; notes, p. 2). If the constraint is simple, solve it for one variable and substitute, and the problem is an ordinary one; when it is too complicated to solve, a new method is needed: Lagrange multipliers (p. 1). (Physics example: pressure, volume and temperature of a gas are tied by PV=NRTPV = NRT, and it can be handy to keep all three as constrained variables, p. 1.) The critical points of ff itself are no help, since they usually do not satisfy the constraint (p. 2).

An example: closest to the origin#

Find the point of the hyperbola xy=3xy = 3 closest to the origin (transcript, p. 2; notes, p. 2). Minimising the distance x2+y2\sqrt{x^2 + y^2} is the same as minimising its square, so (p. 2):

The problem
minimise f(x,y)=x2+y2subject tog(x,y)=xy=3\text{minimise } f(x, y) = x^2 + y^2 \quad\text{subject to}\quad g(x, y) = xy = 3
In words

minimise f(x, y) equals x squared plus y squared subject to g(x, y) equals x y equals 3

On the contour plot of ff (circles) with the hyperbola on top: a large circle meets the hyperbola in four points; shrinking it, there is a smallest circle that still meets it, and that is the minimum. There the circle is tangent to the hyperbola (pp. 2–3; notes, p. 2). So at the minimum the level curve of ff is tangent to the level curve g=3g = 3: they share a tangent line, so their normal vectors, the gradients, are parallel (p. 3; notes, p. 2).

The Lagrange equations#

Parallel vectors are proportional: there is a number λ\lambda, the multiplier, with (transcript, p. 4; notes, p. 2):

Lagrange condition
∇f=λ ∇g\nabla f = \lambda\,\nabla g
In words

del f equals lambda del g

Source: 18.02 lecture summaries, Week 5 (Prof. Auroux), Lecture 13, pp. 2–3, Lecture 13, p. 2

(λ\lambda may be positive or negative, depending on whether the gradients point the same way, p. 5. It is called a multiplier because it is what ∇g\nabla g is multiplied by to give ∇f\nabla f, p. 9.) This replaces a min/max problem in two constrained variables by a system in three unknowns, xx, yy, λ\lambda. Two equations come from the components of the gradients, and the constraint is the third (p. 4; notes, p. 2):

The system
fx=λgx,fy=λgy,g(x,y)=cf_x = \lambda g_x, \qquad f_y = \lambda g_y, \qquad g(x, y) = c
In words

f sub x equals lambda g sub x, f sub y equals lambda g sub y, g(x, y) equals c

With a third variable, add fz=λgzf_z = \lambda g_z (p. 4). For the hyperbola: 2x=λy2x = \lambda y, 2y=λx2y = \lambda x, xy=3xy = 3 (p. 5; notes, p. 2).

Solving the equations#

There is no general method: sometimes it is easy, sometimes it needs a computer (transcript, p. 7; notes, p. 3). Here the first two equations form a linear system (p. 7; notes, p. 3):

A linear system for x and y
[2−λλ−2][xy]=[00]\begin{bmatrix} 2 & -\lambda \\ \lambda & -2 \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}
In words

2 minus lambda; lambda minus 2 x; y equals 0; 0

The obvious solution x=y=0x = y = 0 fails xy=3xy = 3, so we need another solution, which exists only when the determinant is zero: −4+λ2=0-4 + \lambda^2 = 0, so λ=±2\lambda = \pm 2 (p. 7). For λ=2\lambda = 2: x=yx = y and x2=3x^2 = 3, giving (3,3)(\sqrt3, \sqrt3) and (−3,−3)(-\sqrt3, -\sqrt3). For λ=−2\lambda = -2: x=−yx = -y and −x2=3-x^2 = 3, no solution (p. 8; notes, p. 3). At both points f=6f = 6, and on the picture ∇f\nabla f is indeed twice ∇g\nabla g (pp. 6, 8).

Why the method works#

At a constrained minimum or maximum, moving along the level set g=cg = c changes ff only in one way (only up, or only down), so to first order it does not change. The derivatives are zero, but only in the allowed directions, those tangent to g=cg = c (transcript, p. 9; notes, p. 3). For every unit vector u^\hat u tangent to the level set (pp. 9–10; notes, p. 3):

No change along the constraint
(dfds)u^=∇f⋅u^=0\left(\frac{df}{ds}\right)_{\hat u} = \nabla f \cdot \hat u = 0
In words

( d f over d s ) sub u hat equals del f times u hat equals 0

Source: 18.02 Lecture 13 transcript, pp. 9–10

So ∇f\nabla f is perpendicular to every vector tangent to the level set: it is normal to the level set of gg. So is ∇g\nabla g. Hence the two are parallel, which is the same as the level sets of ff and gg being tangent (p. 10; notes, p. 3).

Minimum or maximum?#

Warning: the method does not say whether a solution is a minimum or a maximum, or (in three variables) even a saddle (transcript, pp. 6, 11; notes, p. 3). The second derivative test does not apply, because only the directions along the constraint count (p. 11). What is left is to compare the values of ff at all solutions, or to argue geometrically (p. 11; notes, p. 3). On the hyperbola the two solutions tie for the minimum, and there is no maximum, since points of the hyperbola go arbitrarily far from the origin (p. 11). (Here one could also substitute y=3/xy = 3/x and minimise x2+9/x2x^2 + 9/x^2 directly, but that is not always possible, p. 6.)

An advanced example: the cheapest pyramid#

Build a pyramid on a given triangular base with a given volume, using as little surface area as possible (Auroux's story: a gold-covered building on a triangular plot) (transcript, pp. 11–12; notes, p. 3). Since the volume is V=13Abase hV = \frac13 A_{\text{base}}\,h, the height hh is fixed: only the position of the top vertex is free (p. 12; notes, p. 3). In x,yx, y coordinates the face areas are lengths of cross products, and minimising them that way is hopelessly messy (p. 13; notes, p. 3).

Better variables, adapted to the geometry. Let a1,a2,a3a_1, a_2, a_3 be the side lengths of the base and u1,u2,u3u_1, u_2, u_3 the distances from the point below the top vertex to the three sides. Each side face is a triangle with base aia_i and, by Pythagoras, height ui2+h2\sqrt{u_i^2 + h^2} (pp. 13–14; notes, p. 3). Cutting the base into three triangles with heights uiu_i gives the constraint (p. 14; notes, p. 3):

The pyramid problem
f=12a1u12+h2+12a2u22+h2+12a3u32+h2,g=12a1u1+12a2u2+12a3u3=Abasef = \tfrac12 a_1\sqrt{u_1^2 + h^2} + \tfrac12 a_2\sqrt{u_2^2 + h^2} + \tfrac12 a_3\sqrt{u_3^2 + h^2}, \qquad g = \tfrac12 a_1u_1 + \tfrac12 a_2u_2 + \tfrac12 a_3u_3 = A_{\text{base}}
In words

f equals one half a one the square root of u one squared plus h squared, end of root, plus one half a two the square root of u two squared plus h squared, end of root, plus one half a three the square root of u three squared plus h squared, end of root, g equals one half a one u one plus one half a two u two plus one half a three u three equals capital A base

The Lagrange equations ∂f/∂ui=λ ∂g/∂ui\partial f/\partial u_i = \lambda\,\partial g/\partial u_i simplify, the factors 12ai\frac12 a_i cancelling, to (pp. 14–15; notes, p. 3):

The solution
u1u12+h2=u2u22+h2=u3u32+h2=λ⟹u1=u2=u3\frac{u_1}{\sqrt{u_1^2 + h^2}} = \frac{u_2}{\sqrt{u_2^2 + h^2}} = \frac{u_3}{\sqrt{u_3^2 + h^2}} = \lambda \quad\Longrightarrow\quad u_1 = u_2 = u_3
In words

u one over the square root of u one squared plus h squared, end of root, equals u two over the square root of u two squared plus h squared, end of root, equals u three over the square root of u three squared plus h squared, end of root, equals lambda which gives u one equals u two equals u three

The point below the top is equally far from all three sides: the top goes above the incenter of the base triangle (p. 15; notes, p. 3).

Worked example

Closest point on a plane, and a maximum on a circle

(a) Find the point of the plane x+2y+2z=9x + 2y + 2z = 9 closest to the origin. (b) Find the largest and smallest values of f=xyf = xy on the circle x2+y2=8x^2 + y^2 = 8.

(a) Three variables

Minimise x2+y2+z2x^2 + y^2 + z^2 with g=x+2y+2z=9g = x + 2y + 2z = 9: ⟨2x,2y,2z⟩=λ⟨1,2,2⟩\langle 2x, 2y, 2z\rangle = \lambda\langle 1, 2, 2\rangle gives x=λ/2x = \lambda/2, y=λy = \lambda, z=λz = \lambda. The constraint gives λ/2+2λ+2λ=9\lambda/2 + 2\lambda + 2\lambda = 9, so λ=2\lambda = 2 and the point is (1,2,2)(1, 2, 2), at distance 1+4+4=3\sqrt{1 + 4 + 4} = 3. (It lies along the normal vector ⟨1,2,2⟩\langle 1, 2, 2\rangle, as it should.)

(b) Two solutions, two values

⟨y,x⟩=λ⟨2x,2y⟩\langle y, x\rangle = \lambda\langle 2x, 2y\rangle gives y=2λxy = 2\lambda x and x=2λyx = 2\lambda y, so x=4λ2xx = 4\lambda^2 x; x=0x = 0 would force y=0y = 0, off the circle, so λ=±12\lambda = \pm\frac12. With λ=12\lambda = \frac12: y=xy = x, 2x2=82x^2 = 8, points (2,2)(2, 2) and (−2,−2)(-2, -2) with f=4f = 4. With λ=−12\lambda = -\frac12: y=−xy = -x, points (2,−2)(2, -2) and (−2,2)(-2, 2) with f=−4f = -4.

(b) Compare values

The method alone does not say which is which; comparing values, the maximum of xyxy on the circle is 4 and the minimum is −4-4.

Summary#

  • To minimise or maximise ff subject to g=cg = c: solve ∇f=λ∇g\nabla f = \lambda\nabla g together with g=cg = c (three equations in xx, yy, λ\lambda for two variables).
  • At a constrained extremum the level sets of ff and gg are tangent, because ∇f⋅u^=0\nabla f \cdot \hat u = 0 for every direction u^\hat u along g=cg = c.
  • Example: on xy=3xy = 3, the points closest to the origin are (±3,±3)(\pm\sqrt3, \pm\sqrt3) (same signs), with λ=2\lambda = 2 and f=6f = 6.
  • The method does not tell minimum from maximum, and the second derivative test does not apply: compare values or argue geometrically.
  • The least-area pyramid on a given base with given volume has its top above the incenter.

Symbols on this page

Show the 40 symbols used here
λ\lambda lambda.
The Lagrange multiplier: the number with ∇f = λ∇g. Say it: “lambda”.
⇒\Rightarrow implies.
Implies: what follows is a consequence of what came before. Say it: “which gives”.
±\pm plus or minus.
Plus or minus: both signs, or an uncertainty (67.3 ± 1.2). Say it: “plus or minus”.
⋅\cdot dot.
Times (multiplication). Between two vectors: the dot product. Say it: “times”.
⟨\langle angle brackets.
The average (mean value) of what is inside, ⟨…⟩. Say it: “the average of”.
∂\partial partial.
Partial derivative: the rate of change with one variable, holding the others fixed. Say it: “partial”.
∇\nabla nabla (del).
Del: ∇f is the gradient, ∇·v the divergence, ∇×v the curl, ∇² the Laplacian. Say it: “del”.
ı^\hat\imath hat.
A unit vector: a vector of length 1 that only gives a direction (î, r̂). Say it: “hat”.
zz z.
The third variable. Say it: “z”.
cc c.
The constant in the constraint g = c. Say it: “c”.
kk k.
In the cosmology note, Boltzmann's constant. Unit: J/K. Say it: “k”.
TT T.
Temperature: of a gas in PV = NRT, and in the cosmology note. Unit: K. Say it: “capital T”.
∥\parallel parallel.
Is parallel to. Say it: “parallel”.
xx x.
The first variable. Say it: “x”.
yy y.
The second variable. Say it: “y”.
dd d.
The d of a derivative, df/ds. Say it: “d”.
ff f.
The function to be minimised or maximised. Say it: “f”.
gg g.
The function in the constraint g = c. Say it: “g”.
PP P.
Pressure of a gas, in PV = NRT. Unit: Pa. Say it: “P”.
ss s.
Distance travelled along a direction tangent to the constraint. Say it: “s”.
hh h.
The height of the pyramid, fixed by its volume. Unit: m. Say it: “h”.
NN N.
Amount of gas, in PV = NRT. Unit: mol. Say it: “N”.
RR R.
The gas constant, in PV = NRT. Unit: J/(mol K). Say it: “capital R”.
a1a_{1} a one.
The length of the first side of the pyramid's base triangle. Say it: “a one”.
a2a_{2} a two.
The length of the second side of the base triangle. Say it: “a two”.
uu u.
With a hat, û: a unit vector tangent to the level set g = c. Say it: “u”.
aia_{i} initial scale factor.
The length of side i of the base triangle. Say it: “a sub i”.
VV V.
Volume: of a gas in PV = NRT, and of the pyramid. Unit: m³. Say it: “V”.
a3a_{3} a 3.
The length of the third side of the base triangle. Say it: “a three”.
u1u_{1} u one.
The distance from the point below the top vertex to the first side of the base. Say it: “u one”.
u2u_{2} u two.
The distance from that point to the second side. Say it: “u two”.
u3u_{3} u 3.
The distance from that point to the third side. Say it: “u three”.
fxf_{x} f sub x.
The partial derivative ∂f/∂x. Say it: “f sub x”.
fyf_{y} f sub y.
The partial derivative ∂f/∂y. Say it: “f sub y”.
fzf_{z} f sub z.
The partial derivative ∂f/∂z. Say it: “f sub z”.
gxg_{x} g sub x.
The partial derivative ∂g/∂x. Say it: “g sub x”.
gyg_{y} g sub y.
The partial derivative ∂g/∂y. Say it: “g sub y”.
gzg_{z} g sub z.
The partial derivative ∂g/∂z. Say it: “g sub z”.
uiu_{i} u sub i.
The distance from the point below the top vertex to side i of the base. Say it: “u sub i”.
AbaseA_{\text{base}} A base.
The area of the pyramid's base triangle. Say it: “capital A base”.

Tap or click a symbol in a formula to see the same explanation. All symbols: symbols and notation.

Words on this page

Show the 36 words used here

New here

incentre.
The point inside a triangle that is the same distance from all three sides: the centre of the largest circle that fits inside.

Also used

constraint.
A condition that limits what is allowed, such as a rope of fixed length that links the motions of the bodies it joins. Explained in Tension in ropes and the spring force.
p..
Page, in a reference to a source; pp. means pages, as in pp. 3–5.
Lagrange multipliers.
A method for finding the largest or smallest value of a function when its variables must satisfy a constraint. Explained in A ring on a string, and Newton's method.
pressure.
The force pushing on a surface divided by the area of the surface, so the push on each square metre. Explained in Density and pressure.
critical point.
A point where a function's derivative is zero, so its graph is level there; maxima and minima are found among such points. Explained in Curve sketching with the first and second derivative.
hyperbola.
An open curve with two separate branches: the set of points whose distances from two fixed points differ by the same amount. Explained in Quadratics and power laws.
contour map.
A flat map of a function of two variables, drawing the curves along which it keeps one value, like height lines on a hiking map. Explained in Fields: scalar, vector, gravitational and electric.
tangent.
A straight line that touches a curve at a point and runs in the same direction as the curve there. Explained in Angles, radians and trigonometry.
level curve.
A curve along which a function of two variables keeps the same value, like a line of equal height on a map. Explained in Functions of two variables and partial derivatives.
normal vector.
A vector at right angles to a plane or surface; it fixes which way the plane faces. Explained in Planes through three points, and matrices.
gradient.
The vector of a function's partial derivatives; it points the way the function increases fastest, and its length is that fastest rate. Explained in Graphs, straight lines and slope.
vector.
A quantity with both a size and a direction, such as a velocity or a force, drawn as an arrow. Explained in Vectors.
proportional.
Of two quantities: always in the same ratio, so that doubling one doubles the other. Explained in Graphs, straight lines and slope.
linear.
Of a relation or equation: using only first powers of the unknowns, so doubling the cause doubles the effect and effects simply add. Explained in Solving and rearranging formulas.
determinant.
A single number worked out from a square array of numbers (a matrix), which measures how the matrix stretches areas or volumes. Explained in Determinants and the cross product.
derivative.
The rate at which a function changes as its input changes: the slope of its graph at a point. Explained in Position and velocity in one dimension.
unit vector.
A vector of length one, used only to point in a direction. Explained in Newton's law of gravitation.
perpendicular.
At right angles to a line, a surface or another direction. Explained in Inclined planes.
saddle point.
A point where a surface rises in some directions and falls in others, like the middle of a horse's saddle or a mountain pass. Explained in Functions of two variables and partial derivatives.
second derivative test.
A rule that uses second derivatives at a critical point to tell whether it is a minimum, a maximum or a saddle. Explained in The second derivative test.
cross product.
A way of multiplying two vectors that gives a third vector, at right angles to both, as long as the area of their parallelogram. Explained in Torque and the cross product.
statistical mechanics.
The branch of physics that explains the large-scale behaviour of matter, such as temperature and pressure, from the laws governing its atoms, using probability. Explained in Thermodynamic variables, temperature and work.
equilibrium.
A state that does not change by itself, because the influences acting on it balance. Explained in Newton's first law: inertia.
energy.
A quantity, measured in joules, that a body or field has because of its motion, position or state; a closed system keeps its total. Explained in Conservation of energy.
entropy.
A measure of how many microscopic arrangements of a system match its large-scale state; it never decreases in an isolated system. Explained in Entropy and the second law.
black-body radiation.
The radiation given off by a body in thermal equilibrium, whose spread over wavelengths depends only on its temperature. Explained in Black-body radiation in statistical physics.
spectrum.
The spread of light or other radiation over its wavelengths, or the full set of values a quantity such as energy can take. Explained in Light and the electromagnetic spectrum.
cosmic microwave background.
The faint glow of microwaves filling the universe, left over from when it was hot and dense, now at 2.7 kelvin. Explained in Towards the universe: light-travel time and looking back in time.

Academic

satisfy.
To make an equation or condition true.
transcript.
A written record of exactly what was said in a recorded lecture, word for word.
to first order.
Keeping terms only up to a stated power of a small quantity: to first order keeps the first power and drops squares and higher powers.
hence.
For this reason; as a result of what was just said.
argument.
A chain of reasoning that leads to a conclusion; in maths also the input of a function, such as x in sin x.
arbitrary.
Free to be chosen as one likes; any choice gives a correct result.
messy.
In calculations, long and complicated, with many terms, though not hard in principle.

Tap or click a word, here or in the text, for its meaning in this lesson. All words: the glossary. How many words are marked in the text: Reading options (the “Aa” button).

Where this leads

In cosmology

34 more cosmology pages that build on this

Pages that build on this

Practise

Check your understanding

  1. At a constrained minimum of ff on g=cg = c…
  2. For f(x,y)f(x, y) with one constraint g(x,y)=cg(x, y) = c, the Lagrange equations have how many unknowns?
  3. How do you tell whether a solution of the Lagrange equations is a minimum or a maximum?
0 of 3 answered

Flashcards

1 / 3