Practice / Calculus

Lagrange multipliers

Ten problems on optimising under constraints with Lagrange multipliers: why ∇f = λ∇g, extrema on a line and on a circle, an open box of least area, the closest point on a plane, xᵀAx on the unit sphere, the maximum-entropy and Gibbs distributions, the minimum-norm solution of Ax = b, λ as the sensitivity of the optimum and KKT with active and inactive constraints, with worked solutions and the mistakes that cancel a variable or drop a candidate.

Before you start

When a point must stay on a curve or a surface, setting the gradient to zero is replaced by ∇f=λ∇g\nabla f = \lambda\nabla g: the gradient of the objective lines up with the gradient of the constraint. These ten problems derive that condition, use it on a line, a circle, a box and a plane, then draw from it three results machine learning leans on — eigenvalues as the extremes of a quadratic form, the softmax as a maximum-entropy distribution and the minimum-norm solution of Ax=bAx = b — and end with what λ\lambda measures and with inequality constraints. The five mistakes each lose a candidate or misread the multiplier.

  • ff and gg are functions of x∈Rnx \in \mathbb{R}^n (in the plane, of (x,y)(x, y)) with continuous partial derivatives; ∇f\nabla f is the column of partial derivatives, as on the partial-derivatives page. The constraint is g(x)=cg(x) = c. At a point of g=cg = c where ff, restricted to the constraint, has a local maximum or minimum and ∇g≠0\nabla g \neq 0, there is a number λ\lambda, the Lagrange multiplier, with ∇f=λ∇g\nabla f = \lambda\nabla g. The points satisfying this together with g=cg = c are the candidates.
  • The same equations come from setting every partial derivative of the Lagrangian L(x,λ)=f(x)−λ(g(x)−c)L(x, \lambda) = f(x) - \lambda\big(g(x) - c\big) to 00; ∂L/∂λ=0\partial L/\partial\lambda = 0 is the constraint. Writing f+λ(g−c)f + \lambda(g - c) instead negates λ\lambda; this page never does.
  • With several constraints g1=c1,…,gm=cmg_1 = c_1, \dots, g_m = c_m there is one multiplier for each: ∇f=λ1∇g1+⋯+λm∇gm\nabla f = \lambda_1\nabla g_1 + \cdots + \lambda_m\nabla g_m.
  • Choosing among candidates: on a closed and bounded constraint set, such as a circle or a sphere, ff attains a maximum and a minimum, both are candidates, and comparing the values of ff picks them out. On an unbounded set, such as a line or a plane, a candidate can be a maximum, a minimum or neither, and needs a separate argument.
  • Inequality constraints (Problem 10): to minimise ff subject to h(x)≤0h(x) \le 0, the Karush–Kuhn–Tucker (KKT) conditions are ∇f+μ∇h=0\nabla f + \mu\nabla h = 0, μ≥0\mu \ge 0, h≤0h \le 0 and μh=0\mu h = 0. The last says either μ=0\mu = 0 (the constraint is inactive, and the point is an ordinary stationary point) or h=0h = 0 (it is active, and the point is on the boundary).
  • log⁡\log is the natural log; the entropy of a distribution pp on nn outcomes is H(p)=−∑ipilog⁡piH(p) = -\sum_i p_i\log p_i.

Builds on: Partial derivatives, gradients and Hessians

Problems

  1. ·

    Explain why, at a point x∗x^* of the curve g(x,y)=cg(x, y) = c where ff restricted to the curve has a local maximum or minimum and ∇g(x∗)≠0\nabla g(x^*) \neq 0, the gradients satisfy ∇f(x∗)=λ∇g(x∗)\nabla f(x^*) = \lambda\nabla g(x^*) for some number λ\lambda.

  2. ·

    Find the maximum of f(x,y)=xyf(x, y) = xy on the line x+2y=8x + 2y = 8, and the multiplier. Is there a minimum?

  3. ··

    Find the maximum and minimum of f(x,y)=x2+yf(x, y) = x^2 + y on the unit circle x2+y2=1x^2 + y^2 = 1. List every candidate.

  4. ··

    An open-top box with a rectangular base xx by yy and height zz must hold volume xyz=32xyz = 32. Find the dimensions that minimise the area of base and sides, S=xy+2xz+2yzS = xy + 2xz + 2yz.

  5. ··

    Find the point of the plane x1+2x2+2x3=14x_1 + 2x_2 + 2x_3 = 14 closest to p=(1,1,1)⊤p = (1, 1, 1)^\top, and its distance from pp.

  6. ··

    For a symmetric matrix AA, show that the largest value of x⊤Axx^\top Ax over unit vectors xx is the largest eigenvalue λmax⁡(A)\lambda_{\max}(A). Find the maximum and minimum for A=[2112]A = \begin{bmatrix}2&1\\1&2\end{bmatrix}.

  7. ···

    Find the distribution pp on nn outcomes with the largest entropy when the only constraint is ∑ipi=1\sum_i p_i = 1. Then give the outcomes values x1,…,xnx_1, \dots, x_n and also fix the mean, ∑ipixi=μ\sum_i p_ix_i = \mu: show the maximiser has the form pi=e−βxi/∑je−βxjp_i = e^{-\beta x_i}/\sum_j e^{-\beta x_j}, and find β\beta and pp for x=(0,1,2)x = (0, 1, 2) and μ=47\mu = \tfrac47.

  8. ···

    AA is m×nm\times n with m<nm < n and independent rows, so Ax=bAx = b has infinitely many solutions. Find the one of smallest norm by minimising 12∥x∥2\tfrac12\|x\|^2 subject to Ax=bAx = b, and compute it for A=[101011]A = \begin{bmatrix}1&0&1\\0&1&1\end{bmatrix} and b=(1,1)⊤b = (1, 1)^\top.

  9. ···

    Replace the constraint of Problem 2 by x+2y=cx + 2y = c with c>0c > 0. Find the maximum f∗(c)f^*(c) and the multiplier λ(c)\lambda(c), and show df∗dc=λ\dfrac{df^*}{dc} = \lambda. Then show the same for any ff and gg whose optimum x∗(c)x^*(c) moves differentiably with cc.

  10. ···

    Minimise f(x,y)=(x−2)2+(y−1)2f(x, y) = (x - 2)^2 + (y - 1)^2 subject to (a) x+y≤2x + y \le 2, and (b) x+y≤4x + y \le 4. In each case say whether the constraint is active.

Worked solutions

Problem 1

Explain why, at a point x∗x^* of the curve g(x,y)=cg(x, y) = c where ff restricted to the curve has a local maximum or minimum and ∇g(x∗)≠0\nabla g(x^*) \neq 0, the gradients satisfy ∇f(x∗)=λ∇g(x∗)\nabla f(x^*) = \lambda\nabla g(x^*) for some number λ\lambda.

  1. Near x∗x^* the curve is traced by a path r(t)r(t) with r(0)=x∗r(0) = x^* and a nonzero velocity r′(0)r'(0), which is tangent to the curve.∇g(x∗)≠0\nabla g(x^*) \neq 0 guarantees this: the implicit function theorem then solves g=cg = c for one coordinate in terms of the other near x∗x^*, so the curve is a smooth graph there.
  2. g(r(t))=cg(r(t)) = c for every small tt, so ∇g(x∗)⊤r′(0)=0\nabla g(x^*)^\top r'(0) = 0.The path stays on the curve, so gg is constant along it; differentiate with the chain rule, ddtg(r(t))=∇g(r(t))⊤r′(t)\tfrac{d}{dt}g(r(t)) = \nabla g(r(t))^\top r'(t), at t=0t = 0.
  3. t↦f(r(t))t \mapsto f(r(t)) has a local maximum or minimum at t=0t = 0, so ∇f(x∗)⊤r′(0)=0\nabla f(x^*)^\top r'(0) = 0.A differentiable function of one variable has derivative 00 at an interior local extremum; the same chain rule gives the derivative.
  4. In the plane, the vectors orthogonal to the nonzero vector r′(0)r'(0) form a line through the origin, and ∇g(x∗)≠0\nabla g(x^*) \neq 0 spans it.A line through the origin is spanned by any nonzero vector on it, and step 2 puts ∇g(x∗)\nabla g(x^*) on it.
  5. ∇f(x∗)=λ∇g(x∗)\nabla f(x^*) = \lambda\nabla g(x^*) for some number λ\lambda: both gradients are orthogonal to the tangent r′(0)r'(0), and in the plane those vectors form a single lineStep 3 puts ∇f(x∗)\nabla f(x^*) on the same line as ∇g(x∗)\nabla g(x^*), so it is a multiple of it. Geometrically, the level curve of ff through x∗x^* touches the constraint curve there: if ∇f\nabla f had a component along the tangent, moving along the curve in that direction would increase ff. In Rn\mathbb{R}^n the same argument runs over every tangent direction of the surface g=cg = c.

Problem 2

Find the maximum of f(x,y)=xyf(x, y) = xy on the line x+2y=8x + 2y = 8, and the multiplier. Is there a minimum?

  1. ∇f=(y,x)⊤\nabla f = (y, x)^\top and ∇g=(1,2)⊤\nabla g = (1, 2)^\top for g(x,y)=x+2yg(x, y) = x + 2y.∂(xy)/∂x=y\partial(xy)/\partial x = y and ∂(xy)/∂y=x\partial(xy)/\partial y = x; gg is linear, so its partial derivatives are its coefficients.
  2. y=λy = \lambda and x=2λx = 2\lambda.∇f=λ∇g\nabla f = \lambda\nabla g, one equation per component.
  3. 2λ+2⋅λ=82\lambda + 2\cdot\lambda = 8, so λ=2\lambda = 2 and (x,y)=(4,2)(x, y) = (4, 2), with f=8f = 8.Substitute step 2 into the constraint x+2y=8x + 2y = 8: the third equation, which fixes λ\lambda.
  4. Along the line x=8−2yx = 8 - 2y, so f=(8−2y)y=8−2(y−2)2f = (8 - 2y)y = 8 - 2(y - 2)^2.Parametrise the constraint by yy, then complete the square: 8y−2y2=8−2(y2−4y+4)8y - 2y^2 = 8 - 2(y^2 - 4y + 4).
  5. maximum f=8f = 8 at (4,2)(4, 2), with λ=2\lambda = 2; there is no minimumStep 4 is a downward parabola in yy: it peaks at y=2y = 2 with value 88 and goes to −∞-\infty as ∣y∣\lvert y\rvert grows. The line is unbounded, so the single candidate needed this separate argument. At (4,2)(4, 2), ∇f=(2,4)⊤=2 (1,2)⊤\nabla f = (2, 4)^\top = 2\,(1, 2)^\top.

Problem 3

Find the maximum and minimum of f(x,y)=x2+yf(x, y) = x^2 + y on the unit circle x2+y2=1x^2 + y^2 = 1. List every candidate.

  1. ∇f=(2x,1)⊤\nabla f = (2x, 1)^\top and ∇g=(2x,2y)⊤\nabla g = (2x, 2y)^\top for g(x,y)=x2+y2g(x, y) = x^2 + y^2.Partial derivatives term by term.
  2. 2x=2λx2x = 2\lambda x, 1=2λy1 = 2\lambda y and x2+y2=1x^2 + y^2 = 1.∇f=λ∇g\nabla f = \lambda\nabla g by components, and the constraint.
  3. 2x(1−λ)=02x(1 - \lambda) = 0, so x=0x = 0 or λ=1\lambda = 1.Move everything to one side and factor rather than divide by xx, which may be 00. A product is 00 when either factor is, so both cases must be followed.
  4. Case x=0x = 0: y2=1y^2 = 1, so y=1y = 1 or y=−1y = -1, with λ=12\lambda = \tfrac12 or −12-\tfrac12.The constraint, then λ=1/(2y)\lambda = 1/(2y) from the second equation. y2=1y^2 = 1 has two roots and both are candidates.
  5. Case λ=1\lambda = 1: 1=2y1 = 2y gives y=12y = \tfrac12, and then x2=34x^2 = \tfrac34, so x=±32x = \pm\tfrac{\sqrt3}2.The second equation, then the constraint.
  6. f(0,1)=1f(0, 1) = 1, f(0,−1)=−1f(0, -1) = -1 and f(±32,12)=34+12=54f(\pm\tfrac{\sqrt3}2, \tfrac12) = \tfrac34 + \tfrac12 = \tfrac54.Evaluate ff at all four candidates.
  7. maximum 54\tfrac54 at (±32,12)(\pm\tfrac{\sqrt3}2, \tfrac12); minimum −1-1 at (0,−1)(0, -1); the candidate (0,1)(0, 1), with f=1f = 1, is neitherThe circle is closed and bounded, so the maximum and minimum exist and are among the four candidates; comparing values picks them. Near (0,1)(0, 1) the circle is y≈1−x22y \approx 1 - \tfrac{x^2}2, so f≈1+x22f \approx 1 + \tfrac{x^2}2: that candidate is only a local minimum along the circle.

Problem 4

An open-top box with a rectangular base xx by yy and height zz must hold volume xyz=32xyz = 32. Find the dimensions that minimise the area of base and sides, S=xy+2xz+2yzS = xy + 2xz + 2yz.

  1. ∇S=(y+2z, x+2z, 2x+2y)⊤\nabla S = (y + 2z,\ x + 2z,\ 2x + 2y)^\top and ∇g=(yz, xz, xy)⊤\nabla g = (yz,\ xz,\ xy)^\top for g=xyzg = xyz.Partial derivatives, holding the other two variables fixed.
  2. y+2z=λyzy + 2z = \lambda yz, x+2z=λxzx + 2z = \lambda xz and 2x+2y=λxy2x + 2y = \lambda xy.∇S=λ∇g\nabla S = \lambda\nabla g by components.
  3. xy+2xz=λxyzxy + 2xz = \lambda xyz, xy+2yz=λxyzxy + 2yz = \lambda xyz and 2xz+2yz=λxyz2xz + 2yz = \lambda xyz.Multiply the three equations by xx, yy and zz: every right side becomes λxyz\lambda xyz, and nothing has been divided.
  4. 2xz=2yz2xz = 2yz, so x=yx = y.Subtract the second equation from the first. xyz=32xyz = 32 makes every dimension nonzero, so dividing by 2z2z is safe.
  5. xy=2yzxy = 2yz, so x=2zx = 2z.Subtract the third equation from the first, then divide by y≠0y \neq 0.
  6. xyz=2z⋅2z⋅z=4z3=32xyz = 2z\cdot2z\cdot z = 4z^3 = 32, so z=2z = 2 and x=y=4x = y = 4.Substitute steps 4 and 5 into the constraint.
  7. λ=y+2zyz=88=1\lambda = \dfrac{y + 2z}{yz} = \dfrac{8}{8} = 1.The first equation of step 2; Problem 9 uses this value.
  8. x=y=4x = y = 4, z=2z = 2; least area 4848S=16+16+16S = 16 + 16 + 16. It is the minimum: with z=32/(xy)z = 32/(xy) the area is xy+64/y+64/xxy + 64/y + 64/x, which grows without bound as xx or yy goes to 00 or to ∞\infty, so a minimum exists inside and must be a candidate, and this is the only one. The base is square and the height is half its side.

Problem 5

Find the point of the plane x1+2x2+2x3=14x_1 + 2x_2 + 2x_3 = 14 closest to p=(1,1,1)⊤p = (1, 1, 1)^\top, and its distance from pp.

Write the plane as a⊤x=14a^\top x = 14 with a=(1,2,2)⊤a = (1, 2, 2)^\top.

  1. Minimise ∥x−p∥2\|x - p\|^2 subject to a⊤x=14a^\top x = 14.Squaring is increasing on nonnegative numbers, so the square has the same minimiser as the distance and no square root to differentiate.
  2. ∇∥x−p∥2=2(x−p)\nabla\|x - p\|^2 = 2(x - p) and ∇(a⊤x)=a\nabla(a^\top x) = a.∥x−p∥2=∑i(xi−pi)2\|x - p\|^2 = \sum_i(x_i - p_i)^2 differentiates term by term; a⊤xa^\top x is linear.
  3. 2(x−p)=λa2(x - p) = \lambda a, so x=p+λ2ax = p + \tfrac\lambda2a.Stationarity: the closest point is reached from pp by moving along the normal aa of the plane.
  4. a⊤x=a⊤p+λ2a⊤a=5+92λ=14a^\top x = a^\top p + \tfrac\lambda2a^\top a = 5 + \tfrac92\lambda = 14, so λ=2\lambda = 2.Substitute into the constraint; a⊤p=1+2+2a^\top p = 1 + 2 + 2 and a⊤a=1+4+4a^\top a = 1 + 4 + 4.
  5. x∗=(1,1,1)⊤+(1,2,2)⊤=(2,3,3)⊤x^* = (1, 1, 1)^\top + (1, 2, 2)^\top = (2, 3, 3)^\top, and ∥x∗−p∥=∥a∥=3\|x^* - p\| = \|a\| = 3.λ2=1\tfrac\lambda2 = 1, so x∗−p=ax^* - p = a; check a⊤x∗=2+6+6=14a^\top x^* = 2 + 6 + 6 = 14.
  6. closest point (2,3,3)⊤(2, 3, 3)^\top; distance 33It is the minimum: any other point of the plane is x∗+zx^* + z with a⊤z=0a^\top z = 0, and z⊥a=x∗−pz \perp a = x^* - p gives ∥x∗+z−p∥2=9+∥z∥2\|x^* + z - p\|^2 = 9 + \|z\|^2. In general step 4 gives distance ∣d−a⊤p∣/∥a∥\lvert d - a^\top p\rvert/\|a\| for the plane a⊤x=da^\top x = d, here 9/39/3.

Problem 6

For a symmetric matrix AA, show that the largest value of x⊤Axx^\top Ax over unit vectors xx is the largest eigenvalue λmax⁡(A)\lambda_{\max}(A). Find the maximum and minimum for A=[2112]A = \begin{bmatrix}2&1\\1&2\end{bmatrix}.

  1. f(x)=x⊤Axf(x) = x^\top Ax and g(x)=x⊤xg(x) = x^\top x with c=1c = 1; ∇f=2Ax\nabla f = 2Ax and ∇g=2x\nabla g = 2x.The gradient of x⊤Axx^\top Ax is (A+A⊤)x(A + A^\top)x, which is 2Ax2Ax for symmetric AA; x⊤xx^\top x is the case A=IA = I.
  2. 2Ax=λ⋅2x2Ax = \lambda\cdot2x, that is Ax=λxAx = \lambda x.Stationarity: the candidates are the unit eigenvectors of AA, and the multiplier is the eigenvalue.
  3. At a candidate, f=x⊤Ax=λ x⊤x=λf = x^\top Ax = \lambda\,x^\top x = \lambda.Substitute Ax=λxAx = \lambda x, then the constraint x⊤x=1x^\top x = 1.
  4. The unit sphere is closed and bounded, so the maximum exists and is a candidate; the largest candidate value is λmax⁡(A)\lambda_{\max}(A).By step 3 the candidate values are exactly the eigenvalues; likewise the minimum is the smallest eigenvalue.
  5. For the given AA: det⁡(A−λI)=(2−λ)2−1=0\det(A - \lambda I) = (2 - \lambda)^2 - 1 = 0, so λ=3\lambda = 3 or 11, with eigenvectors (1,1)⊤(1, 1)^\top and (1,−1)⊤(1, -1)^\top.2−λ=±12 - \lambda = \pm1; then A(1,1)⊤=(3,3)⊤A(1,1)^\top = (3,3)^\top and A(1,−1)⊤=(1,−1)⊤A(1,-1)^\top = (1,-1)^\top.
  6. max⁡∥x∥=1x⊤Ax=λmax⁡(A)\max_{\|x\|=1}x^\top Ax = \lambda_{\max}(A), attained at a unit eigenvector; here the maximum is 33 at ±12(1,1)⊤\pm\tfrac1{\sqrt2}(1,1)^\top and the minimum 11 at ±12(1,−1)⊤\pm\tfrac1{\sqrt2}(1,-1)^\topCheck: x=12(1,1)⊤x = \tfrac1{\sqrt2}(1,1)^\top gives x⊤Ax=12(2+1+1+2)=3x^\top Ax = \tfrac12(2 + 1 + 1 + 2) = 3. This is why the first principal component, the direction of largest variance x⊤Σxx^\top\Sigma x, is the top eigenvector of the covariance matrix.

Problem 7

Find the distribution pp on nn outcomes with the largest entropy when the only constraint is ∑ipi=1\sum_i p_i = 1. Then give the outcomes values x1,…,xnx_1, \dots, x_n and also fix the mean, ∑ipixi=μ\sum_i p_ix_i = \mu: show the maximiser has the form pi=e−βxi/∑je−βxjp_i = e^{-\beta x_i}/\sum_j e^{-\beta x_j}, and find β\beta and pp for x=(0,1,2)x = (0, 1, 2) and μ=47\mu = \tfrac47.

Every pip_i is taken positive. The derivative of −tlog⁡t-t\log t tends to +∞+\infty as t→0+t \to 0^+, so moving a little probability onto an empty outcome always raises HH, and the maximum is not on the boundary.

  1. ∂H∂pi=−log⁡pi−1\dfrac{\partial H}{\partial p_i} = -\log p_i - 1.Product rule on −pilog⁡pi-p_i\log p_i; no other term of HH contains pip_i.
  2. Normalisation only: −log⁡pi−1=λ-\log p_i - 1 = \lambda for every ii.∇H=λ∇g\nabla H = \lambda\nabla g with g=∑ipig = \sum_ip_i, whose gradient is the all-ones vector.
  3. pi=e−1−λp_i = e^{-1-\lambda}, the same for every ii, so pi=1np_i = \tfrac1n and H=−∑i1nlog⁡1n=log⁡nH = -\sum_i\tfrac1n\log\tfrac1n = \log n.Solve step 2 for pip_i; then ∑ipi=1\sum_ip_i = 1 fixes the common value.
  4. This is the maximum.−tlog⁡t-t\log t has second derivative −1/t<0-1/t < 0, so HH is concave, and on a constraint set cut out by linear equations a stationary point of a concave function is its maximum. The entropy page proved the same bound with the KL divergence.
  5. With the mean: −log⁡pi−1=λ+βxi-\log p_i - 1 = \lambda + \beta x_i.Two constraints, two multipliers: ∇H=λ∇(∑ipi)+β∇(∑ipixi)\nabla H = \lambda\nabla(\sum_ip_i) + \beta\nabla(\sum_ip_ix_i), and the second gradient is the vector of values xix_i.
  6. pi=e−1−λe−βxip_i = e^{-1-\lambda}e^{-\beta x_i}, and ∑ipi=1\sum_ip_i = 1 gives e−1−λ=1/∑je−βxje^{-1-\lambda} = 1/\sum_je^{-\beta x_j}.Exponentiate step 5; the factor e−1−λe^{-1-\lambda} is the same for every ii, so normalisation determines it.
  7. For x=(0,1,2)x = (0, 1, 2) write r=e−βr = e^{-\beta}: p=(1,r,r2)1+r+r2p = \dfrac{(1, r, r^2)}{1 + r + r^2}, with mean r+2r21+r+r2=47\dfrac{r + 2r^2}{1 + r + r^2} = \dfrac47.e−βxi=rxie^{-\beta x_i} = r^{x_i}, and the mean is ∑ipixi\sum_ip_ix_i; the remaining constraint fixes β\beta.
  8. 7r+14r2=4+4r+4r27r + 14r^2 = 4 + 4r + 4r^2, so 10r2+3r−4=(2r−1)(5r+4)=010r^2 + 3r - 4 = (2r - 1)(5r + 4) = 0, and r=12r = \tfrac12.Cross-multiply and collect terms; r=e−β>0r = e^{-\beta} > 0 rules out −45-\tfrac45.
  9. β=log⁡2\beta = \log 2 and p=(1,12,14)7/4=(47,27,17)p = \dfrac{(1, \tfrac12, \tfrac14)}{7/4} = (\tfrac47, \tfrac27, \tfrac17).e−β=12e^{-\beta} = \tfrac12; 1+12+14=741 + \tfrac12 + \tfrac14 = \tfrac74. Check: mean 27+27=47\tfrac27 + \tfrac27 = \tfrac47.
  10. Normalisation only: pi=1np_i = \tfrac1n, H=log⁡nH = \log n. With the mean: pi=e−βxi∑je−βxjp_i = \dfrac{e^{-\beta x_i}}{\sum_je^{-\beta x_j}}, and for x=(0,1,2)x = (0,1,2), μ=47\mu = \tfrac47: β=log⁡2\beta = \log 2, p=(47,27,17)p = (\tfrac47, \tfrac27, \tfrac17)The second form is the softmax of −βx-\beta x, the Gibbs distribution; β=0\beta = 0 gives back the uniform distribution, whose mean here is 11. A mean below 11 needs β>0\beta > 0, which tilts the probability toward small xix_i. The concavity argument of step 4 again makes it the maximum.

Problem 8

AA is m×nm\times n with m<nm < n and independent rows, so Ax=bAx = b has infinitely many solutions. Find the one of smallest norm by minimising 12∥x∥2\tfrac12\|x\|^2 subject to Ax=bAx = b, and compute it for A=[101011]A = \begin{bmatrix}1&0&1\\0&1&1\end{bmatrix} and b=(1,1)⊤b = (1, 1)^\top.

  1. The constraints are ai⊤x=bia_i^\top x = b_i for i=1,…,mi = 1, \dots, m, where ai⊤a_i^\top is row ii of AA; give them multipliers ν1,…,νm\nu_1, \dots, \nu_m, collected in ν∈Rm\nu \in \mathbb{R}^m.One multiplier per constraint; ν\nu avoids a clash with the eigenvalue λ\lambda of Problem 6.
  2. x=∑iνiai=A⊤νx = \sum_i\nu_ia_i = A^\top\nu.Stationarity: ∇12∥x∥2=x\nabla\tfrac12\|x\|^2 = x and ∇(ai⊤x)=ai\nabla(a_i^\top x) = a_i. The columns of A⊤A^\top are the aia_i, so the sum is A⊤νA^\top\nu.
  3. AA⊤ν=bAA^\top\nu = b, so ν=(AA⊤)−1b\nu = (AA^\top)^{-1}b.Substitute into Ax=bAx = b. AA⊤AA^\top is m×mm\times m and invertible because the rows of AA are independent.
  4. x∗=A⊤(AA⊤)−1bx^* = A^\top(AA^\top)^{-1}b.Substitute ν\nu back into step 2.
  5. Any other solution is x∗+zx^* + z with Az=0Az = 0, and ∥x∗+z∥2=∥x∗∥2+2ν⊤Az+∥z∥2=∥x∗∥2+∥z∥2\|x^* + z\|^2 = \|x^*\|^2 + 2\nu^\top Az + \|z\|^2 = \|x^*\|^2 + \|z\|^2.x∗⊤z=ν⊤Az=0x^{*\top}z = \nu^\top Az = 0, so the cross term vanishes; every other solution is longer, and x∗x^* is the minimum.
  6. For the given AA: AA⊤=[2112]AA^\top = \begin{bmatrix}2&1\\1&2\end{bmatrix}, (AA⊤)−1=13[2−1−12](AA^\top)^{-1} = \tfrac13\begin{bmatrix}2&-1\\-1&2\end{bmatrix}, and ν=13(1,1)⊤\nu = \tfrac13(1, 1)^\top.Entry (i,j)(i, j) of AA⊤AA^\top is row ii dotted with row jj; the determinant is 33, and the 2×22\times2 inverse swaps the diagonal and negates the off-diagonal.
  7. x∗=A⊤ν=13(1,0,1)⊤+13(0,1,1)⊤=13(1,1,2)⊤x^* = A^\top\nu = \tfrac13(1, 0, 1)^\top + \tfrac13(0, 1, 1)^\top = \tfrac13(1, 1, 2)^\top.A⊤νA^\top\nu is ν1\nu_1 times the first row of AA plus ν2\nu_2 times the second. Check: Ax∗=13(1+2, 1+2)⊤=(1,1)⊤Ax^* = \tfrac13(1 + 2,\ 1 + 2)^\top = (1, 1)^\top.
  8. x∗=A⊤(AA⊤)−1bx^* = A^\top(AA^\top)^{-1}b; for this AA and bb, x∗=(13,13,23)⊤x^* = (\tfrac13, \tfrac13, \tfrac23)^\topx∗x^* lies in the row space of AA, orthogonal to the null space: here (13,13,23)⋅(1,1,−1)=0(\tfrac13, \tfrac13, \tfrac23)\cdot(1, 1, -1) = 0. It is the pseudoinverse solution A+bA^+b of the least-squares page, the wide-matrix counterpart of (A⊤A)−1A⊤b(A^\top A)^{-1}A^\top b.

Problem 9

Replace the constraint of Problem 2 by x+2y=cx + 2y = c with c>0c > 0. Find the maximum f∗(c)f^*(c) and the multiplier λ(c)\lambda(c), and show df∗dc=λ\dfrac{df^*}{dc} = \lambda. Then show the same for any ff and gg whose optimum x∗(c)x^*(c) moves differentiably with cc.

  1. y=λy = \lambda, x=2λx = 2\lambda and 4λ=c4\lambda = c, so λ(c)=c4\lambda(c) = \tfrac c4 and (x,y)=(c2,c4)(x, y) = (\tfrac c2, \tfrac c4).Problem 2's equations with 88 replaced by cc.
  2. f∗(c)=c2⋅c4=c28f^*(c) = \tfrac c2\cdot\tfrac c4 = \tfrac{c^2}8, so df∗dc=c4=λ(c)\dfrac{df^*}{dc} = \tfrac c4 = \lambda(c).Differentiate in cc; at c=8c = 8 both are 22, as in Problem 2.
  3. In general f∗(c)=f(x∗(c))f^*(c) = f(x^*(c)), so df∗dc=∇f(x∗)⊤dx∗dc\dfrac{df^*}{dc} = \nabla f(x^*)^\top\dfrac{dx^*}{dc}.Chain rule through the path the optimum traces as cc changes.
  4. ∇f(x∗)⊤dx∗dc=λ ∇g(x∗)⊤dx∗dc\nabla f(x^*)^\top\dfrac{dx^*}{dc} = \lambda\,\nabla g(x^*)^\top\dfrac{dx^*}{dc}.Stationarity at the optimum, ∇f=λ∇g\nabla f = \lambda\nabla g.
  5. g(x∗(c))=cg(x^*(c)) = c for every cc, so ∇g(x∗)⊤dx∗dc=1\nabla g(x^*)^\top\dfrac{dx^*}{dc} = 1.Differentiate the constraint, which holds identically in cc, with the same chain rule.
  6. f∗(c)=c28f^*(c) = \tfrac{c^2}8 and λ(c)=c4\lambda(c) = \tfrac c4, so df∗dc=c4=λ\dfrac{df^*}{dc} = \tfrac c4 = \lambda; in general df∗dc=∇f⊤dx∗dc=λ ∇g⊤dx∗dc=λ\dfrac{df^*}{dc} = \nabla f^\top\dfrac{dx^*}{dc} = \lambda\,\nabla g^\top\dfrac{dx^*}{dc} = \lambdaλ\lambda is the price of the constraint: raising cc from 88 to 99 raises the maximum by about 22 (exactly 818−8=178\tfrac{81}8 - 8 = \tfrac{17}8). For the box of Problem 4, λ=1\lambda = 1: the least area for volume VV is S∗(V)=3(2V)2/3S^*(V) = 3(2V)^{2/3}, whose derivative at V=32V = 32 is 11, so one more unit of volume costs about one more unit of area.

Problem 10

Minimise f(x,y)=(x−2)2+(y−1)2f(x, y) = (x - 2)^2 + (y - 1)^2 subject to (a) x+y≤2x + y \le 2, and (b) x+y≤4x + y \le 4. In each case say whether the constraint is active.

  1. h(x,y)=x+y−c≤0h(x, y) = x + y - c \le 0 with c=2c = 2 or 44; ∇f=(2(x−2), 2(y−1))⊤\nabla f = \big(2(x - 2),\ 2(y - 1)\big)^\top and ∇h=(1,1)⊤\nabla h = (1, 1)^\top.The KKT conditions of Before you start need the constraint in the form h≤0h \le 0.
  2. 2(x−2)+μ=02(x - 2) + \mu = 0 and 2(y−1)+μ=02(y - 1) + \mu = 0, so x=2−μ2x = 2 - \tfrac\mu2 and y=1−μ2y = 1 - \tfrac\mu2.Stationarity, ∇f+μ∇h=0\nabla f + \mu\nabla h = 0, by components.
  3. Inactive case, μ=0\mu = 0: (x,y)=(2,1)(x, y) = (2, 1), where x+y=3x + y = 3.Complementary slackness allows μ=0\mu = 0; then the point is the unconstrained minimum of ff.
  4. (a) 3>23 > 2, so (2,1)(2, 1) is infeasible and the constraint must be active: x+y=3−μ=2x + y = 3 - \mu = 2 gives μ=1\mu = 1, the point (32,12)(\tfrac32, \tfrac12) and f=14+14=12f = \tfrac14 + \tfrac14 = \tfrac12.With the inactive case ruled out, μh=0\mu h = 0 forces h=0h = 0; and μ=1≥0\mu = 1 \ge 0, so all four conditions hold.
  5. (b) 3≤43 \le 4, so (2,1)(2, 1) is feasible, μ=0\mu = 0 satisfies all four conditions, and f=0f = 0.f≥0f \ge 0 everywhere, so 00 cannot be beaten.
  6. (a) active: (32,12)(\tfrac32, \tfrac12), μ=1\mu = 1, f=12f = \tfrac12; (b) inactive: (2,1)(2, 1), μ=0\mu = 0, f=0f = 0ff is convex and the constraint linear, so a KKT point is the minimum. μ\mu is a sensitivity, as in Problem 9: in (a) the minimum is f∗(c)=(3−c)22f^*(c) = \tfrac{(3 - c)^2}2 for c<3c < 3, with df∗dc=−1=−μ\tfrac{df^*}{dc} = -1 = -\mu at c=2c = 2, so loosening the constraint lowers the minimum at rate μ\mu; in (b) loosening it changes nothing, and μ=0\mu = 0.

Where this goes wrong

1. Taking only the positive root of y² = 1

1=1\sqrt1 = 1 is the habit, and y2=1y^2 = 1 gets solved as if it were y=1y = \sqrt1.

  1. In Problem 3 the case x=0x = 0 leaves the constraint y2=1y^2 = 1Right so far: this is the branch from 2x(1−λ)=02x(1 - \lambda) = 0.
  2. “Take the square root.”The shortcut that causes the mistake: the square-root sign names one root, and the equation has two.
  3. y=1y = 1, so the candidates are (±32,12)(\pm\tfrac{\sqrt3}2, \tfrac12) with f=54f = \tfrac54 and (0,1)(0, 1) with f=1f = 1, and the minimum is 11y2=1y^2 = 1 also has y=−1y = -1, and (0,−1)(0, -1) gives f=−1f = -1, the true minimum. Comparing values finds the maximum and minimum only among the candidates actually listed, so a dropped root can silently replace the answer with a merely local extremum, as (0,1)(0, 1) is here.

2. Dividing by x and losing the x = 0 candidates

Cancelling a common factor from both sides is the first move in solving most equations.

  1. Problem 3's conditions are 2x=2λx2x = 2\lambda x, 1=2λy1 = 2\lambda y and x2+y2=1x^2 + y^2 = 1Right so far: stationarity and the constraint.
  2. “Cancel the common factor 2x2x.”The habit that causes the mistake: it is valid only when the factor cannot be 00.
  3. λ=1\lambda = 1, so y=12y = \tfrac12 and the only candidates are (±32,12)(\pm\tfrac{\sqrt3}2, \tfrac12), both with f=54f = \tfrac54Dividing by xx assumes x≠0x \neq 0; the equation 2x(1−λ)=02x(1 - \lambda) = 0 also holds when x=0x = 0, and that branch holds (0,−1)(0, -1), the minimum −1-1, and (0,1)(0, 1). The warning sign was there: the circle is closed and bounded, so a minimum must exist, and this list has nothing below 54\tfrac54. In Problem 4 the same division was safe because xyz=32xyz = 32 rules out zeros.

3. Choosing λ instead of solving the constraint

After stationarity, λ\lambda looks like a free parameter, and it is tempting to set it for convenience.

  1. In Problem 5, 2(x−p)=λa2(x - p) = \lambda a, so x=p+λ2ax = p + \tfrac\lambda2aRight so far: the stationarity condition of Problem 5.
  2. “Pick the λ\lambda that makes the objective smallest.”The shortcut that causes the mistake: treating λ\lambda as a design choice rather than an unknown.
  3. λ=0\lambda = 0 gives x=p=(1,1,1)⊤x = p = (1, 1, 1)^\top, at distance 00pp is not on the plane: a⊤p=5≠14a^\top p = 5 \neq 14. λ\lambda is fixed by the constraint equation a⊤x=14a^\top x = 14, which stationarity alone does not contain; solving it gives λ=2\lambda = 2, the point (2,3,3)⊤(2, 3, 3)^\top and distance 33. Any answer that does not satisfy g=cg = c has solved an unconstrained problem.

4. Reading df*/dc as λ under the other sign convention

Many texts write the Lagrangian as f+λ(g−c)f + \lambda(g - c), and the sensitivity rule gets carried over without its sign.

  1. For Problem 2, L=xy+λ(x+2y−8)L = xy + \lambda(x + 2y - 8); its derivatives give y=−λy = -\lambda, x=−2λx = -2\lambda, λ=−2\lambda = -2 and the maximiser (4,2)(4, 2)Right so far: this convention finds the same point, with λ\lambda negated.
  2. “λ\lambda is the rate at which the optimum changes with cc.”The rule that causes the mistake: Problem 9's result, used without the convention it was proved in.
  3. λ=−2\lambda = -2, so raising cc from 88 to 99 lowers the maximum of xyxy by about 22With L=f+λ(g−c)L = f + \lambda(g - c), stationarity says ∇f=−λ∇g\nabla f = -\lambda\nabla g, so df∗dc=−λ=2\tfrac{df^*}{dc} = -\lambda = 2: the maximum rises. Check directly: (4.5,2.25)(4.5, 2.25) is on x+2y=9x + 2y = 9 and gives xy=818>8xy = \tfrac{81}8 > 8. The sign of λ\lambda is a convention; df∗dc=λ\tfrac{df^*}{dc} = \lambda holds for ∇f=λ∇g\nabla f = \lambda\nabla g.

5. Treating an inactive inequality as active

With equality constraints the answer always lies on the constraint, and that expectation carries over to inequalities.

  1. In Problem 10(b), stationarity gives 2(x−2)+μ=02(x - 2) + \mu = 0 and 2(y−1)+μ=02(y - 1) + \mu = 0Right so far: the KKT stationarity condition.
  2. “The answer of a constrained problem lies on the constraint.”The analogy that causes the mistake: true for g=cg = c, not for h≤0h \le 0.
  3. Set x+y=4x + y = 4: then μ=−1\mu = -1, the point is (52,32)(\tfrac52, \tfrac32), and the minimum is 12\tfrac12μ=−1\mu = -1 breaks μ≥0\mu \ge 0: it says moving into the region lowers ff, so the boundary is not where the minimum is. The unconstrained minimum (2,1)(2, 1) has x+y=3<4x + y = 3 < 4, so it is feasible, with μ=0\mu = 0 and f=0<12f = 0 < \tfrac12. Always try the inactive case first, and accept the active one only with μ≥0\mu \ge 0.

Print this set: lagrange-multipliers.pdf (problems, answers, and worked solutions on separate pages).