Survey of Mathematics

5.8 Constrained extrema and Lagrange multipliers

To extremise a field f on the set where g = c, look for points where the gradient of f is a multiple of the gradient of g, because there the level curve of f touches the constraint without crossing it. The multiplier is a number you solve for, and it equals the rate at which the best value changes when the constraint moves. The proof reduces to an ordinary extremum by solving the constraint with the implicit function theorem, and a bordered Hessian decides between maximum and minimum.

Taught in 375/376Apostol, not taughtBeyond the courseMATH 376, Worksheets 1 and 3 and Homework 1 (the Lagrange warm-up)MATH 375, Lecture 24 (extrema on a region, check the boundary)Apostol Vol. 2, 9.14 and 9.15Lagrange, Mécanique analytique (1788)Rudin, Principles of Mathematical Analysis, Thm 9.28 (the implicit function step)Markowitz, Portfolio Selection, Journal of Finance (1952)

You have a field ff and you may not look at the whole plane or space: only at points that satisfy an equation, such as a circle, a plane, or a budget. Where is ff largest on that set, and where is it smallest? The rule from 5.2 (∇f=O\nabla f = O at an interior extremum) cannot be the answer, because the constraint set has no interior points: stepping off it breaks the constraint. In JEE you solved such problems by substituting one equation into the other to leave one variable. That works when the constraint can be solved for a variable, and the implicit function theorem of 5.7 says it can be, locally, at a regular point, even when you cannot write the formula. Lagrange’s idea is to do the substitution without doing it: the condition for an extremum can be written in a form where the symmetry between the variables is kept, and where the extra unknown λ\lambda that appears turns out to be a quantity with a meaning.

Before you start

5.6: critical points, the second-derivative test, and why an absolute extremum on a compact set exists. 5.7: regular points, and level sets as graphs. 5.3: the gradient is perpendicular to level sets.

Quick checkThe minimum of f(x,y)=x2+y2f(x, y) = x^2 + y^2 on the line x+y=2x + y = 2 is at (1,1)(1, 1). Is ∇f(1,1)=O\nabla f(1, 1) = O?
Quick checkAt a point of the circle x2+y2=1x^2 + y^2 = 1, which vector is perpendicular to the circle?
Quick checkFor g(x,y,z)=x2+y2+z2g(x, y, z) = x^2 + y^2 + z^2, which points of the level set g=0g = 0 are regular points?

The picture: when two curves touch

Slide the dot along the blue constraint. The orange curves are level curves of ff. As the dot slides, it crosses some level curves and so ff changes: the plot on the right goes up or down. At a few special positions the plot is flat, and on the left the two arrows point the same way (or exactly opposite ways). There the level curve of ff through the dot is tangent to the constraint: it touches it and turns back, and the constraint stays on one side of it. That is the maximum or minimum. Choose the second and third pictures to see a minimum and the eigenvalue structure; choose the last one to see where the method breaks.

The idea, in words

Apostol’s picture (9.14) of the nearest point to the origin: inflate a ball (a level set of f(x)=∥x∥f(x) = \lVert x \rVert) from radius 00 until it first touches the constraint surface. At the first contact the ball and the surface are tangent. Two tangent surfaces have the same tangent plane, hence the same normal line, hence parallel gradients. The first contact is the minimum of ff on the surface, since any smaller ball has not reached it.

Why· The same fact without pictures

Take any curve r(t)r(t) lying in the constraint set, through the candidate point aa at t=0t = 0. The function t↦f(r(t))t \mapsto f(r(t)) has an extremum at t=0t = 0, so its derivative is 00 there, and by the path theorem of 5.3 that derivative is ∇f(a)⋅r′(0)\nabla f(a)\cdot r'(0). So ∇f(a)\nabla f(a) is perpendicular to every tangent vector r′(0)r'(0) of the constraint. But ∇g(a)\nabla g(a) is also perpendicular to all of them. In the plane or in space with one constraint, the vectors perpendicular to the tangent vectors form a single line, so ∇f(a)\nabla f(a) and ∇g(a)\nabla g(a) lie on one line: ∇f(a)=λ∇g(a)\nabla f(a) = \lambda\nabla g(a).

Where this came from· Lagrange and the statics of constrained bodies

Joseph-Louis Lagrange wanted one method for the statics and dynamics of bodies whose parts are tied together by constraints (a bead on a wire, a rigid rod, the links of a chain). In his Mécanique analytique (1788) he combined the principle of virtual velocities, due to Johann Bernoulli, with the multipliers that now carry his name; the rule had appeared in his earlier work on the calculus of variations, and the 1788 treatise is where he stated it in its modern form. The mechanical meaning survives: in mechanics the multipliers are the forces by which the constraints push on the system, and the theorem later in this chapter shows that in optimisation the multiplier is the derivative of the best value with respect to the constraint, the price of the constraint.

Definitions and the theorem

Definition T

Constrained extremum

Let f:U→Rf: U \to \mathbb R and g=(g1,…,gm):U→Rmg = (g_1, \dots, g_m): U \to \mathbb R^m be fields on an open set U⊆RnU \subseteq \mathbb R^n with m<nm \lt n, and let S={x∈U:g(x)=c}S = \{x \in U : g(x) = c\} (the constraint set, the common level set of the gig_i). A point a∈Sa \in S is a local constrained maximum of ff if there is a ball B(a,r)B(a, r) with f(x)≤f(a)f(x) \le f(a) for every x∈S∩B(a,r)x \in S \cap B(a, r); a local constrained minimum with ≥\ge. Together: constrained extrema. As in 5.6, absolute ones compare with all of SS. This is the 376 definition: ‘a local extremum at PP on g=kg = k’.

In one lineA point aa with g(a)=cg(a) = c such that f(x)≤f(a)f(x) \le f(a) (a maximum) or f(x)≥f(a)f(x) \ge f(a) (a minimum) for all nearby xx that also satisfy g(x)=cg(x) = c.

Why it existsIt is the precise form of 'largest or smallest value of ff on the constraint', and it only compares f(a)f(a) with values on the constraint set, never with values off it.

Definition T

Lagrange multiplier

When ∇f(a)=λ1∇g1(a)+⋯+λm∇gm(a)\nabla f(a) = \lambda_1\nabla g_1(a) + \dots + \lambda_m\nabla g_m(a), the numbers λ1,…,λm\lambda_1, \dots, \lambda_m are the Lagrange multipliers of ff with respect to the constraints at aa. The sign convention varies (f−λgf - \lambda g here, f+λgf + \lambda g in some books); the points found are the same and only the sign of λ\lambda changes.

In one lineA number λi\lambda_i in the equation ∇f(a)=∑iλi∇gi(a)\nabla f(a) = \sum_i\lambda_i\nabla g_i(a); there is one multiplier for each constraint.

Why it existsIt is the coefficient that expresses the gradient of ff in terms of the constraint gradients; it turns a search over a curved set into algebraic equations and, by the theorem below, measures how much the best value would change if the constraint were loosened.

Definition T

Lagrangian

The Lagrangian is L(x,λ)=f(x)−∑i=1mλi(gi(x)−ci)L(x, \lambda) = f(x) - \sum_{i=1}^m\lambda_i\big(g_i(x) - c_i\big). Its partial derivatives are ∂L∂xk=∂f∂xk−∑iλi∂gi∂xk\dfrac{\partial L}{\partial x_k} = \dfrac{\partial f}{\partial x_k} - \sum_i\lambda_i\dfrac{\partial g_i}{\partial x_k} (the kk-th component of ∇f−∑λi∇gi\nabla f - \sum\lambda_i\nabla g_i) and ∂L∂λi=−(gi−ci)\dfrac{\partial L}{\partial\lambda_i} = -(g_i - c_i) (the ii-th constraint). Setting all n+mn + m of them to 00 is the system the method solves.

In one lineThe field L(x,λ)=f(x)−∑iλi(gi(x)−ci)L(x, \lambda) = f(x) - \sum_i\lambda_i\big(g_i(x) - c_i\big) of n+mn + m variables, whose critical points are exactly the solutions of ∇f=∑λi∇gi\nabla f = \sum\lambda_i\nabla g_i together with the constraints.

Why it existsIt packages the n+mn + m equations of the method into one 'find the critical points' problem, so that the machinery of 5.6 can be reused.

Theorem T MATH 376 Worksheet 3 #5 (m = 1, n = 3) and Warm-up; Apostol 9.14; Rudin Thm 9.28

Lagrange multiplier theorem

Let f,g1,…,gmf, g_1, \dots, g_m be continuously differentiable on an open set U⊆RnU \subseteq \mathbb R^n, m<nm \lt n, and S={g=c}S = \{g = c\}. Suppose f∣Sf|_S has a local extremum at a∈Sa \in S and aa is a regular point of gg. Then there are unique λ1,…,λm∈R\lambda_1, \dots, \lambda_m \in \mathbb R with

∇f(a)=λ1∇g1(a)+⋯+λm∇gm(a).\nabla f(a) = \lambda_1\nabla g_1(a) + \dots + \lambda_m\nabla g_m(a).

In one lineIf f,g1,…,gmf, g_1, \dots, g_m are C1C^1, ff has a local constrained extremum at aa, and aa is a regular point of gg (the gradients ∇gi(a)\nabla g_i(a) are linearly independent), then ∇f(a)=∑λi∇gi(a)\nabla f(a) = \sum\lambda_i\nabla g_i(a) for unique numbers λi\lambda_i.

Why it is trueIt reduces a problem on a curved set to n+mn + m equations in n+mn + m unknowns, and it names the one hypothesis that cannot be skipped: the constraint gradients must be independent.

ProofWorksheet 3 #5 (in space), Rudin Thm 9.28 (general)
The idea: At a regular point the implicit function theorem lets us solve the constraint for m of the variables as functions of the other n minus m, so the constraint set is a graph and f restricted to it is an ordinary function of n minus m free variables with an interior extremum. Its gradient is zero. Writing that gradient with the chain rule, and defining lambda to match the m solved coordinates, gives the equation in the other coordinates automatically.
Write x=(u,w)x = (u, w) with u∈Rn−mu \in \mathbb R^{n-m}, w∈Rmw \in \mathbb R^m, and a=(au,aw)a = (a_u, a_w), such that the m×mm \times m matrix Dwg(a)D_wg(a) is invertible.
The m×nm \times n Jacobian Dg(a)Dg(a) has rank mm (regular point), so some mm of its columns are independent (2.6). Renumber the variables so that these are the last mm columns. Then Dwg(a)D_wg(a) is invertible.
There is a C1C^1 function hh near aua_u with h(au)=awh(a_u) = a_w and g(u,h(u))=cg(u, h(u)) = c, and near aa the constraint set is the graph {(u,h(u))}\{(u, h(u))\}.
Implicit function theorem (5.7) for g(u,w)−c=Og(u, w) - c = O.
Define φ(u)=f(u,h(u))\varphi(u) = f\big(u, h(u)\big). It has an ordinary local extremum at aua_u, an interior point of an open set of Rn−m\mathbb R^{n-m}.
Every uu near aua_u gives the point (u,h(u))(u, h(u)) of SS near aa, and every point of SS near aa is of this form. So φ\varphi inherits the extremum of f∣Sf|_S at the point aua_u.
So ∇φ(au)=O\nabla\varphi(a_u) = O.
Partial derivatives vanish at an interior extremum (5.2).
∇uf(a)+Dh(au)T ∇wf(a)=O\nabla_uf(a) + Dh(a_u)^{\mathsf T}\,\nabla_wf(a) = O.
Chain rule (5.4): u↦(u,h(u))u \mapsto (u, h(u)) has Jacobian [IDh]\begin{bmatrix}I\\ Dh\end{bmatrix}, so the gradient of the composite is ∇uf+DhT∇wf\nabla_uf + Dh^{\mathsf T}\nabla_wf, with everything evaluated at aa.
Dh(au)=−Dwg(a)−1Dug(a)Dh(a_u) = -D_wg(a)^{-1}D_ug(a).
Differentiate the identity g(u,h(u))=cg(u, h(u)) = c (chain rule): Dug+Dwg Dh=0D_ug + D_wg\,Dh = 0, and solve with the invertible DwgD_wg.
Put λ=(Dwg(a)T)−1∇wf(a)∈Rm\lambda = \big(D_wg(a)^{\mathsf T}\big)^{-1}\nabla_wf(a) \in \mathbb R^m.
Define λ\lambda so that the last mm components of the claimed equation hold: ∇wf=(Dwg)Tλ=∑iλi∇wgi\nabla_wf = (D_wg)^{\mathsf T}\lambda = \sum_i\lambda_i\nabla_wg_i. This is possible because (Dwg)T(D_wg)^{\mathsf T} is invertible.This is the 'where does the idea come from' step. We have mm numbers to choose and mm equations to satisfy, and the matrix is invertible exactly because the point is regular.
∇uf(a)=Dug(a)Tλ=∑iλi∇ugi(a)\nabla_uf(a) = D_ug(a)^{\mathsf T}\lambda = \sum_i\lambda_i\nabla_ug_i(a).
Substitute Dh=−Dwg−1DugDh = -D_wg^{-1}D_ug into the equation of the fifth step; transposing gives DhT=−DugT(DwgT)−1Dh^{\mathsf T} = -D_ug^{\mathsf T}\big(D_wg^{\mathsf T}\big)^{-1}. Then ∇uf=−DhT∇wf=DugT(DwgT)−1∇wf=DugTλ\nabla_uf = -Dh^{\mathsf T}\nabla_wf = D_ug^{\mathsf T}\big(D_wg^{\mathsf T}\big)^{-1}\nabla_wf = D_ug^{\mathsf T}\lambda.
So ∇f(a)=∑iλi∇gi(a)\nabla f(a) = \sum_i\lambda_i\nabla g_i(a), with unique λi\lambda_i. ■\blacksquare
The uu-components and the ww-components together make the whole vector. Uniqueness: if two lists of multipliers worked, their difference would be a linear relation among the independent gradients ∇gi(a)\nabla g_i(a), so it is zero.
Proof workshopRebuild the proof of the Lagrange multiplier theoremRudin Thm 9.28; MATH 376 Worksheet 3 #5

Tap the lines in the order a proof would write them. Each line can only use what is already above it.

    Quick checkIn the proof, why does the extremum of f∣Sf|_S at aa become an ordinary extremum of φ\varphi with ∇φ=O\nabla\varphi = O?
    Why· The picture behind the proof, in space (the version from Worksheet 3 #5)

    In R3\mathbb R^3 with one constraint g=cg = c and ∇g(P)≠O\nabla g(P) \ne O, say gz(P)≠0g_z(P) \ne 0. Near PP the level set is a graph z=h(x,y)z = h(x, y), parametrised by r(u,v)=(u,v,h(u,v))r(u, v) = (u, v, h(u, v)), and the two tangent vectors rur_u, rvr_v span the tangent plane (5.7). Differentiating g(r)=cg(r) = c shows ∇g⋅ru=∇g⋅rv=0\nabla g\cdot r_u = \nabla g\cdot r_v = 0; differentiating f(r)f(r), which has a critical point, shows ∇f⋅ru=∇f⋅rv=0\nabla f\cdot r_u = \nabla f\cdot r_v = 0. The vectors perpendicular to a plane in space form one line, so ∇f\nabla f is a multiple of ∇g\nabla g (here ∇g≠O\nabla g \ne O). In the visualiser above, this is the red arrow lining up with the purple one.

    Watch out· Two hypotheses the theorem needs, and one thing it does not say

    (1) The point must be regular: ∇g(a)≠O\nabla g(a) \ne O for one constraint, independent gradients for several. If it is not, the theorem says nothing, and the point must be examined separately (the cusp y2=x3y^2 = x^3 in the examples). (2) f,gf, g must be C1C^1. (3) The theorem is a necessary condition: it produces candidates. It does not say that an extremum exists, nor which candidate is the maximum. You need an existence argument (a continuous function on a compact set has a largest and a smallest value, 4.3 and 5.6) or a growth argument.

    The recipe

    A preview· The method, as used in MATH 376 (WS3 solution key)
    1. Write the constraint as g=cg = c. List the points of the constraint where ∇g=O\nabla g = O (or where the gradients of several constraints are dependent). They are candidates of their own.
    2. Solve ∇f=∑λi∇gi\nabla f = \sum\lambda_i\nabla g_i together with g=cg = c: n+mn + m equations for nn coordinates and mm multipliers. The usual trick is to solve each coordinate in terms of λ\lambda, substitute in the constraint, and find λ\lambda; or to divide one component equation by another (after checking the divisor is not 00).
    3. List all candidate points.
    4. Evaluate ff at each candidate. Decide the maximum and the minimum by an existence argument (compact set, or f→∞f \to \infty along every unbounded direction) or by geometry. If asked for a distance, use the squared distance (same minimiser, no square root).

    Examples from the course

    Worked example MATH 376 Worksheet 1 #5
    Find the largest and smallest values of f(x,y)=xyf(x, y) = xy on the circle x2+y2=1x^2 + y^2 = 1.

    Solution.

    1. Set up. g=x2+y2g = x^2 + y^2, constraint g=1g = 1. ∇g=(2x,2y)\nabla g = (2x, 2y) is zero only at the origin, which is not on the circle. Step 1 of the recipe: there are no singular candidates.
    2. Write the equations. ∇f=(y,x)=λ(2x,2y)\nabla f = (y, x) = \lambda(2x, 2y), so y=2λxy = 2\lambda x and x=2λyx = 2\lambda y. Components of ∇f=λ∇g\nabla f = \lambda\nabla g.
    3. Eliminate λ\lambda. Substitute x=2λyx = 2\lambda y into y=2λxy = 2\lambda x: y=4λ2yy = 4\lambda^2y. If y=0y = 0 then x=0x = 0, not on the circle. So y≠0y \ne 0 and 4λ2=14\lambda^2 = 1, λ=±12\lambda = \pm\frac12. Dividing by yy is allowed once we have checked y=0y = 0 separately; this is the step where solutions are lost if you divide too early.
    4. Find the points. λ=12\lambda = \frac12 gives y=xy = x and 2x2=12x^2 = 1: ±(22,22)\pm\big(\frac{\sqrt2}2, \frac{\sqrt2}2\big), f=12f = \frac12. λ=−12\lambda = -\frac12 gives y=−xy = -x: ±(22,−22)\pm\big(\frac{\sqrt2}2, -\frac{\sqrt2}2\big), f=−12f = -\frac12. Put each λ\lambda in y=2λxy = 2\lambda x and then in the circle.
    5. Decide. The circle is closed and bounded and xyxy is continuous, so a largest and a smallest value exist (5.6, 4.3), and they are among the four candidates. Existence from compactness; the theorem only gives candidates.

    Answer. Maximum 12\frac12 at the two points where x,yx, y have the same sign; minimum −12-\frac12 where they have opposite signs. (Check by substitution: x=cos⁡tx = \cos t, y=sin⁡ty = \sin t gives xy=12sin⁡2txy = \frac12\sin2t.)

    Your answerWhat is the largest value of xyxy on the circle x2+y2=1x^2 + y^2 = 1?
    Worked example MATH 376 Worksheet 3 #4
    Find the point of the plane x+2y+z=10x + 2y + z = 10 closest to (1,2,0)(1, 2, 0) and the distance.

    Solution.

    1. Squared distance. Minimise f=(x−1)2+(y−2)2+z2f = (x - 1)^2 + (y - 2)^2 + z^2 subject to g=x+2y+z=10g = x + 2y + z = 10. The squared distance has the same minimiser and no square root.
    2. Singular points. ∇g=(1,2,1)≠O\nabla g = (1, 2, 1) \ne O everywhere. The theorem applies at every point.
    3. Equations. 2(x−1)=λ2(x - 1) = \lambda, 2(y−2)=2λ2(y - 2) = 2\lambda, 2z=λ2z = \lambda, so x=λ2+1x = \frac\lambda2 + 1, y=λ+2y = \lambda + 2, z=λ2z = \frac\lambda2. Solve each coordinate in terms of λ\lambda.
    4. Constraint. (λ2+1)+2(λ+2)+λ2=3λ+5=10\big(\frac\lambda2 + 1\big) + 2(\lambda + 2) + \frac\lambda2 = 3\lambda + 5 = 10, so λ=53\lambda = \frac53. Substitute into the plane.
    5. Point and distance. (x,y,z)=(116,113,56)(x, y, z) = \big(\frac{11}6, \frac{11}3, \frac56\big) and f=(56)2+(53)2+(56)2=15036f = \big(\frac56\big)^2 + \big(\frac53\big)^2 + \big(\frac56\big)^2 = \frac{150}{36}, so the distance is 56\frac{5}{\sqrt6}. The offsets from (1,2,0)(1, 2, 0) are 56,53,56\frac56, \frac53, \frac56.
    6. Why a minimum exists. The plane is unbounded, but f→∞f \to \infty far away, so ff has a smallest value; it must be at a candidate, and there is only one. Existence by growth.

    Answer. (116,113,56)\big(\frac{11}6, \frac{11}3, \frac56\big), distance 56≈2.041\frac5{\sqrt6} \approx 2.041. It agrees with the formula ∣1+4+0−10∣1+4+1\frac{\lvert1 + 4 + 0 - 10\rvert}{\sqrt{1 + 4 + 1}}. The offset from (1,2,0)(1, 2, 0) to the closest point is 56(1,2,1)\frac56(1, 2, 1), parallel to the normal ∇g=(1,2,1)\nabla g = (1, 2, 1), as the picture says.

    Your answerWhat is the shortest distance from (1,2,0)(1, 2, 0) to the plane x+2y+z=10x + 2y + z = 10? (Give a decimal.)
    Worked example MATH 376 Worksheet 1 #6
    Find the extreme values of f=x2+y2+z2f = x^2 + y^2 + z^2 on the line where the planes x+y+z=1x + y + z = 1 and x−y+2z=2x - y + 2z = 2 meet.

    Solution.

    1. Check independence. ∇g1=(1,1,1)\nabla g_1 = (1, 1, 1) and ∇g2=(1,−1,2)\nabla g_2 = (1, -1, 2) are not multiples of each other, at every point. Every point is regular; the two-constraint theorem applies.
    2. Equations. ∇f=(2x,2y,2z)=λ1(1,1,1)+λ2(1,−1,2)\nabla f = (2x, 2y, 2z) = \lambda_1(1, 1, 1) + \lambda_2(1, -1, 2), so x=λ1+λ22x = \frac{\lambda_1 + \lambda_2}2, y=λ1−λ22y = \frac{\lambda_1 - \lambda_2}2, z=λ1+2λ22z = \frac{\lambda_1 + 2\lambda_2}2. Solve each coordinate. (The Worksheet writes L=f+λ(g1−1)+μ(g2−2)L = f + \lambda(g_1 - 1) + \mu(g_2 - 2), so its multipliers are the negatives of these; the points are the same.)
    3. Constraints. x+y+z=3λ1+2λ22=1x + y + z = \frac{3\lambda_1 + 2\lambda_2}2 = 1 and x−y+2z=2λ1+6λ22=λ1+3λ2=2x - y + 2z = \frac{2\lambda_1 + 6\lambda_2}2 = \lambda_1 + 3\lambda_2 = 2. So 3λ1+2λ2=23\lambda_1 + 2\lambda_2 = 2 and λ1+3λ2=2\lambda_1 + 3\lambda_2 = 2. Two linear equations in the two multipliers.
    4. Solve. λ1=27\lambda_1 = \frac27, λ2=47\lambda_2 = \frac47. Then (x,y,z)=(37,−17,57)(x, y, z) = \big(\frac37, -\frac17, \frac57\big) and f=9+1+2549=57f = \frac{9 + 1 + 25}{49} = \frac57. Substitute.
    5. Decide. The feasible set is a line and f→∞f \to \infty along it, so the single candidate is the minimum and there is no maximum. Growth argument.

    Answer. Minimum 57\frac57 at (37,−17,57)\big(\frac37, -\frac17, \frac57\big); no maximum. The sympy lab below reports the multipliers 27,47\frac27, \frac47 for this same problem.

    Worked example MATH 376 Worksheet 3 #2
    Minimise 50x+100y50x + 100y subject to 100xy=1000100\sqrt{xy} = 1000, with x,y>0x, y \gt 0.

    Solution.

    1. Clean the constraint. xy=10\sqrt{xy} = 10 means g=xy=100g = xy = 100 for x,y>0x, y \gt 0. Same set, no square root.
    2. Singular points. ∇g=(y,x)≠O\nabla g = (y, x) \ne O for x,y>0x, y \gt 0. No extra candidates.
    3. Equations. 50=λy50 = \lambda y and 100=λx100 = \lambda x. Dividing the second by the first, 2=x/y2 = x/y, so x=2yx = 2y. λ≠0\lambda \ne 0 (else 50=050 = 0) and y>0y \gt 0, so the division is legal.
    4. Constraint. 2y2=1002y^2 = 100, y=52y = 5\sqrt2, x=102x = 10\sqrt2. Substitute x=2yx = 2y into xy=100xy = 100.
    5. Cost and existence. The cost is 50⋅102+100⋅52=10002≈141450\cdot10\sqrt2 + 100\cdot5\sqrt2 = 1000\sqrt2 \approx 1414. On the curve y=100/xy = 100/x the cost 50x+10000/x→∞50x + 10000/x \to \infty as x→0+x \to 0^+ and as x→∞x \to \infty, so a minimum exists and it is the only candidate. Existence by growth.

    Answer. x=102≈14.14x = 10\sqrt2 \approx 14.14, y=52≈7.07y = 5\sqrt2 \approx 7.07, minimum cost 10002≈14141000\sqrt2 \approx 1414. The input with the lower price (here xx, at 5050 against 100100) is bought in the larger amount, x/y=price of yprice of x=2x/y = \frac{\text{price of }y}{\text{price of }x} = 2, which is what the equal exponents in xy\sqrt{xy} give.

    Worked example MATH 376 Worksheet 3 #3
    Minimise f=xf = x on the curve y2=x3y^2 = x^3. Why does the Lagrange recipe fail?

    Solution.

    1. Write the constraint. g=y2−x3=0g = y^2 - x^3 = 0 with ∇g=(−3x2,2y)\nabla g = (-3x^2, 2y). Step 1 of the recipe.
    2. Singular points. ∇g=O\nabla g = O only at (0,0)(0, 0), which is on the curve. That point is a separate candidate, not covered by the theorem.
    3. Try Lagrange. ∇f=(1,0)=λ(−3x2,2y)\nabla f = (1, 0) = \lambda(-3x^2, 2y): the first component needs 1=−3λx21 = -3\lambda x^2, so x≠0x \ne 0; the second needs λy=0\lambda y = 0, so y=0y = 0 (since λ≠0\lambda \ne 0). But y=0y = 0 and y2=x3y^2 = x^3 force x=0x = 0. Contradiction. The system has no solutions at all.
    4. The true minimum. On the curve x3=y2≥0x^3 = y^2 \ge 0, so x≥0x \ge 0, and x=0x = 0 is attained at the origin. Direct inspection.

    Answer. The minimum is 00 at (0,0)(0, 0), the single singular point, where no multiplier exists. This is why step 1 of the recipe (find the points with ∇g=O\nabla g = O) cannot be skipped. In the visualiser, choose the last picture and slide to 00.

    Quick checkYou solve ∇f=λ∇g\nabla f = \lambda\nabla g with g=cg = c and find exactly one solution. What else must you do before calling it the minimum?
    Worked example MATH 376 Homework 1 #1
    Find the shortest distance from (1,2,3)(1, 2, 3) to the northern hemisphere {x2+y2+z2=1, z≥0}\{x^2 + y^2 + z^2 = 1,\ z \ge 0\}.

    Solution.

    1. Use the whole sphere. Minimise f=(x−1)2+(y−2)2+(z−3)2f = (x - 1)^2 + (y - 2)^2 + (z - 3)^2 on g=x2+y2+z2=1g = x^2 + y^2 + z^2 = 1. ∇g=2(x,y,z)≠O\nabla g = 2(x, y, z) \ne O on the sphere. The constraint is smooth on the full sphere; the boundary z=0z = 0 of the hemisphere would add a second kind of candidate, to be checked at the end.
    2. Equations. 2(x−1)=2λx2(x - 1) = 2\lambda x, and similarly for y,zy, z, so (1−λ)x=1(1 - \lambda)x = 1, (1−λ)y=2(1 - \lambda)y = 2, (1−λ)z=3(1 - \lambda)z = 3. Move λx\lambda x to the left and divide by 22.
    3. Find λ\lambda. Square and add: (1−λ)2(x2+y2+z2)=1+4+9=14(1 - \lambda)^2(x^2 + y^2 + z^2) = 1 + 4 + 9 = 14, and on the sphere the bracket is 11, so 1−λ=±141 - \lambda = \pm\sqrt{14}. Use the constraint.
    4. The points. (x,y,z)=±(1,2,3)14(x, y, z) = \pm\dfrac{(1, 2, 3)}{\sqrt{14}}. Divide each equation by 1−λ1 - \lambda.
    5. Choose. The plus sign has z>0z \gt 0, so q=(1,2,3)14q = \frac{(1, 2, 3)}{\sqrt{14}} is in the hemisphere. The distance to qq is (1−114)14=14−1\big(1 - \frac1{\sqrt{14}}\big)\sqrt{14} = \sqrt{14} - 1, and to −q-q it is 14+1\sqrt{14} + 1. (1,2,3)−q(1, 2, 3) - q is a multiple of (1,2,3)(1, 2, 3).
    6. The boundary. The closest point of the whole sphere already lies in the hemisphere, so the boundary circle z=0z = 0 is not a competitor. A minimum over a larger set that lies in the smaller set is also the minimum over the smaller set.

    Answer. 14−1≈2.742\sqrt{14} - 1 \approx 2.742, at (1,2,3)14\frac{(1, 2, 3)}{\sqrt{14}}. (For a point vv outside the unit ball the closest point of the sphere is v/∥v∥v/\lVert v\rVert and the distance is ∥v∥−1\lVert v\rVert - 1.)

    Worked example new (the style of MATH 375 Lecture 24: interior critical points, then check the boundary)
    Find the largest and smallest values of f(x,y)=x2+2y2−xf(x, y) = x^2 + 2y^2 - x on the closed unit disc x2+y2≤1x^2 + y^2 \le 1.

    Solution.

    1. Interior. ∇f=(2x−1, 4y)=O\nabla f = (2x - 1,\ 4y) = O at (12,0)\big(\frac12, 0\big), an interior point, with f=14−12=−14f = \frac14 - \frac12 = -\frac14. The zero-gradient rule applies in the interior (5.6).
    2. Boundary by a multiplier. On x2+y2=1x^2 + y^2 = 1: 2x−1=2λx2x - 1 = 2\lambda x and 4y=2λy4y = 2\lambda y. The second gives y=0y = 0 or λ=2\lambda = 2. If y=0y = 0, then x=±1x = \pm1: f(1,0)=0f(1, 0) = 0, f(−1,0)=2f(-1, 0) = 2. If λ=2\lambda = 2, then 2x−1=4x2x - 1 = 4x, x=−12x = -\frac12, y=±32y = \pm\frac{\sqrt3}2, and f=14+32+12=94f = \frac14 + \frac32 + \frac12 = \frac94. Case split on the factor yy rather than dividing by it.
    3. Boundary by substitution. With x=cos⁡tx = \cos t, y=sin⁡ty = \sin t: f=cos⁡2t+2sin⁡2t−cos⁡t=2−cos⁡2t−cos⁡tf = \cos^2t + 2\sin^2t - \cos t = 2 - \cos^2t - \cos t. As a function of c=cos⁡t∈[−1,1]c = \cos t \in [-1, 1] this is 2−c2−c2 - c^2 - c, with derivative −2c−1=0-2c - 1 = 0 at c=−12c = -\frac12, value 94\frac94, and endpoint values 00 (c=1c = 1) and 22 (c=−1c = -1). The two methods give the same candidates and values.
    4. Compare. Candidates: −14-\frac14 (interior), 00, 22, 94\frac94 (boundary). The disc is compact, so the largest and smallest values exist (5.6). Absolute extrema on a compact set: compare interior critical points with boundary candidates.

    Answer. Maximum 94\frac94 at (−12,±32)\big(-\frac12, \pm\frac{\sqrt3}2\big); minimum −14-\frac14 at the interior point (12,0)\big(\frac12, 0\big). Note that the minimum on the boundary alone is 00: the true minimum is not on the boundary.

    Your answerWhat is the largest value of x2+2y2−xx^2 + 2y^2 - x on the closed unit disc?
    Worked example Apostol 9.15 #2
    Find the greatest and least distances from the origin to the curve 5x2+6xy+5y2=85x^2 + 6xy + 5y^2 = 8.

    Solution.

    1. Set up. Minimise and maximise f=x2+y2f = x^2 + y^2 (the squared distance) on g=5x2+6xy+5y2=8g = 5x^2 + 6xy + 5y^2 = 8. ∇g=(10x+6y, 6x+10y)\nabla g = (10x + 6y,\ 6x + 10y) is zero only at the origin, which is not on the curve. No singular candidates.
    2. Equations. ∇f=(2x,2y)=λ∇g\nabla f = (2x, 2y) = \lambda\nabla g, that is [5335][xy]=1λ[xy]\begin{bmatrix}5 & 3\\ 3 & 5\end{bmatrix}\begin{bmatrix}x\\ y\end{bmatrix} = \dfrac1\lambda\begin{bmatrix}x\\ y\end{bmatrix}. Here ∇g=2A[xy]\nabla g = 2A\begin{bmatrix}x\\ y\end{bmatrix}, so ∇f=λ∇g\nabla f = \lambda\nabla g reads 2[xy]=2λA[xy]2\begin{bmatrix}x\\ y\end{bmatrix} = 2\lambda A\begin{bmatrix}x\\ y\end{bmatrix}. We have λ≠0\lambda \ne 0, else x=y=0x = y = 0, which is off the curve. Dividing by 2λ2\lambda says (x,y)(x, y) is an eigenvector of A=[5335]A = \begin{bmatrix}5 & 3\\ 3 & 5\end{bmatrix} with eigenvalue 1λ\frac1\lambda.
    3. Eigenvalues. AA has eigenvalues 88 (eigenvector (1,1)(1, 1)) and 22 (eigenvector (1,−1)(1, -1)). Trace 1010, determinant 1616: μ2−10μ+16=0\mu^2 - 10\mu + 16 = 0.
    4. Points. Along (1,1)(1, 1): (x,y)=s(1,1)(x, y) = s(1, 1) and g=16s2=8g = 16s^2 = 8, so s2=12s^2 = \frac12, f=2s2=1f = 2s^2 = 1. Along (1,−1)(1, -1): g=4s2=8g = 4s^2 = 8, s2=2s^2 = 2, f=2s2=4f = 2s^2 = 4. Substitute in the constraint, then compute f=x2+y2f = x^2 + y^2.
    5. Decide. The curve is closed and bounded, so both extremes are attained; they are the two values found.

    Answer. Nearest distance 11, at ±(22,22)\pm\big(\frac{\sqrt2}2, \frac{\sqrt2}2\big); farthest distance 22, at ±(2,−2)\pm(\sqrt2, -\sqrt2). The multiplier turned the problem into an eigenvalue problem: for a quadratic constraint xTAx=8x^{\mathsf T}Ax = 8 the squared distance is 8/μ8/\mu where μ\mu runs over the eigenvalues, and the principal axes of 3.2 are the ends of the ellipse’s axes. (Third picture of the visualiser.)

    Your answerWhat is the greatest distance from the origin to the curve 5x2+6xy+5y2=85x^2 + 6xy + 5y^2 = 8?
    Worked example Apostol 9.15 #7
    Find the shortest distance from (1,0)(1, 0) to the parabola y2=4xy^2 = 4x.

    Solution.

    1. Set up. Minimise f=(x−1)2+y2f = (x - 1)^2 + y^2 on g=y2−4x=0g = y^2 - 4x = 0. ∇g=(−4, 2y)\nabla g = (-4,\ 2y) is never OO. No singular points.
    2. Equations. 2(x−1)=−4λ2(x - 1) = -4\lambda and 2y=2λy2y = 2\lambda y. Components of ∇f=λ∇g\nabla f = \lambda\nabla g.
    3. Split on the second. y(1−λ)=0y(1 - \lambda) = 0. If y=0y = 0, then x=0x = 0 (from y2=4xy^2 = 4x), the point (0,0)(0, 0). If λ=1\lambda = 1, then 2(x−1)=−42(x - 1) = -4 gives x=−1x = -1, and y2=−4y^2 = -4: impossible. Never divide by yy without treating y=0y = 0 separately.
    4. Conclude. The only candidate is (0,0)(0, 0), at distance 11. A minimum exists since f→∞f \to \infty far along the curve. One candidate plus an existence argument.

    Answer. 11, at the vertex (0,0)(0, 0). Check by substitution: on the parabola f=(x−1)2+4x=(x+1)2f = (x - 1)^2 + 4x = (x + 1)^2 for x≥0x \ge 0, smallest at x=0x = 0.

    Which candidate is which? The second-order test

    The theorem produces candidates. For a maximum or minimum we used geometry or existence so far. When that is not available, there is a second-order test, which is the Hessian test of 5.6 restricted to the tangent space of the constraint.

    Definition B

    Bordered Hessian

    Let f,g1,…,gmf, g_1, \dots, g_m be C2C^2, aa a regular point with multipliers λi\lambda_i. The Hessian of the Lagrangian in the xx variables is H=D2f(a)−∑iλiD2gi(a)H = D^2f(a) - \sum_{i}\lambda_iD^2g_i(a), a symmetric n×nn \times n matrix (5.5). The bordered Hessian is B=[0Dg(a)Dg(a)TH]B = \begin{bmatrix}0 & Dg(a)\\ Dg(a)^{\mathsf T} & H\end{bmatrix}, with the m×nm \times n block Dg(a)Dg(a) above and its transpose beside HH. The tangent space is T=ker⁡Dg(a)T = \ker Dg(a) (5.7).

    In one lineThe (n+m)×(n+m)(n + m) \times (n + m) symmetric matrix B=[0Dg(a)Dg(a)TH]B = \begin{bmatrix}0 & Dg(a)\\ Dg(a)^{\mathsf T} & H\end{bmatrix}, where H=D2f(a)−∑λiD2gi(a)H = D^2f(a) - \sum\lambda_iD^2g_i(a) is the Hessian in xx of the Lagrangian.

    Why it existsIt puts the constraint gradients around the Hessian like a border, so that a single determinant (for two variables) or a few minors decide between maximum and minimum on the tangent space.

    Theorem B Rudin-style via 5.4 and 5.6; Apostol 9.14 (remark); Spivak ch. 5

    Second-order test for constrained extrema

    Let f,gif, g_i be C2C^2 near a regular point aa of gg with g(a)=cg(a) = c, ∇f(a)=∑λi∇gi(a)\nabla f(a) = \sum\lambda_i\nabla g_i(a), H=D2f(a)−∑λiD2gi(a)H = D^2f(a) - \sum\lambda_iD^2g_i(a) and T=ker⁡Dg(a)T = \ker Dg(a).

    (i) If vTHv>0v^{\mathsf T}Hv \gt 0 for every v∈T∖{O}v \in T\setminus\{O\}, then aa is a strict local constrained minimum of ff. If vTHv<0v^{\mathsf T}Hv \lt 0 for every such vv, a strict local constrained maximum.

    (ii) If aa is a local constrained minimum, then vTHv≥0v^{\mathsf T}Hv \ge 0 for all v∈Tv \in T; for a local constrained maximum, vTHv≤0v^{\mathsf T}Hv \le 0.

    In one lineAt a regular point with multipliers λi\lambda_i: if vTHv>0v^{\mathsf T}Hv \gt 0 for all nonzero vv in the tangent space then aa is a strict local constrained minimum; if <0\lt 0, a strict local maximum; a local minimum forces vTHv≥0v^{\mathsf T}Hv \ge 0 on the tangent space.

    Why it is trueIt is the second-derivative test with the constraint accounted for: only the directions along the constraint matter, and the curvature of the constraint itself enters through the term −∑λiD2gi-\sum\lambda_iD^2g_i in HH.

    ProofSpivak ch. 5; this version uses 5.4 and 5.6
    The idea: Parametrise the constraint by the free variables, as in the proof of the multiplier theorem. On the constraint, f equals the Lagrangian, and the Lagrangian has zero gradient at a, so the second derivative of the restricted function is the Hessian of the Lagrangian pulled back to the tangent space. Then apply the ordinary second-derivative test of 5.6 to the restricted function.
    Solve the constraint near aa as w=h(u)w = h(u) with hh of class C2C^2, and let X(u)=(u,h(u))X(u) = (u, h(u)).
    As in the multiplier theorem. Since f,gf, g are C2C^2, hh is C2C^2: Dh=−Dwg−1DugDh = -D_wg^{-1}D_ug is built from C1C^1 functions.
    Define φ(u)=f(X(u))=L(X(u),λ)\varphi(u) = f(X(u)) = L(X(u), \lambda) with L(x,λ)=f(x)−∑λi(gi(x)−ci)L(x, \lambda) = f(x) - \sum\lambda_i(g_i(x) - c_i) and λ\lambda the fixed multipliers.
    For xx on the constraint, g(x)=cg(x) = c, so the terms λi(gi−ci)\lambda_i(g_i - c_i) vanish: L(x,λ)=f(x)L(x, \lambda) = f(x) there.
    At aua_u: D2φ(au)=ZTHZD^2\varphi(a_u) = Z^{\mathsf T}HZ.
    Second derivatives of a composite (5.4): D2φ=ZT (D2L) Z+∑k∂L∂xk D2XkD^2\varphi = Z^{\mathsf T}\,(D^2L)\,Z + \sum_k\dfrac{\partial L}{\partial x_k}\,D^2X_k, where Z=DX(au)=[IDh]Z = DX(a_u) = \begin{bmatrix}I\\ Dh\end{bmatrix}. The sum has the factors ∂L∂xk(a)=0\frac{\partial L}{\partial x_k}(a) = 0, because ∇xL(a)=∇f(a)−∑λi∇gi(a)=O\nabla_xL(a) = \nabla f(a) - \sum\lambda_i\nabla g_i(a) = O.
    So vTHv>0v^{\mathsf T}Hv \gt 0 on T∖{O}T\setminus\{O\} says exactly that D2φ(au)D^2\varphi(a_u) is positive definite.
    5.7: the columns of ZZ are the tangent vectors (ej,Dh ej)(e_j, Dh\,e_j), a basis of T=ker⁡Dg(a)T = \ker Dg(a). So v∈Tv \in T means v=Zsv = Zs for a unique s∈Rn−ms \in \mathbb R^{n-m}, and vTHv=sTZTHZsv^{\mathsf T}Hv = s^{\mathsf T}Z^{\mathsf T}HZs.
    Positive definite: φ\varphi has a strict local minimum at aua_u, hence ff has a strict local constrained minimum at aa. The statements for maxima and (ii) are the same with signs changed or with ‘semidefinite’. ■\blacksquare
    ∇φ(au)=O\nabla\varphi(a_u) = O (proof of the multiplier theorem) and the second-derivative test of 5.6, together with its converse for a minimum (a minimum needs a positive semidefinite Hessian).
    Corollary B standard; Apostol 9.14 remark

    Bordered determinant test in two variables

    Let n=2n = 2, m=1m = 1, aa a regular point, gx=gx(a)g_x = g_x(a), gy=gy(a)g_y = g_y(a) and Lxx,Lxy,LyyL_{xx}, L_{xy}, L_{yy} the entries of HH. Then

    det⁡B=det⁡[0gxgygxLxxLxygyLxyLyy]=−(gx2Lyy−2gxgyLxy+gy2Lxx).\det B = \det\begin{bmatrix}0 & g_x & g_y\\ g_x & L_{xx} & L_{xy}\\ g_y & L_{xy} & L_{yy}\end{bmatrix} = -\big(g_x^2L_{yy} - 2g_xg_yL_{xy} + g_y^2L_{xx}\big).

    If det⁡B>0\det B \gt 0, aa is a strict local constrained maximum; if det⁡B<0\det B \lt 0, a strict local constrained minimum.

    In one lineFor f(x,y)f(x, y) with one constraint gg at a regular point: det⁡B>0\det B \gt 0 means a strict local constrained maximum, det⁡B<0\det B \lt 0 a strict local constrained minimum, where BB is the 3×33 \times 3 bordered Hessian.

    Why it is trueIt gives a one-line test for the most common case, and shows how the bordering encodes the restriction to the tangent line.

    Proofstandard
    The idea: The tangent space is the line spanned by (minus g_y, g_x). Compute v-transpose H v for that vector and compare it with the determinant.
    det⁡B=−gx2Lyy+2gxgyLxy−gy2Lxx\det B = -g_x^2L_{yy} + 2g_xg_yL_{xy} - g_y^2L_{xx}.
    Expand along the first row: 0−gx(gxLyy−Lxygy)+gy(gxLxy−Lxxgy)0 - g_x\big(g_xL_{yy} - L_{xy}g_y\big) + g_y\big(g_xL_{xy} - L_{xx}g_y\big).
    The tangent line is spanned by v=(−gy,gx)v = (-g_y, g_x).
    T=ker⁡Dg={v:gxv1+gyv2=0}T = \ker Dg = \{v : g_xv_1 + g_yv_2 = 0\} is the line through v=(−gy,gx)v = (-g_y, g_x) (nonzero since the point is regular).
    vTHv=gy2Lxx−2gxgyLxy+gx2Lyy=−det⁡Bv^{\mathsf T}Hv = g_y^2L_{xx} - 2g_xg_yL_{xy} + g_x^2L_{yy} = -\det B.
    Multiply out vTHv=Lxxv12+2Lxyv1v2+Lyyv22v^{\mathsf T}Hv = L_{xx}v_1^2 + 2L_{xy}v_1v_2 + L_{yy}v_2^2 with v1=−gyv_1 = -g_y, v2=gxv_2 = g_x.
    So det⁡B<0\det B \lt 0 gives vTHv>0v^{\mathsf T}Hv \gt 0: a strict local minimum; det⁡B>0\det B \gt 0 gives a strict local maximum.
    Every nonzero tangent vector is a nonzero multiple of vv, so wTHww^{\mathsf T}Hw has the same sign as vTHvv^{\mathsf T}Hv. Then the second-order test: −det⁡B>0-\det B \gt 0 means minimum, <0\lt 0 means maximum. ■\blacksquare

    For more variables the same idea is a test on the leading principal minors of BB (the determinants of its top-left k×kk \times k blocks). With nn variables and mm constraints, look at the n−mn - m minors of orders 2m+1,…,m+n2m + 1, \dots, m + n. If all have the sign of (−1)m(-1)^m the point is a strict local minimum. If they alternate in sign, starting with the sign of (−1)m+1(-1)^{m + 1} at order 2m+12m + 1, it is a strict local maximum. For n=2n = 2, m=1m = 1 there is the single minor det⁡B\det B of order 33, and the rule is the one proved above. We state the general rule without proof; its source is the same reduction to the tangent space. Check on x2+y2+z2x^2 + y^2 + z^2 with the constraint x+y+z=1x + y + z = 1 (n=3n = 3, m=1m = 1): the minors of orders 33 and 44 are −4-4 and −12-12, both with the sign of (−1)1(-1)^1, so the point is a minimum.

    Worked example MATH 376 Worksheet 1 #5, second-order check (new)
    Classify the four candidates of xyxy on x2+y2=1x^2 + y^2 = 1 with the bordered Hessian.

    Solution.

    1. Hessian of the Lagrangian. With L=xy−λ(x2+y2−1)L = xy - \lambda(x^2 + y^2 - 1): Lxx=Lyy=−2λL_{xx} = L_{yy} = -2\lambda, Lxy=1L_{xy} = 1. D2f=[0110]D^2f = \begin{bmatrix}0 & 1\\ 1 & 0\end{bmatrix} and D2g=2ID^2g = 2I.
    2. At (22,22)\big(\frac{\sqrt2}2, \frac{\sqrt2}2\big), λ=12\lambda = \frac12. Lxx=Lyy=−1L_{xx} = L_{yy} = -1, gx=gy=2g_x = g_y = \sqrt2. gx2Lyy−2gxgyLxy+gy2Lxx=−2−4−2=−8g_x^2L_{yy} - 2g_xg_yL_{xy} + g_y^2L_{xx} = -2 - 4 - 2 = -8, so det⁡B=+8>0\det B = +8 \gt 0. Positive: maximum.
    3. At (22,−22)\big(\frac{\sqrt2}2, -\frac{\sqrt2}2\big), λ=−12\lambda = -\frac12. Lxx=Lyy=1L_{xx} = L_{yy} = 1, gx=2g_x = \sqrt2, gy=−2g_y = -\sqrt2. The bracket is 2+4+2=82 + 4 + 2 = 8, so det⁡B=−8<0\det B = -8 \lt 0. Negative: minimum.
    4. The other two are the negatives of these points; the same values hold by symmetry.

    Answer. Maxima (value 12\frac12) where x,yx, y have the same sign, minima (value −12-\frac12) where they differ, in agreement with the compactness argument. A second example: minimising x+yx + y on xy=1xy = 1, x>0x \gt 0: at (1,1)(1, 1), λ=1\lambda = 1, Lxx=Lyy=0L_{xx} = L_{yy} = 0, Lxy=−1L_{xy} = -1, gx=gy=1g_x = g_y = 1, bracket =0+2+0=2= 0 + 2 + 0 = 2, det⁡B=−2<0\det B = -2 \lt 0: a minimum, value 22 (the inequality x+1x≥2x + \frac1x \ge 2).

    Quick checkAt a candidate for the problem 'maximise ff on g=cg = c' the bordered determinant is det⁡B=−6\det B = -6 (two variables, one constraint). What is the candidate?

    What the multiplier means

    Theorem B standard (the shadow price of economics); Lagrange's mechanical interpretation

    The multiplier is the price of the constraint

    Let f,gf, g be C1C^1 with m=1m = 1, and suppose for cc in an interval there is a C1C^1 curve c↦x∗(c)c \mapsto x^*(c) of regular constrained extrema with g(x∗(c))=cg(x^*(c)) = c and ∇f(x∗(c))=λ(c)∇g(x∗(c))\nabla f(x^*(c)) = \lambda(c)\nabla g(x^*(c)). Then V(c)=f(x∗(c))V(c) = f(x^*(c)) has V′(c)=λ(c)V'(c) = \lambda(c).

    In one lineIf the constrained optimum x∗(c)x^*(c) depends differentiably on cc and V(c)=f(x∗(c))V(c) = f(x^*(c)), then V′(c)=λ(c)V'(c) = \lambda(c): the multiplier is the rate at which the best value changes when the constraint g=cg = c is moved.

    Why it is trueIt explains why the multiplier is worth computing: it tells you how much a unit of loosening the constraint is worth (a price), and its size tells you how binding the constraint is.

    Proofstandard
    The idea: Differentiate V with the chain rule, replace the gradient of f by lambda times the gradient of g, and differentiate the constraint to see that the remaining dot product equals 1.
    V′(c)=∇f(x∗(c))⋅x∗′(c)V'(c) = \nabla f(x^*(c))\cdot x^{*\prime}(c).
    Chain rule along the curve x∗(c)x^*(c) (5.3).
    =λ(c) ∇g(x∗(c))⋅x∗′(c)= \lambda(c)\,\nabla g(x^*(c))\cdot x^{*\prime}(c).
    The multiplier equation at x∗(c)x^*(c).
    ∇g(x∗(c))⋅x∗′(c)=1\nabla g(x^*(c))\cdot x^{*\prime}(c) = 1, so V′(c)=λ(c)V'(c) = \lambda(c). ■\blacksquare
    Differentiate the identity g(x∗(c))=cg(x^*(c)) = c with the chain rule: the right side has derivative 11.This is the whole content: moving the constraint by dcdc moves the point by dxdx with ∇g⋅dx=dc\nabla g\cdot dx = dc, and the first-order change of ff is λ dc\lambda\,dc.
    Worked example
    Check the price theorem on: minimise x2+y2x^2 + y^2 subject to x+y=cx + y = c.

    Solution.

    1. Solve. ∇f=(2x,2y)=λ(1,1)\nabla f = (2x, 2y) = \lambda(1, 1), so x=y=λ2x = y = \frac\lambda2, and the constraint gives λ=c\lambda = c, x=y=c2x = y = \frac c2. Lagrange.
    2. The best value. V(c)=c24+c24=c22V(c) = \frac{c^2}4 + \frac{c^2}4 = \frac{c^2}2. Substitute.
    3. Compare. V′(c)=c=λ(c)V'(c) = c = \lambda(c). The theorem holds: loosening x+y=cx + y = c by one unit raises the minimum squared distance at rate cc.

    Answer. V′(c)=λ=cV'(c) = \lambda = c. For several constraints, ∂V/∂ci=λi\partial V/\partial c_i = \lambda_i.

    Convexity: when a candidate is automatically the best

    Definition B

    Convex function

    A set C⊆RnC \subseteq \mathbb R^n is convex if it contains the segment between any two of its points (a ball, a plane, all of Rn\mathbb R^n). A function f:C→Rf: C \to \mathbb R is a convex function if f(tx+(1−t)y)≤tf(x)+(1−t)f(y)f\big(tx + (1 - t)y\big) \le tf(x) + (1 - t)f(y) for all x,y∈Cx, y \in C and t∈[0,1]t \in [0, 1], that is, the graph lies below every chord. It is concave if −f-f is convex. Examples: ∥x∥2\lVert x\rVert^2, exe^x, xTAxx^{\mathsf T}Ax with AA positive semidefinite; ln⁡x\ln x is concave.

    In one lineA function ff on a convex set with f(tx+(1−t)y)≤tf(x)+(1−t)f(y)f\big(tx + (1 - t)y\big) \le tf(x) + (1 - t)f(y) for all x,yx, y and t∈[0,1]t \in [0, 1]: the graph lies below every chord.

    Why it existsIt is the property that makes every critical point a global minimum, which is why convex problems are the ones that optimisation solves reliably (5.10).

    Theorem B standard (Boyd and Vandenberghe, Convex Optimization, 3.1.3)

    Gradient inequality for convex functions

    If ff is convex and differentiable on an open convex set CC, then for all x,y∈Cx, y \in C: f(y)≥f(x)+∇f(x)⋅(y−x)f(y) \ge f(x) + \nabla f(x)\cdot(y - x).

    In one lineA differentiable convex function lies above each of its tangent planes: f(y)≥f(x)+∇f(x)⋅(y−x)f(y) \ge f(x) + \nabla f(x)\cdot(y - x).

    Why it is trueIt says the linearization is a lower bound, so a zero gradient forces the global minimum; it also drives the convergence proofs of gradient descent.

    Proofstandard
    The idea: Compare the chord with the tangent: the difference quotient of f in the direction y minus x increases with the step, so it is at most its value at the full step, and its limit at step 0 is the directional derivative.
    f(x+t(y−x))≤(1−t)f(x)+tf(y)f(x + t(y - x)) \le (1 - t)f(x) + tf(y).
    Convexity with the point x+t(y−x)=(1−t)x+tyx + t(y - x) = (1 - t)x + ty, 0<t≤10 \lt t \le 1.
    f(x+t(y−x))−f(x)t≤f(y)−f(x)\dfrac{f(x + t(y - x)) - f(x)}{t} \le f(y) - f(x).
    Subtract f(x)f(x) and divide by t>0t \gt 0.
    So ∇f(x)⋅(y−x)≤f(y)−f(x)\nabla f(x)\cdot(y - x) \le f(y) - f(x).
    Let t→0+t \to 0^+: the left side tends to f′(x;y−x)=∇f(x)⋅(y−x)f'(x; y - x) = \nabla f(x)\cdot(y - x) by 5.3. ■\blacksquare
    Theorem B standard

    Positive semidefinite Hessian implies convex

    Let ff be C2C^2 on an open convex set CC with vTHf(x)v≥0v^{\mathsf T}H_f(x)v \ge 0 for all x∈Cx \in C, v∈Rnv \in \mathbb R^n. Then ff is convex on CC.

    In one lineIf ff is C2C^2 on an open convex set and its Hessian is positive semidefinite everywhere, then ff is convex; in particular 12xTAx−bTx\tfrac12x^{\mathsf T}Ax - b^{\mathsf T}x is convex when AA is symmetric positive semidefinite.

    Why it is trueIt turns convexity into the eigenvalue test of 3.2, so you can check it for any smooth function.

    Proofstandard
    The idea: Show the tangent-plane inequality on each segment with the one-variable mean value theorem, then average the two tangent-plane inequalities at the point on the chord.
    ψ′\psi' is non-decreasing on [0,1][0, 1] (its derivative is ≥0\ge 0, mean value theorem of 1.4).
    Fix x,yx, y and put ψ(t)=f(x+t(y−x))\psi(t) = f(x + t(y - x)). Then ψ′(t)=∇f(⋅)⋅(y−x)\psi'(t) = \nabla f(\cdot)\cdot(y - x) and ψ′′(t)=(y−x)THf(⋅)(y−x)≥0\psi''(t) = (y - x)^{\mathsf T}H_f(\cdot)(y - x) \ge 0 (chain rule twice, 5.4).
    f(y)−f(x)≥ψ′(0)=∇f(x)⋅(y−x)f(y) - f(x) \ge \psi'(0) = \nabla f(x)\cdot(y - x).
    Mean value theorem: ψ(1)−ψ(0)=ψ′(ξ)\psi(1) - \psi(0) = \psi'(\xi) for some ξ∈(0,1)\xi \in (0, 1), and ψ′(ξ)≥ψ′(0)\psi'(\xi) \ge \psi'(0).
    tf(x)+(1−t)f(y)≥f(z)=f(tx+(1−t)y)tf(x) + (1 - t)f(y) \ge f(z) = f(tx + (1 - t)y). ■\blacksquare
    Apply this at z=tx+(1−t)yz = tx + (1 - t)y twice: f(x)≥f(z)+∇f(z)⋅(x−z)f(x) \ge f(z) + \nabla f(z)\cdot(x - z) and f(y)≥f(z)+∇f(z)⋅(y−z)f(y) \ge f(z) + \nabla f(z)\cdot(y - z). Multiply by tt and 1−t1 - t and add: the gradient terms cancel because t(x−z)+(1−t)(y−z)=Ot(x - z) + (1 - t)(y - z) = O.
    Corollary B standard

    A convex Lagrangian gives a global minimum

    Suppose ∇xL(a,λ)=O\nabla_xL(a, \lambda) = O, g(a)=cg(a) = c and L(⋅,λ)L(\cdot, \lambda) is convex and differentiable. Then f(x)≥f(a)f(x) \ge f(a) for every xx with g(x)=cg(x) = c. In particular this holds whenever ff is convex and the constraints are linear, Mx=cMx = c.

    In one lineIf x↦L(x,λ)=f(x)−∑λi(gi(x)−ci)x \mapsto L(x, \lambda) = f(x) - \sum\lambda_i(g_i(x) - c_i) is convex and aa satisfies ∇f(a)=∑λi∇gi(a)\nabla f(a) = \sum\lambda_i\nabla g_i(a) and g(a)=cg(a) = c, then aa is an absolute minimum of ff on {g=c}\{g = c\}.

    Why it is trueThis is the case where the recipe needs no existence argument and no second-order test: for convex ff with linear constraints (least squares, quadratic programs, maximum entropy) every Lagrange point is the global optimum.

    Proofstandard
    The idea: On the constraint set f equals the Lagrangian; a convex function with zero gradient at a is minimal at a.
    For feasible xx, f(x)=L(x,λ)f(x) = L(x, \lambda) and f(a)=L(a,λ)f(a) = L(a, \lambda).
    For g(x)=cg(x) = c the terms λi(gi−ci)\lambda_i(g_i - c_i) vanish.
    L(x,λ)≥L(a,λ)+∇xL(a,λ)⋅(x−a)=L(a,λ)L(x, \lambda) \ge L(a, \lambda) + \nabla_xL(a, \lambda)\cdot(x - a) = L(a, \lambda).
    Gradient inequality for the convex function L(⋅,λ)L(\cdot, \lambda), with ∇xL(a,λ)=O\nabla_xL(a, \lambda) = O.
    So f(x)≥f(a)f(x) \ge f(a) for all feasible xx.
    Combine. If ff is convex and gig_i linear, then LL is convex (sum of a convex and a linear function). ■\blacksquare
    Quick checkMinimise ∥x∥2\lVert x\rVert^2 on the set Mx=cMx = c (an affine subspace). You solve 2x=MTλ2x = M^{\mathsf T}\lambda, Mx=cMx = c and find one solution. What does the corollary say?

    Where it is used

    Used inside maths· Inside maths: eigenvalues, inequalities and minimum-norm solutions

    Eigenvalues are Lagrange multipliers. The maximum of xTAxx^{\mathsf T}Ax on ∥x∥=1\lVert x\rVert = 1, for AA symmetric, is found by ∇(xTAx)=2Ax=λ⋅2x\nabla(x^{\mathsf T}Ax) = 2Ax = \lambda\cdot2x, so every candidate is an eigenvector and the value there is xTAx=λx^{\mathsf T}Ax = \lambda. The sphere is compact, so the maximum is attained: it is the largest eigenvalue. This is the Rayleigh bound used in 5.6, and it proves the spectral theorem’s first step (3.1). The same argument with ATAA^{\mathsf T}A shows σ1=max⁡∥x∥=1∥Ax∥\sigma_1 = \max_{\lVert x\rVert = 1}\lVert Ax\rVert (3.4). Inequalities. The maximum of a⋅xa\cdot x on ∥x∥=1\lVert x\rVert = 1 is ∥a∥\lVert a\rVert (the Cauchy–Schwarz inequality, problem below). To maximise xyzxyz on x+y+z=sx + y + z = s with x,y,z≥0x, y, z \ge 0: the maximum exists on the compact triangle and is not on the boundary (where xyz=0xyz = 0); ∇=(yz,xz,xy)=λ(1,1,1)\nabla = (yz, xz, xy) = \lambda(1, 1, 1) forces x=y=z=s3x = y = z = \frac s3; so xyz≤(s3)3xyz \le \big(\frac s3\big)^3, the AM–GM inequality for three numbers. Minimum-norm solutions. Among all solutions of an underdetermined system Mx=cMx = c the shortest is x=MT(MMT)−1cx = M^{\mathsf T}(MM^{\mathsf T})^{-1}c (the corollary above): for the two planes of Worksheet 1 #6 this is the point (37,−17,57)\big(\frac37, -\frac17, \frac57\big), whose norm squared is 57\frac57.

    Used in the real world· Entropy, portfolios, margins and budgets: four real Lagrange problems

    Maximum entropy (physics and machine learning). Among all probability distributions p=(p1,…,pn)p = (p_1, \dots, p_n) the entropy H(p)=−∑piln⁡piH(p) = -\sum p_i\ln p_i measures how spread out pp is. E. T. Jaynes (1957) proposed this as a rule of inference: among all distributions that fit what you know, pick the one with the largest entropy, because it assumes nothing more. Maximise it subject to ∑pi=1\sum p_i = 1: −ln⁡pi−1=λ-\ln p_i - 1 = \lambda for every ii, so all pip_i are equal, pi=1np_i = \frac1n, H=ln⁡nH = \ln n (for n=8n = 8: ln⁡8=2.079\ln8 = 2.079 nats, which is 33 bits). Add a constraint on the average of a quantity EiE_i (energy): ∑piEi=e\sum p_iE_i = e. The equation becomes −ln⁡pi−1=λ0+βEi-\ln p_i - 1 = \lambda_0 + \beta E_i, so pi=e−βEi/Zp_i = e^{-\beta E_i}/Z with Z=∑e−βEiZ = \sum e^{-\beta E_i}, the Boltzmann distribution, and the multiplier β\beta is the inverse temperature. The Hessian of HH is −diag⁡(1/pi)-\operatorname{diag}(1/p_i), negative definite, so HH is concave, and the corollary applied to −H-H (convex) says this is the global maximum. Numbers: three levels with E=(0,1,2)E = (0, 1, 2) and mean energy 12\frac12: with x=e−βx = e^{-\beta} the mean is x+2x21+x+x2=12\frac{x + 2x^2}{1 + x + x^2} = \frac12, that is 3x2+x−1=03x^2 + x - 1 = 0, x=−1+136=0.4343x = \frac{-1 + \sqrt{13}}6 = 0.4343, p=(0.616,0.268,0.116)p = (0.616, 0.268, 0.116), H=0.901H = 0.901 nats against ln⁡3=1.099\ln3 = 1.099 for the uniform distribution (which has mean 11). For a six-sided die forced to average 4.54.5, the maximum-entropy distribution has β=−0.371\beta = -0.371 and p=(0.054,0.079,0.114,0.165,0.240,0.347)p = (0.054, 0.079, 0.114, 0.165, 0.240, 0.347), H=1.614H = 1.614 nats against ln⁡6=1.792\ln6 = 1.792. And the softmax of a neural network is the same: maximising ∑pizi+H(p)\sum p_iz_i + H(p) over distributions gives pi=ezi/∑jezjp_i = e^{z_i}/\sum_je^{z_j} with the maximum value ln⁡∑jezj\ln\sum_je^{z_j}, so the output layer of a classifier (3.8, 5.10) returns the maximum-entropy distribution compatible with its scores ziz_i.

    Portfolio optimisation (finance). Harry Markowitz (1952) proposed choosing portfolio weights ww to minimise the variance wTΣww^{\mathsf T}\Sigma w for a target expected return: constraints 1Tw=1\mathbf 1^{\mathsf T}w = 1 and μTw=r\mu^{\mathsf T}w = r. Lagrange gives 2Σw=λ11+λ2μ2\Sigma w = \lambda_1\mathbf 1 + \lambda_2\mu, and together with the two constraints this is one linear system (its matrix is the bordered matrix [2Σ1μ1T00μT00]\begin{bmatrix}2\Sigma & \mathbf 1 & \mu\\ \mathbf 1^{\mathsf T} & 0 & 0\\ \mu^{\mathsf T} & 0 & 0\end{bmatrix}). Take three assets with expected returns μ=(6%,10%,14%)\mu = (6\%, 10\%, 14\%), standard deviations 20%,30%,40%20\%, 30\%, 40\% and covariances Σ12=0.006\Sigma_{12} = 0.006, Σ23=0.012\Sigma_{23} = 0.012, Σ13=0\Sigma_{13} = 0 (so Σ=[0.040.00600.0060.090.01200.0120.16]\Sigma = \begin{bmatrix}0.04 & 0.006 & 0\\ 0.006 & 0.09 & 0.012\\ 0 & 0.012 & 0.16\end{bmatrix}). The target r=9%r = 9\% gives w=(0.485,0.281,0.235)w = (0.485, 0.281, 0.235) with standard deviation 16.9%16.9\%. Dropping the return constraint (only 1Tw=1\mathbf 1^{\mathsf T}w = 1) gives the minimum-variance portfolio w=Σ−111TΣ−11=(0.622,0.231,0.147)w = \dfrac{\Sigma^{-1}\mathbf 1}{\mathbf 1^{\mathsf T}\Sigma^{-1}\mathbf 1} = (0.622, 0.231, 0.147) with standard deviation 16.2%16.2\% and return 8.1%8.1\%. The quadratic objective is convex, so these Lagrange points are global minima (corollary). (Weights here happen to be positive; a ban on short selling adds inequality constraints.)

    Support vector machines (a light look). To separate points with labels yi=±1y_i = \pm1 by a plane w⋅x+b=0w\cdot x + b = 0 with the widest empty margin, minimise 12∥w∥2\frac12\lVert w\rVert^2 subject to yi(w⋅xi+b)≥1y_i(w\cdot x_i + b) \ge 1. These are inequality constraints; the Lagrangian 12∥w∥2−∑αi(yi(w⋅xi+b)−1)\frac12\lVert w\rVert^2 - \sum\alpha_i\big(y_i(w\cdot x_i + b) - 1\big) now needs multipliers αi≥0\alpha_i \ge 0 (the Karush–Kuhn–Tucker conditions, B). Setting the derivatives in ww and bb to zero gives w=∑αiyixiw = \sum\alpha_iy_ix_i and ∑αiyi=0\sum\alpha_iy_i = 0, and substituting back leaves the dual problem: maximise ∑αi−12∑i,jαiαjyiyj xi⋅xj\sum\alpha_i - \frac12\sum_{i,j}\alpha_i\alpha_jy_iy_j\,x_i\cdot x_j. It involves the data only through dot products xi⋅xjx_i\cdot x_j, which is why one can replace them by kernels. Tiny example: x1=(2,0)x_1 = (2, 0) with y1=+1y_1 = +1 and x2=(0,0)x_2 = (0, 0) with y2=−1y_2 = -1. The constraint ∑αiyi=0\sum\alpha_iy_i = 0 forces α1=α2=α\alpha_1 = \alpha_2 = \alpha, the dual is 2α−12α2∥x1−x2∥2=2α−2α22\alpha - \frac12\alpha^2\lVert x_1 - x_2\rVert^2 = 2\alpha - 2\alpha^2, maximal at α=12\alpha = \frac12, and w=α(x1−x2)=(1,0)w = \alpha(x_1 - x_2) = (1, 0). From y1(w⋅x1+b)=1y_1(w\cdot x_1 + b) = 1: 2+b=12 + b = 1, b=−1b = -1. The plane is x=1x = 1, halfway between the points, and the margin from each point is 1/∥w∥=11/\lVert w\rVert = 1.

    Economics: budgets and shadow prices. A consumer with income mm buys xx and yy at prices px,pyp_x, p_y to maximise U=x0.4y0.6U = x^{0.4}y^{0.6} subject to pxx+pyy=mp_xx + p_yy = m. Lagrange gives Ux=λpxU_x = \lambda p_x and Uy=λpyU_y = \lambda p_y, so the marginal rate of substitution Ux/UyU_x/U_y equals the price ratio px/pyp_x/p_y, and x=0.4mpxx = \frac{0.4m}{p_x}, y=0.6mpyy = \frac{0.6m}{p_y}. With m=100m = 100, px=2p_x = 2, py=5p_y = 5: x=20x = 20, y=12y = 12, U=200.4120.6=14.72U = 20^{0.4}12^{0.6} = 14.72, and λ=Ux/px=0.1472=U/m\lambda = U_x/p_x = 0.1472 = U/m. By the price theorem, λ\lambda is the utility gained per extra unit of money: raising mm from 100100 to 101101 raises the best utility by 0.1470.147 (here UU is homogeneous of degree 11, so the best utility is exactly 0.1472 m0.1472\,m).

    Your answerIn the maximum-entropy example with energies 0,1,20, 1, 2 and mean energy 12\frac12, what is x=e−βx = e^{-\beta}? (Give a decimal.)
    Your answerA consumer maximises U=x0.4y0.6U = x^{0.4}y^{0.6} with budget 100100 and prices px=2p_x = 2, py=5p_y = 5. What is the best amount of xx?
    Python labSolve the Lagrange system with sympy and check against brute force
    import numpy as np
    import sympy as sp
    
    x, y, z = sp.symbols('x y z', real=True)
    
    def lagrange(f, gs, vs):
        """Solve grad f = sum(l_i grad g_i) with g_i = 0. Returns (point, multipliers, f value) triples."""
        ls = sp.symbols('l1:%d' % (len(gs) + 1), real=True)
        L = f - sum(l * g for l, g in zip(ls, gs))
        eqs = [sp.diff(L, v) for v in vs] + list(gs)
        out = []
        for s in sp.solve(eqs, list(vs) + list(ls), dict=True):
            out.append(([s[v] for v in vs], [s[l] for l in ls], sp.simplify(f.subs(s))))
        return out
    
    print("A. xyz on the unit sphere")
    for p, l, val in lagrange(x*y*z, [x**2 + y**2 + z**2 - 1], [x, y, z]):
        print("  ", [sp.nsimplify(c) for c in p], " lambda =", l[0], " f =", val, "~", round(float(val), 5))
    
    print("B. x^2+y^2+z^2 on x+y+z=1 and x-y+2z=2")
    for p, l, val in lagrange(x**2 + y**2 + z**2, [x + y + z - 1, x - y + 2*z - 2], [x, y, z]):
        print("  ", p, " multipliers =", l, " f =", val)
    
    print("C. minimise x on y^2 = x^3: the recipe finds")
    print("  ", lagrange(x, [y**2 - x**3], [x, y]), " (no candidates, yet the minimum 0 is at the origin)")
    
    rng = np.random.default_rng(0)
    v = rng.normal(size=(400000, 3)); v /= np.linalg.norm(v, axis=1)[:, None]
    vals = v[:, 0] * v[:, 1] * v[:, 2]
    print("sampled max, min of xyz on the sphere:", vals.max().round(4), vals.min().round(4), "  1/(3*sqrt(3)) =", round(1/(3*3**0.5), 4))

    Try this. Run it. Problem A (xyz on the sphere) has fourteen solutions: six on the axes, where xyz = 0 and the point is a saddle of f on the sphere, and eight at the corners of a cube, where xyz is plus or minus 0.19245. The brute-force sampling agrees that these are the largest and smallest values. Problem B reports the multipliers 2/7 and 4/7. Problem C returns the empty list: the recipe finds nothing, yet the minimum 0 exists at the origin, the point where the gradient of the constraint vanishes. Change f in A to x + y + z or x**2 + 2*y**2 + 3*z**2 and see how the candidates change. Add the constraint z - x - y for a second constraint on A and read off the two multipliers.

    Traps

    Watch out· Skipping the singular points

    Points where ∇g=O\nabla g = O (or the constraint gradients are dependent) are candidates of their own and the equation ∇f=λ∇g\nabla f = \lambda\nabla g cannot find them. The cusp y2=x3y^2 = x^3 (Worksheet 3 #3) is built to catch this: Lagrange returns no solution, and the minimum is at the singular point. Apostol’s example of a plane meeting a cylinder along a line (stretch problem below) is the same trap with two constraints.

    Watch out· Dividing by something that can be zero

    From y=4λ2yy = 4\lambda^2y you may not cancel yy without first treating y=0y = 0 (Worksheet 1 #5: y=0y = 0 forces x=0x = 0, off the circle). In the disc example the equation 4y=2λy4y = 2\lambda y splits into y=0y = 0 or λ=2\lambda = 2. Lost cases are lost extrema.

    Watch out· Candidates are not answers

    One solution does not mean it is the minimum. Say why an extremum exists (the constraint set is compact, or f→∞f \to \infty along every unbounded direction) or classify with the bordered Hessian or convexity. Worksheet 1 #6 has a minimum and no maximum, because the constraint is a line.

    Watch out· The Lagrangian's critical point is a saddle, not a minimum

    For xyxy on the circle, at the maximum (22,22)\big(\frac{\sqrt2}2, \frac{\sqrt2}2\big) with λ=12\lambda = \frac12, the Hessian of L(x,y,λ)L(x, y, \lambda) in all three variables is [−11−21−1−2−2−20]\begin{bmatrix}-1 & 1 & -\sqrt2\\ 1 & -1 & -\sqrt2\\ -\sqrt2 & -\sqrt2 & 0\end{bmatrix}, with eigenvalues −2,−2,2-2, -2, 2: indefinite. The 5.6 test applied to LL in all variables is meaningless; the right matrix is the Hessian in xx restricted to the tangent space (the bordered Hessian).

    Watch out· Inequality constraints and the boundary of a region

    For a region such as a disc, find the interior critical points with ∇f=O\nabla f = O (5.6) and then treat the boundary with a multiplier; compare all values. Two constraints need independent gradients. For true inequality constraints the multipliers have a sign (KKT), which the equality case does not.

    Watch out· Sign and size of lambda

    The sign of λ\lambda depends on writing f−λgf - \lambda g or f+λgf + \lambda g. Do not read meaning from it before fixing the convention. With L=f−λ(g−c)L = f - \lambda(g - c) the price theorem says V′(c)=+λV'(c) = +\lambda.

    Problems

    check

    Write and solve the Lagrange equations for the maximum of x+2yx + 2y on x2+y2=5x^2 + y^2 = 5.

    Solution

    ∇f=(1,2)=λ(2x,2y)\nabla f = (1, 2) = \lambda(2x, 2y) gives x=12λx = \frac1{2\lambda}, y=1λ=2xy = \frac1\lambda = 2x. Then 5x2=55x^2 = 5, x=±1x = \pm1. The points are (1,2)(1, 2) with f=5f = 5 and (−1,−2)(-1, -2) with f=−5f = -5. The circle is compact, so the maximum is 55 at (1,2)(1, 2) (and the minimum is −5-5). Check: x+2y=(1,2)⋅(x,y)≤5⋅5=5x + 2y = (1, 2)\cdot(x, y) \le \sqrt5\cdot\sqrt5 = 5 by Cauchy–Schwarz.

    check

    How many unknowns and how many equations are there when you maximise f(x1,x2,x3,x4)f(x_1, x_2, x_3, x_4) on two constraints g1=c1g_1 = c_1, g2=c2g_2 = c_2?

    Solution

    Unknowns: four coordinates and two multipliers, six. Equations: four from ∇f=λ1∇g1+λ2∇g2\nabla f = \lambda_1\nabla g_1 + \lambda_2\nabla g_2 and two constraints, six. In general n+mn + m equations in n+mn + m unknowns.

    checkApostol 9.15 #1

    Find the extreme values of z=xyz = xy subject to x+y=1x + y = 1.

    Solution

    ∇(xy)=(y,x)=λ(1,1)\nabla(xy) = (y, x) = \lambda(1, 1) gives x=yx = y, and x+y=1x + y = 1 gives x=y=12x = y = \frac12, z=14z = \frac14. The constraint is a line (not compact): by substitution z=x(1−x)=14−(x−12)2z = x(1 - x) = \frac14 - \big(x - \frac12\big)^2, a downward parabola. So 14\frac14 is the maximum and there is no minimum (z→−∞z \to -\infty).

    check

    Show that replacing L=f−λgL = f - \lambda g by L′=f+λgL' = f + \lambda g changes the multiplier’s sign but not the candidate points.

    Solution

    ∇L′=O\nabla L' = O means ∇f=−λ∇g\nabla f = -\lambda\nabla g and g=cg = c. So (x,λ)(x, \lambda) solves the system for L′L' exactly when (x,−λ)(x, -\lambda) solves it for LL. The points xx are the same; only λ\lambda changes sign.

    useApostol 9.15 #5

    Find the extreme values of f(x,y,z)=x−2y+2zf(x, y, z) = x - 2y + 2z on the sphere x2+y2+z2=1x^2 + y^2 + z^2 = 1.

    Solution

    ∇f=(1,−2,2)=λ(2x,2y,2z)\nabla f = (1, -2, 2) = \lambda(2x, 2y, 2z), so (x,y,z)=(1,−2,2)2λ(x, y, z) = \frac{(1, -2, 2)}{2\lambda}. On the sphere, 1+4+44λ2=1\frac{1 + 4 + 4}{4\lambda^2} = 1, so λ=±32\lambda = \pm\frac32 and (x,y,z)=±(1,−2,2)3(x, y, z) = \pm\frac{(1, -2, 2)}3. Values: f=±1+4+43=±3f = \pm\frac{1 + 4 + 4}{3} = \pm3. The sphere is compact: maximum 33, minimum −3-3 (this is ∥(1,−2,2)∥=3\lVert(1, -2, 2)\rVert = 3, Cauchy–Schwarz).

    useApostol 9.15 #13

    Find the greatest and least distances from the ellipse x2+4y2=4x^2 + 4y^2 = 4 to the line x+y=4x + y = 4.

    Solution

    The distance from (x,y)(x, y) to the line is ∣x+y−4∣2\frac{\lvert x + y - 4\rvert}{\sqrt2}. On the ellipse x+yx + y has extremes found by (1,1)=λ(2x,8y)(1, 1) = \lambda(2x, 8y): x=12λx = \frac1{2\lambda}, y=18λy = \frac1{8\lambda}, so x=4yx = 4y; then 16y2+4y2=416y^2 + 4y^2 = 4, y=±15y = \pm\frac1{\sqrt5}, x=±45x = \pm\frac4{\sqrt5}, and x+y=±5x + y = \pm\sqrt5. Since ∣x+y∣≤5<4\lvert x + y\rvert \le \sqrt5 \lt 4, the distance is 4−(x+y)2\frac{4 - (x + y)}{\sqrt2}: greatest 4+52≈4.410\frac{4 + \sqrt5}{\sqrt2} \approx 4.410, least 4−52≈1.247\frac{4 - \sqrt5}{\sqrt2} \approx 1.247.

    useApostol 9.15 #6

    Find the points of the surface z2−xy=1z^2 - xy = 1 nearest to the origin.

    Solution

    Minimise f=x2+y2+z2f = x^2 + y^2 + z^2 on g=z2−xy=1g = z^2 - xy = 1. ∇g=(−y,−x,2z)\nabla g = (-y, -x, 2z) is zero only at the origin, which is not on the surface. Equations: 2x=−λy2x = -\lambda y, 2y=−λx2y = -\lambda x, 2z=2λz2z = 2\lambda z. If z≠0z \ne 0: λ=1\lambda = 1, then 2x=−y2x = -y and 2y=−x2y = -x give x=y=0x = y = 0, z=±1z = \pm1, f=1f = 1. If z=0z = 0: −xy=1-xy = 1 and 4xy=λ2xy4xy = \lambda^2xy so λ=±2\lambda = \pm2; λ=2\lambda = 2 gives y=−xy = -x, x2=1x^2 = 1, points ±(1,−1,0)\pm(1, -1, 0) with f=2f = 2; λ=−2\lambda = -2 gives y=xy = x and −x2=1-x^2 = 1, impossible. A minimum exists since f→∞f \to \infty on the closed surface. The nearest points are (0,0,±1)(0, 0, \pm1), distance 11.

    usenew (economics, with the price theorem)

    Maximise U=xyU = \sqrt{xy} subject to 4x+y=404x + y = 40. Find the best bundle and λ\lambda, and check λ=dV/dm\lambda = dV/dm for m=40m = 40.

    Solution

    ∇U=(y2xy, x2xy)=λ(4,1)\nabla U = \Big(\frac{y}{2\sqrt{xy}},\ \frac{x}{2\sqrt{xy}}\Big) = \lambda(4, 1), so yx=4\frac yx = 4 (ratio of the two equations: yx=41\frac{y}{x} = \frac41), y=4xy = 4x. Budget: 4x+4x=404x + 4x = 40, x=5x = 5, y=20y = 20, U=100=10U = \sqrt{100} = 10. Then λ=Uypy=x2xy=520=14\lambda = \frac{U_y}{p_y} = \frac{x}{2\sqrt{xy}} = \frac5{20} = \frac14. For general income mm: x=m8x = \frac m8, y=m2y = \frac m2, V(m)=m216=m4V(m) = \sqrt{\frac{m^2}{16}} = \frac m4, so V′(m)=14=λV'(m) = \frac14 = \lambda. ✓.

    provenew (Cauchy–Schwarz)

    Use Lagrange multipliers to show that max⁡{a⋅x:∥x∥=1}=∥a∥\max\{a\cdot x : \lVert x\rVert = 1\} = \lVert a\rVert for a≠Oa \ne O, and deduce ∣a⋅x∣≤∥a∥∥x∥\lvert a\cdot x\rvert \le \lVert a\rVert\lVert x\rVert.

    Solution

    Plan. Find the candidates, use compactness for existence, then scale.

    ∇(a⋅x)=a=λ∇(∥x∥2)=2λx\nabla(a\cdot x) = a = \lambda\nabla(\lVert x\rVert^2) = 2\lambda x, so x=a2λx = \frac{a}{2\lambda} and ∥x∥=1\lVert x\rVert = 1 gives 2∣λ∣=∥a∥2\lvert\lambda\rvert = \lVert a\rVert: the candidates are x=±a∥a∥x = \pm\frac{a}{\lVert a\rVert}, with values ±∥a∥\pm\lVert a\rVert. The unit sphere is compact, so the maximum exists; it is ∥a∥\lVert a\rVert. For a general nonzero xx apply this to x/∥x∥x/\lVert x\rVert: a⋅x∥x∥≤∥a∥a\cdot\frac x{\lVert x\rVert} \le \lVert a\rVert, and replacing xx by −x-x gives the absolute value. ■\blacksquare

    provenew (Rayleigh quotient)

    Let AA be a real symmetric matrix. Prove that max⁡{xTAx:∥x∥=1}\max\{x^{\mathsf T}Ax : \lVert x\rVert = 1\} equals the largest eigenvalue of AA.

    Solution

    Plan. Lagrange turns the maximisation into an eigenvalue equation.

    The sphere is compact and xTAxx^{\mathsf T}Ax is continuous, so the maximum is attained at some x0x_0. Every point of the sphere is regular for g=∥x∥2g = \lVert x\rVert^2 (∇g=2x≠O\nabla g = 2x \ne O). By the theorem, ∇(xTAx)=2Ax0=λ⋅2x0\nabla(x^{\mathsf T}Ax) = 2Ax_0 = \lambda\cdot2x_0 (using ∇(xTAx)=2Ax\nabla(x^{\mathsf T}Ax) = 2Ax, 3.8, for symmetric AA), so Ax0=λx0Ax_0 = \lambda x_0: x0x_0 is an eigenvector. Then x0TAx0=λ∥x0∥2=λx_0^{\mathsf T}Ax_0 = \lambda\lVert x_0\rVert^2 = \lambda, so the maximum value is an eigenvalue. Conversely for any eigenvalue μ\mu with unit eigenvector uu, uTAu=μu^{\mathsf T}Au = \mu is attained on the sphere, so the maximum is at least every eigenvalue. Hence the maximum is the largest eigenvalue. ■\blacksquare

    provenew (AM–GM)

    Prove that (abc)1/3≤a+b+c3(abc)^{1/3} \le \frac{a + b + c}3 for a,b,c≥0a, b, c \ge 0 by maximising xyzxyz on x+y+z=sx + y + z = s, x,y,z≥0x, y, z \ge 0.

    Solution

    Plan. Existence by compactness, boundary excluded because the product vanishes there, interior by Lagrange.

    Fix s>0s \gt 0. The triangle T={x+y+z=s, x,y,z≥0}T = \{x + y + z = s,\ x, y, z \ge 0\} is closed and bounded, so xyzxyz attains a maximum on TT. On the boundary of TT some coordinate is 00 and xyz=0xyz = 0, while the interior has xyz>0xyz \gt 0, so the maximum is at an interior point. There ∇(xyz)=(yz,xz,xy)=λ(1,1,1)\nabla(xyz) = (yz, xz, xy) = \lambda(1, 1, 1). Multiplying the first equation by xx and the second by yy gives xyz=λx=λyxyz = \lambda x = \lambda y, and λ=xyz/x≠0\lambda = xyz/x \ne 0, so x=yx = y; likewise y=zy = z. So x=y=z=s3x = y = z = \frac s3 and the maximum is (s3)3\big(\frac s3\big)^3. Taking s=a+b+cs = a + b + c (the case s=0s = 0 is trivial), abc≤(a+b+c3)3abc \le \big(\frac{a + b + c}{3}\big)^3. ■\blacksquare

    provenew (n = 2, m = 1, directly)

    Prove the multiplier theorem for f,gf, g of two variables, ∇g(a)≠O\nabla g(a) \ne O, without using the general implicit function proof: use a curve in the level set.

    Solution

    Plan. A regular level curve has a tangent vector; ff along it is stationary; the perpendicular line in the plane is one-dimensional.

    By the corollary of 5.7, near aa the level curve g=cg = c is the image of a C1C^1 curve r(t)r(t) with r(0)=ar(0) = a and r′(0)≠Or'(0) \ne O spanning ker⁡Dg(a)\ker Dg(a), so r′(0)⊥∇g(a)r'(0) \perp \nabla g(a). The function t↦f(r(t))t \mapsto f(r(t)) has a local extremum at the interior point t=0t = 0, so its derivative is 00: by the path theorem (5.3) ∇f(a)⋅r′(0)=0\nabla f(a)\cdot r'(0) = 0. In the plane the vectors perpendicular to the nonzero vector r′(0)r'(0) form a line, and it contains both ∇f(a)\nabla f(a) and ∇g(a)≠O\nabla g(a) \ne O. So ∇f(a)=λ∇g(a)\nabla f(a) = \lambda\nabla g(a). ■\blacksquare

    stretchApostol 9.14 (the example where the method fails)

    Minimise f(x,y,z)=x2+y2f(x, y, z) = x^2 + y^2 on the set z=0z = 0, z2=(y−1)3z^2 = (y - 1)^3. Show that the method of Lagrange multipliers applied to g1=zg_1 = z, g2=z2−(y−1)3g_2 = z^2 - (y - 1)^3 finds no candidate, and explain.

    Solution

    The constraint set: z=0z = 0 forces (y−1)3=0(y - 1)^3 = 0, so y=1y = 1: it is the line {(x,1,0)}\{(x, 1, 0)\}. On it f=x2+1f = x^2 + 1, minimal at (0,1,0)(0, 1, 0) with value 11. There ∇g1=(0,0,1)\nabla g_1 = (0, 0, 1) and ∇g2=(0,−3(y−1)2,2z)=O\nabla g_2 = (0, -3(y - 1)^2, 2z) = O: the gradients are linearly dependent, so (0,1,0)(0, 1, 0) is not a regular point. And ∇f=(0,2,0)\nabla f = (0, 2, 0) is not in the span of ∇g1,∇g2\nabla g_1, \nabla g_2, which is the zz-axis direction. So no multipliers exist. The theorem requires independent gradients; here the two surfaces (a plane and a cylinder) are tangent along the line, which is why the dependence appears.

    stretchnew (finance; links 2.10 and 5.8)

    Derive the minimum-variance portfolio w=Σ−111TΣ−11w = \dfrac{\Sigma^{-1}\mathbf 1}{\mathbf 1^{\mathsf T}\Sigma^{-1}\mathbf 1} for a positive definite covariance matrix Σ\Sigma, and compute it for two uncorrelated assets with variances 0.040.04 and 0.090.09.

    Solution

    Minimise wTΣww^{\mathsf T}\Sigma w subject to 1Tw=1\mathbf 1^{\mathsf T}w = 1. ∇=2Σw=λ1\nabla = 2\Sigma w = \lambda\mathbf 1, so w=λ2Σ−11w = \frac\lambda2\Sigma^{-1}\mathbf 1 (Σ\Sigma is invertible, being positive definite). The constraint gives λ21TΣ−11=1\frac\lambda2\mathbf 1^{\mathsf T}\Sigma^{-1}\mathbf 1 = 1, hence the formula. The objective is convex (Σ\Sigma positive definite, hence the convexity theorem above) and the constraint linear, so by the corollary this is the global minimum. For Σ=diag⁡(0.04,0.09)\Sigma = \operatorname{diag}(0.04, 0.09), Σ−11=(25,11.11)\Sigma^{-1}\mathbf 1 = (25, 11.11) and 1TΣ−11=36.11\mathbf 1^{\mathsf T}\Sigma^{-1}\mathbf 1 = 36.11, so w=(0.6923,0.3077)=(913,413)w = (0.6923, 0.3077) = \big(\frac9{13}, \frac4{13}\big), with variance 0.04⋅0.090.13=0.02769\frac{0.04\cdot0.09}{0.13} = 0.02769 (standard deviation 16.6%16.6\%, less than the 20%20\% of the safer asset alone: diversification).

    Summary

    • A constrained extremum of ff on {g=c}\{g = c\} is not a point with ∇f=O\nabla f = O. The Lagrange multiplier theorem: if aa is a regular point of the constraint (the gradients ∇gi(a)\nabla g_i(a) are independent) and f∣Sf|_S has a local extremum at aa, then ∇f(a)=∑λi∇gi(a)\nabla f(a) = \sum\lambda_i\nabla g_i(a). Picture: the level curve of ff touches the constraint, so their normals are parallel.
    • Proof: by the implicit function theorem the constraint is a graph over n−mn - m free variables, ff restricted to it has an interior extremum, so its gradient is zero, and defining λ\lambda from the solved coordinates makes the equation hold in the free coordinates too.
    • Recipe: (1) find the singular points of the constraint; (2) solve ∇f=∑λi∇gi\nabla f = \sum\lambda_i\nabla g_i and g=cg = c (n+mn + m equations); (3) list candidates; (4) compare values and justify existence (compactness, growth) or classify. Use squared distances, and never divide by a quantity that may be 00.
    • The theorem gives candidates only. Classification: compact feasible set, growth, convexity (a convex Lagrangian makes any Lagrange point a global minimum), or the second-order test: vTHvv^{\mathsf T}Hv on the tangent space with H=D2f−∑λiD2giH = D^2f - \sum\lambda_iD^2g_i; for two variables and one constraint det⁡B>0\det B \gt 0 means a maximum and det⁡B<0\det B \lt 0 a minimum.
    • The multiplier is the price of the constraint: V′(c)=λV'(c) = \lambda, where V(c)V(c) is the best value.
    • Eigenvalues are Lagrange multipliers: the extremes of xTAxx^{\mathsf T}Ax on the unit sphere are the extreme eigenvalues; σ1\sigma_1 is max⁡∥Ax∥\max\lVert Ax\rVert.
    • Real problems: maximum entropy gives the Boltzmann distribution and the softmax; the Markowitz portfolio solves a linear (bordered) system; SVM margins come from a dual problem; utility maximisation gives the budget tangency and shadow prices.
    • Failure modes: singular points (the cusp y2=x3y^2 = x^3), dependent gradients (plane and cylinder), lost cases from dividing by a variable, and treating the Lagrangian’s critical point as if it were a minimum of LL.

    Watch and read

    The same ideas explained by someone else. Use these when an explanation here does not land.

    Where this sits

    Comes from
    3.2 Quadratic forms and principal axes
    4.3 Compactness
    5.2 Directional derivatives, partial derivatives and the gradient
    5.3 The total derivative, the Jacobian matrix and tangent planes
    5.4 The chain rule for fields
    5.6 Taylor's formula, the Hessian and extrema
    5.7 Inverse and implicit functions
    Leads to
    5.10 Gradient descent, momentum and Newton's method
    Same idea elsewhere
    MATH 376: Worksheet 1 (problems 5 and 6), Worksheet 3 (problems 2 to 5) and Homework 1 problem 1 are the problems of this chapter: xy on the circle, the sum of squares on two planes, Cobb–Douglas cost, the singular point y² = x³, the proof of the theorem in space, and the distance to a hemisphere. All are worked below, with the corrections the digest records.
    MATH 375: Lagrange multipliers were not lectured. Lecture 24 handled a region by finding the interior critical points and then 'checking the boundary' edge by edge; the disc example below does the boundary both by substitution and by a multiplier, so the two methods can be compared.
    MATH 340 / CS 532: Every constrained problem in optimisation (linear programming, quadratic programming, support vector machines) is solved through its Lagrangian. The multipliers become dual variables, and for inequality constraints the conditions of Karush, Kuhn and Tucker replace the equation of this chapter.
    MATH 521: 521 proves the multiplier rule on a manifold: at a constrained extremum the derivative of f vanishes on the tangent space of the constraint set.
    Economics, physics, statistics: Utility maximisation under a budget, the Boltzmann distribution (maximum entropy under an energy constraint), and the mean-variance portfolio of Markowitz are all Lagrange problems; the multiplier is a price, a temperature, and a risk premium respectively.