Optimization & Lagrange Multipliers

Study Sheet

Optimization & Lagrange Multipliers

Critical points, the second-derivative test, constrained maxima

Free and Constrained Optimization

Tip
Critical points and the D-test
xy
Level curves of x2+3xy+y2x^2 + 3xy + y^2: solid where f>0f > 0, dashed where f<0f < 0. Along the faint line y=−xy = -x the values are negative, so the origin is a saddle.

Interior extrema need ∇f=0\nabla f = \mathbf 0. Classify with D=fxxfyy−fxy2D = f_{xx}f_{yy} - f_{xy}^2: D>0D > 0 with fxx>0f_{xx} > 0 is a MIN, D>0D > 0 with fxx<0f_{xx} < 0 a MAX, and D<0D < 0 a SADDLE — the genuinely new 2-variable phenomenon, downhill one way and uphill another.

Why these conditions: at an interior extremum every slice through the point has a horizontal tangent, so both partials vanish. Near such a point ff is governed by its quadratic part 12(fxxh2+2fxyhk+fyyk2)\tfrac12(f_{xx}h^2 + 2f_{xy}hk + f_{yy}k^2). D>0D > 0 means this quadratic keeps one sign in every direction — a bowl or a dome, and the sign of fxxf_{xx} says which — while D<0D < 0 means it takes both signs. The test can overrule the slices you happen to look at: f=x2+3xy+y2f = x^2 + 3xy + y^2 curves upward along both axes, yet fxx=fyy=2f_{xx} = f_{yy} = 2, fxy=3f_{xy} = 3 and D=4−9=−5<0D = 4 - 9 = -5 < 0. The origin is a saddle, and along the line y=−xy = -x, f=x2−3x2+x2=−x2f = x^2 - 3x^2 + x^2 = -x^2 curves down.

Tip
Lagrange: gradients align at constrained extrema
xy55∇f ∥ ∇gxy = 25
The line x+y=10x + y = 10 and the level curves xy=9,16xy = 9, 16 (dashed), which cross it, and xy=25xy = 25, which just touches it at (5,5)(5, 5), where the gradients are parallel.

To optimize ff subject to g=cg = c, solve ∇f=λ∇g\nabla f = \lambda\nabla g: at the best point the level curve of ff is TANGENT to the constraint, so the gradients are parallel. Maximizing xyxy on x+y=10x + y = 10 gives x=y=5x = y = 5 — AM–GM, rediscovered by calculus.

Why tangency: at the best point, moving along the constraint cannot change ff to first order, so the constraint curve runs along a level curve of ff there. Two curves that touch have parallel normals, and the normals are ∇f\nabla f and ∇g\nabla g. For xyxy on x+y=10x + y = 10: ∇(xy)=(y,x)\nabla(xy) = (y, x) and ∇g=(1,1)\nabla g = (1, 1), so y=λ=xy = \lambda = x, and the constraint gives x=y=5x = y = 5, λ=5\lambda = 5. The maximum is 2525, and the level curve xy=25xy = 25 touches the line at (5,5)(5, 5).

Example
A linear function on a circle
xy(1, 2)x + 2y = 5
The level lines x+2y=−5,0,5x + 2y = -5, 0, 5: the line x+2y=5x + 2y = 5 touches the circle of radius 5\sqrt5 at (1,2)(1, 2).

Maximize x+2yx + 2y on x2+y2=5x^2 + y^2 = 5: Lagrange forces (x,y)∥(1,2)(x,y) \parallel (1,2), giving (1,2)(1, 2) and the maximum 55. In general ax+byax + by on a radius-rr circle peaks at ra2+b2r\sqrt{a^2+b^2} — Cauchy–Schwarz with a geometric proof.

Why (1,2)(1, 2): ∇(x+2y)=(1,2)\nabla(x + 2y) = (1, 2) and ∇(x2+y2)=(2x,2y)\nabla(x^2 + y^2) = (2x, 2y), so parallel gradients mean (x,y)(x, y) is a multiple of (1,2)(1, 2). On the circle x2+y2=5x^2 + y^2 = 5 the only multiples are ±(1,2)\pm(1, 2); the plus sign gives the maximum 1+4=51 + 4 = 5 and the minus sign the minimum −5-5. The general bound ra2+b2r\sqrt{a^2 + b^2} is here 5⋅5=5\sqrt5\cdot\sqrt5 = 5.

Side note
Significance: everything optimal is a critical point

Prices in economics, shapes of soap films, maximum-likelihood estimates in statistics, minimum-energy configurations in chemistry — all sit where a gradient vanishes, usually subject to constraints. Lagrange multipliers even carry meaning: λ\lambda is the "shadow price," how much the optimum improves per unit of loosened constraint.

Try it
Try it: a fenced field

A rectangular field lies along a straight river, so only three sides need fencing: two sides of length xx and one of length yy, with 2x+y=402x + y = 40 metres of fence. What is the largest area xyxy?

Show the answer

Substitute the constraint: A=x(40−2x)=40x−2x2A = x(40 - 2x) = 40x - 2x^2, so A′=40−4x=0A' = 40 - 4x = 0 gives x=10x = 10, then y=20y = 20 and the area is 200200 m2^2. Lagrange gives the same point without substituting: ∇(xy)=λ∇(2x+y)\nabla(xy) = \lambda\nabla(2x + y) reads y=2λy = 2\lambda and x=λx = \lambda, so y=2xy = 2x, and 2x+2x=402x + 2x = 40 gives x=10x = 10. The side along the river's far edge gets half of the fence and the two ends share the other half.

Absolute Extrema on a Closed Region

Tip
Check the inside, the edges and the corners

A continuous ff on a closed, bounded region attains an absolute maximum and minimum. They occur either at critical points inside the region or on its boundary. So: (1) find the interior critical points; (2) find the extremes of ff along each piece of the boundary (a one-variable problem, or Lagrange); (3) include the corners; (4) compare all the candidate values.

Why the boundary needs its own search: at an edge point, ff may still be increasing toward the outside, where the region does not allow you to go, so the gradient does not have to vanish there. The interior test ∇f=0\nabla f = \mathbf 0 cannot see such points. Both conditions on the region matter: on the open disk x2+y2<1x^2 + y^2 < 1, f=xf = x gets arbitrarily close to 11 but never reaches a maximum.

Example
Example: a disk
xy−180
Level curves of ff are circles about (1,0)(1, 0) (dashed): the smallest value −1-1 is at the centre, the largest 88 at the far point (−2,0)(-2, 0).

Find the absolute extremes of f=x2+y2−2xf = x^2 + y^2 - 2x on the disk x2+y2≤4x^2 + y^2 \le 4. Inside, fx=2x−2f_x = 2x - 2 and fy=2yf_y = 2y vanish only at (1,0)(1, 0), where f=−1f = -1. On the boundary circle x2+y2=4x^2 + y^2 = 4, so there f=4−2xf = 4 - 2x with −2≤x≤2-2 \le x \le 2.

On the edge, 4−2x4 - 2x is largest at x=−2x = -2, giving 88 at (−2,0)(-2, 0), and smallest at x=2x = 2, giving 00 at (2,0)(2, 0). Comparing the candidates −1-1, 88, 00: the absolute minimum is −1-1 at (1,0)(1, 0) and the absolute maximum is 88 at (−2,0)(-2, 0). A geometric check: f=(x−1)2+y2−1f = (x - 1)^2 + y^2 - 1 is the squared distance from (1,0)(1, 0), minus 11. The disk's nearest point to (1,0)(1, 0) is (1,0)(1, 0) itself, and its farthest is (−2,0)(-2, 0), at distance 33: 9−1=89 - 1 = 8.

Example
Example: a rectangle, where the corners matter

Find the absolute extremes of f=x2+2y2−4xf = x^2 + 2y^2 - 4x on the rectangle 0≤x≤30 \le x \le 3, −1≤y≤1-1 \le y \le 1. Inside, fx=2x−4=0f_x = 2x - 4 = 0 and fy=4y=0f_y = 4y = 0 give (2,0)(2, 0), with f=−4f = -4. Along the edges: on x=0x = 0, f=2y2f = 2y^2 runs from 00 to 22; on x=3x = 3, f=2y2−3f = 2y^2 - 3 runs from −3-3 to −1-1; on y=±1y = \pm1, f=x2−4x+2f = x^2 - 4x + 2 is smallest at x=2x = 2 (value −2-2), and equals 22 at x=0x = 0 and −1-1 at x=3x = 3.

The candidate values are −4-4 inside and 0,2,−3,−1,−20, 2, -3, -1, -2 on the edges. The maximum, 22, occurs at the two corners (0,±1)(0, \pm1); the minimum, −4-4, at (2,0)(2, 0). Notice that the maximum is at points where no derivative of any kind vanishes: along the edge x=0x = 0, f=2y2f = 2y^2 is still increasing when it hits the corner. Without the corners, the maximum would be missed.

Side note
Where it goes wrong

Stopping at the interior. In the disk example, ∇f=0\nabla f = \mathbf 0 only at (1,0)(1, 0). Someone who stops there reports the minimum −1-1 and no maximum at all, but the maximum 88 sits on the boundary at (−2,0)(-2, 0), where ∇f=(−6,0)≠0\nabla f = (-6, 0) \ne \mathbf 0. The gradient points out of the disk there: ff would keep growing if the region let it.

Try it
Try it: a tall rectangle

Find the absolute extremes of f=x2+y2−4yf = x^2 + y^2 - 4y on the rectangle −1≤x≤1-1 \le x \le 1, 0≤y≤30 \le y \le 3.

Show the answer

Inside, fx=2xf_x = 2x and fy=2y−4f_y = 2y - 4 vanish at (0,2)(0, 2), where f=−4f = -4. Completing the square, f=x2+(y−2)2−4f = x^2 + (y - 2)^2 - 4 is the squared distance from (0,2)(0, 2) minus 44, so the maximum is at the points of the rectangle farthest from (0,2)(0, 2): the corners (±1,0)(\pm1, 0), at squared distance 1+4=51 + 4 = 5, giving f=1f = 1. The edges confirm it: on y=0y = 0, f=x2f = x^2 reaches 11 at x=±1x = \pm1; on y=3y = 3, f=x2−3f = x^2 - 3 stays between −3-3 and −2-2; on x=±1x = \pm1, f=(y−2)2−3f = (y - 2)^2 - 3 stays between −3-3 and 11. Maximum 11 at (±1,0)(\pm1, 0), minimum −4-4 at (0,2)(0, 2).

Lagrange Multipliers in Practice

Tip
Solving the Lagrange system, and what λ means

To extremize ff subject to g=cg = c, solve ∇f=λ∇g\nabla f = \lambda\nabla g together with g=cg = c — for two variables, three equations in xx, yy, λ\lambda. Evaluate ff at every solution; when the constraint set is closed and bounded, the largest and smallest of these values are the constrained maximum and minimum. The multiplier has a meaning: if M(c)M(c) is the optimal value, then λ=dMdc\lambda = \dfrac{dM}{dc}.

Why λ\lambda is a rate: at the optimum, ∇f=λ∇g\nabla f = \lambda\nabla g. Raise the constraint level by dcdc and the optimal point moves by a small step dxd\mathbf x that keeps it on the new constraint, so ∇g⋅dx=dc\nabla g\cdot d\mathbf x = dc. The optimal value then changes by ∇f⋅dx=λ ∇g⋅dx=λ dc\nabla f\cdot d\mathbf x = \lambda\,\nabla g\cdot d\mathbf x = \lambda\,dc. Economists call λ\lambda the shadow price of the constraint: what one more unit of budget is worth.

Example
Example: the point of a plane nearest the origin

Minimize f=x2+y2+z2f = x^2 + y^2 + z^2 subject to x+2y+2z=9x + 2y + 2z = 9. The Lagrange condition (2x,2y,2z)=λ(1,2,2)(2x, 2y, 2z) = \lambda(1, 2, 2) says the point is a multiple of the normal: (x,y,z)=λ2(1,2,2)(x, y, z) = \tfrac\lambda2(1, 2, 2).

Put this into the constraint: λ2(1+4+4)=9\tfrac\lambda2(1 + 4 + 4) = 9, so λ=2\lambda = 2 and the point is (1,2,2)(1, 2, 2), with f=9f = 9. Check with the distance formula: the plane is ∣−9∣3=3\tfrac{|-9|}{3} = 3 from the origin, and 32=93^2 = 9. Check the meaning of λ\lambda: for the constraint x+2y+2z=cx + 2y + 2z = c the minimum is (c3)2=c29\left(\tfrac c3\right)^2 = \tfrac{c^2}{9}, whose derivative at c=9c = 9 is 2c9=2=λ\tfrac{2c}{9} = 2 = \lambda.

Example
Example: xy on an ellipse
xy(2, 1)xy = 2
The hyperbola xy=2xy = 2 (dashed) touches the ellipse x2+4y2=8x^2 + 4y^2 = 8 at (2,1)(2, 1) and (−2,−1)(-2, -1); at (2,1)(2, 1) the gradients (1,2)(1, 2) and (4,8)(4, 8) lie along one line.

Find the extremes of f=xyf = xy on the ellipse x2+4y2=8x^2 + 4y^2 = 8. The condition (y,x)=λ(2x,8y)(y, x) = \lambda(2x, 8y) gives y=2λxy = 2\lambda x and x=8λyx = 8\lambda y.

Substitute one equation into the other: y=2λ(8λy)=16λ2yy = 2\lambda(8\lambda y) = 16\lambda^2 y. If y=0y = 0 then x=0x = 0, which is not on the ellipse, so 16λ2=116\lambda^2 = 1 and λ=±14\lambda = \pm\tfrac14. For λ=14\lambda = \tfrac14, x=2yx = 2y, and the constraint gives 4y2+4y2=84y^2 + 4y^2 = 8, y=±1y = \pm1: the points (2,1)(2, 1) and (−2,−1)(-2, -1), where xy=2xy = 2. For λ=−14\lambda = -\tfrac14, x=−2yx = -2y: the points (−2,1)(-2, 1) and (2,−1)(2, -1), where xy=−2xy = -2. The maximum is 22 and the minimum −2-2. At (2,1)(2, 1), ∇f=(1,2)\nabla f = (1, 2) and ∇g=(4,8)=4(1,2)\nabla g = (4, 8) = 4(1, 2).

Side note
Where it goes wrong

Dividing by a variable that might be zero. Extremize f=x2+2y2f = x^2 + 2y^2 on x2+y2=1x^2 + y^2 = 1: the equations are 2x=2λx2x = 2\lambda x and 4y=2λy4y = 2\lambda y. Dividing the first by xx gives λ=1\lambda = 1; then 4y=2y4y = 2y forces y=0y = 0, so x=±1x = \pm1 and f=1f = 1, and the search seems finished. But x=0x = 0 was never ruled out: then y=±1y = \pm1, λ=2\lambda = 2 and f=2f = 2, which is the maximum. Write 2x(1−λ)=02x(1 - \lambda) = 0 and follow both cases instead of dividing.

Try it
Try it: the largest sum on a sphere

Find the maximum of x+y+zx + y + z on the sphere x2+y2+z2=12x^2 + y^2 + z^2 = 12.

Show the answer

The condition (1,1,1)=λ(2x,2y,2z)(1, 1, 1) = \lambda(2x, 2y, 2z) gives x=y=z=12λx = y = z = \tfrac{1}{2\lambda} (here λ≠0\lambda \ne 0, since the left side is not zero). The constraint becomes 3x2=123x^2 = 12, so x=±2x = \pm2. The point (2,2,2)(2, 2, 2) gives 66 and (−2,−2,−2)(-2, -2, -2) gives −6-6, so the maximum is 66, with λ=14\lambda = \tfrac14. Cauchy–Schwarz confirms it: x+y+z=(1,1,1)⋅(x,y,z)≤3⋅12=6x + y + z = (1, 1, 1)\cdot(x, y, z) \le \sqrt3\cdot\sqrt{12} = 6.

Proofs & Why It Matters

Tip
Proof sketch: the second-derivative D-test

Near a critical point, Taylor gives f≈f(a,b)+12(fxxh2+2fxyhk+fyyk2)f \approx f(a,b) + \tfrac12\left(f_{xx}h^2 + 2f_{xy}hk + f_{yy}k^2\right) — a quadratic form Q(h,k)Q(h,k). Complete the square: Q=fxx(h+fxyfxxk)2+Dfxxk2Q = f_{xx}\left(h + \tfrac{f_{xy}}{f_{xx}}k\right)^2 + \tfrac{D}{f_{xx}}k^2 with D=fxxfyy−fxy2D = f_{xx}f_{yy} - f_{xy}^2.

If D>0D > 0 both terms share the sign of fxxf_{xx} (a definite bowl: min or max); if D<0D < 0 the two terms disagree, so QQ takes both signs — a saddle. ■\blacksquare

Tip
Proof: why ∇f = λ∇g at a constrained extremum

Let r(t)\mathbf r(t) be any curve inside the constraint surface g=cg = c through the extremum at t=0t = 0. Then t↦f(r(t))t \mapsto f(\mathbf r(t)) has an extremum at 00, so 0=ddtf(r(t))∣0=∇f⋅r′(0)0 = \tfrac{d}{dt}f(\mathbf r(t))\big|_0 = \nabla f\cdot\mathbf r'(0).

Thus ∇f\nabla f is orthogonal to EVERY tangent direction of the constraint — but the vectors orthogonal to that whole tangent plane are exactly the multiples of ∇g\nabla g. Hence ∇f=λ∇g\nabla f = \lambda\nabla g. ■\blacksquare

Going Deeper: Explanations & Worked Problems

Concept
Why critical points, and what can go wrong

At an interior maximum or minimum, every slice through the point is a one-variable function with an extremum there, so every directional derivative vanishes — hence ∇f=0\nabla f = \mathbf 0.

But the converse fails in a way one variable never shows: at a SADDLE, the surface rises along one line and falls along another, with ∇f=0\nabla f = \mathbf 0 all the same (f=x2−y2f = x^2 - y^2 at the origin is the model: uphill along the xx-axis, downhill along the yy-axis). That is why the DD-test exists: near a critical point, ff is governed by its quadratic part 12(fxxh2+2fxyhk+fyyk2)\tfrac12(f_{xx}h^2 + 2f_{xy}hk + f_{yy}k^2), and D=fxxfyy−fxy2D = f_{xx}f_{yy} - f_{xy}^2 decides whether that quadratic keeps one sign (a genuine bowl or dome) or changes sign (a saddle). And remember the boundary: on a closed region, extrema can sit on the edge with ∇f≠0\nabla f \ne \mathbf 0 — that is precisely the situation Lagrange multipliers handle.

Example
Worked: classify every critical point of f = x³ − 3x + y²
xymin
Level curves of x3−3x+y2x^3 - 3x + y^2: closed loops around the minimum at (1,0)(1, 0); the dashed level f=2f = 2 crosses itself at the saddle (−1,0)(-1, 0).

Step 1 — set the gradient to zero: fx=3x2−3=0f_x = 3x^2 - 3 = 0 gives x=±1x = \pm1; fy=2y=0f_y = 2y = 0 gives y=0y = 0. Critical points: (1,0)(1, 0) and (−1,0)(-1, 0).

Step 2 — second partials: fxx=6xf_{xx} = 6x, fyy=2f_{yy} = 2, fxy=0f_{xy} = 0, so D=12xD = 12x.

Step 3 — test (1,0)(1, 0): D=12>0D = 12 > 0 and fxx=6>0f_{xx} = 6 > 0 — both slice curvatures upward: a LOCAL MIN, value f(1,0)=1−3=−2f(1,0) = 1 - 3 = -2.

Step 4 — test (−1,0)(-1, 0): D=−12<0D = -12 < 0 — a SADDLE, no extremum, even though the gradient vanishes.

Step 5 — global view: as x→−∞x \to -\infty, x3x^3 drags f→−∞f \to -\infty, so the local min at (1,0)(1,0) is NOT global — a reminder that the DD-test speaks only about a neighborhood.

Example
Worked: Lagrange multipliers on x + 2y with x² + y² = 5, no steps skipped

Step 1 — set up ∇f=λ∇g\nabla f = \lambda\nabla g: f=x+2yf = x + 2y, g=x2+y2g = x^2 + y^2, so (1,2)=λ(2x,2y)(1, 2) = \lambda(2x, 2y), giving 1=2λx1 = 2\lambda x and 2=2λy2 = 2\lambda y.

Step 2 — eliminate λ\lambda: divide the equations: 12=xy\tfrac12 = \tfrac xy, so y=2xy = 2x.

Step 3 — enforce the constraint: x2+(2x)2=5x^2 + (2x)^2 = 5 gives 5x2=55x^2 = 5, x=±1x = \pm1, hence the candidates (1,2)(1, 2) and (−1,−2)(-1, -2).

Step 4 — evaluate ff at each: f(1,2)=1+4=5f(1,2) = 1 + 4 = 5 and f(−1,−2)=−5f(-1,-2) = -5. The constraint circle is closed and bounded, so these are the global max and min: maximum 55.

Step 5 — see it geometrically: the level lines x+2y=cx + 2y = c are parallel lines sliding outward as cc grows; the largest cc still touching the circle touches it TANGENTLY, at the point where the radius is parallel to (1,2)(1,2) — which is exactly what Step 1 said.