Lagrange Multipliers

At the constrained best, gradients line up.

The best value along a path

The bowl f(x, y) = x² + y² has its lowest point at the origin. Now ask for the smallest value of f only among the points on the line x + 2y = 5. The origin is not on that line, so the answer is somewhere else: the point of the line closest to the origin.

The line is a constraint, written g(x, y) = c with g = x + 2y and c = 5. On a contour map, the contours of f are circles, and the constraint is a line drawn across them. Walking along the line, you cross the circles, and f goes down and then up again.

g = k∇f∇g

The contours of a bowl, cut at heights 4, 8, 12 and 16, and a straight constraint g = k. At the marked point on the line, the gold ∇f points straight out from the center and the plain ∇g stands square to the line: they point different ways, and the small arrow shows the direction along the line in which f falls.

Crossing gradients mean f can still improve

At a point on the path, let t be a unit vector along the path. Moving along the path, f changes at the rate ∇f · t. If that is not 0, f falls one way along the path and rises the other, so the point is neither the smallest nor the largest value of f on the path.

So at a constrained maximum or minimum, ∇f · t = 0: ∇f is at right angles to the path. The path is a level curve of g, and ∇g is always at right angles to the level curves of g. Two vectors at right angles to the same direction are parallel, so at the best point ∇f = λ∇g for some number λ, the Lagrange multiplier.

g = k∇f∇g

The same map with the point moved to where the smallest contour, the ring at height 4, just touches the line. There ∇f and ∇g lie along one ray, ∇f the longer: ∇f = λ∇g.

Three equations, three unknowns

Written in components, ∇f = λ∇g is two equations: ∂f/∂x = λ ∂g/∂x and ∂f/∂y = λ ∂g/∂y. With the constraint g(x, y) = c that makes three equations for x, y and λ. Solve the first two for x and y in terms of λ, then substitute into the constraint.

For x² + y² on x + 2y = 5: ∇f = (2x, 2y) and ∇g = (1, 2), so 2x = λ and 2y = 2λ, giving x = λ/2 and y = λ. The constraint becomes λ/2 + 2λ = 5, so 2.5λ = 5 and λ = 2. The point is (1, 2), which is on the line, since 1 + 4 = 5, and f(1, 2) = 1² + 2² = 5.

Other points on the line give more: (5, 0) gives 25, and (3, 1) and (−1, 3) both give 10. Far along the line f grows without limit, so 5 is the minimum.

xyx + 2y = 5

The line x + 2y = 5, the contour x² + y² = 5 touching it at (1, 2), and the dashed contour x² + y² = 10 crossing it at (3, 1) and (−1, 3). Each ∇f is drawn at a quarter of its length. At (1, 2), ∇f = (2, 4) = 2 × (1, 2) stands square to the line; at (3, 1), ∇f = (6, 2) does not, and f still falls along the line toward (1, 2).

More than one candidate

The equations can give several points, and each must be checked. Find the largest and smallest values of f = xy on the circle x² + y² = 8. Here ∇f = (y, x) and ∇g = (2x, 2y), so y = 2λx and x = 2λy. Then x = 2λ(2λx) = 4λ²x. If x = 0 then y = 0 too, which is not on the circle, so 4λ² = 1 and λ = 1/2 or λ = −1/2.

With λ = 1/2, y = x, and 2x² = 8 gives (2, 2) and (−2, −2), where f = 4. With λ = −1/2, y = −x, giving (2, −2) and (−2, 2), where f = −4. All four lie on the circle, since 4 + 4 = 8. Comparing the values, the largest is 4 and the smallest is −4.

What λ measures

The multiplier is the rate at which the best value changes as the constant in the constraint changes. To maximize xy on x + y = 10, the equations y = λ and x = λ give x = y = 5, a maximum of 25, with λ = 5. On x + y = 11 the maximum is 5.5 × 5.5 = 30.25, which is 5.25 more: close to λ for a change of 1.

In the bowl example, the smallest value of x² + y² on x + 2y = c is c²/5. At c = 5 it is 5, and at c = 5.1 it is 5.202, a rise of about 2 for each unit of c, which is λ = 2.

∇f∇gx + 2y = 1two crossings

x + 2y = 1 cuts the ellipse twice: walk along the ellipse between the crossings and x + 2y rises above 1, so neither crossing is the maximum

Slide the line up until it only just touches the ellipse

The ellipse x²/4 + y² = 1 is the constraint, and the line x + 2y = k is a contour of f = x + 2y. At k = 1 the line cuts the ellipse at two points, where the plain ∇f = (1, 2) and the gold ∇g = (x/2, 2y) point different ways, so a larger k can still be reached. Slide k up and the cuts close in, until at k = 2√2 ≈ 2.83 the line just touches at (√2, 1/√2), where ∇f = √2 ∇g.

The usual mistakes

Solving ∇f = λ∇g without the constraint. The two component equations alone leave λ undetermined; the constraint fixes it.

Dividing by a variable that might be 0. In xy on x² + y² = 8, dividing x = 4λ²x by x is safe only after checking that x = 0 gives no point on the circle.

Stopping at the first candidate. The method gives every point where the gradients are parallel; the largest and smallest values come from comparing f at all of them.

Taking the gradients to be perpendicular at the best point. They are parallel; it is ∇f and the path that are at right angles.

A beam sawn from a log

In the application below, a beam with a rectangular cross-section is cut from a round log, so its width and depth are tied by the circle of the log. Setting the gradient of its strength equal to λ times the gradient of the constraint gives the strongest beam, which is deeper than it is wide.

Worked example: A Beam Sawn From a Round Log: the Width and Depth That Resist Bending Best, Compared With a Square Beam

Question A sawmill cuts a beam of rectangular cross-section, w centimeters wide and d centimeters deep, from a round log 60 centimeters across, with the corners of the rectangle on the circle, so that w2 + d2 = 3600. The beam's strength against bending under a load from above is S = kwd2, for a constant k. (a) Use a Lagrange multiplier to find the width and depth of the strongest beam. (b) Find how much stronger it is than the square beam cut from the same log, as a percentage of the square beam's strength.

  1. 1.(a) ∇ S = (kd2, 2kwd) and ∇ g = (2w, 2d), so ∇ S = λ∇ g says kd2 = 2λ w and 2kwd = 2λ d.

    204060204060width w, cmdepth d, cm(a) at the best beam the two gradients are parallel
    204060204060width w, cmdepth d, cm(a) at the best beam the two gradients are parallel
    (a) The arc is the edge of the log, w2 + d2 = 3600, and the other curves join beams of equal strength. The strongest beam is where one of them just touches the arc, and there the two gradients are parallel.
  2. 2.The depth is not 0, so dividing the second equation by 2d gives λ = kw. The first then becomes kd2 = 2kw2, that is d2 = 2w2.

    204060204060width w, cmdepth d, cm(a) at the best beam the two gradients are parallelso d2= 2w2
    204060204060width w, cmdepth d, cm(a) at the best beam the two gradients are parallelso d2= 2w2
    The equations kd2 = 2λ w and 2kwd = 2λ d give d2 = 2w2: the strongest beam lies on the line d = √2w.
  3. 3.Substituting into the constraint: w2 + 2w2 = 3600, so w2 = 1200 and w = √1200 ≈ 34.6 centimeters, and d2 = 2400, so d = √2400 ≈ 49.0 centimeters. At the ends of the arc, where w = 0 or d = 0, the strength is 0, so this point is the maximum.

    204060204060width w, cmdepth d, cm34.6 by 49.0(a) at the best beam the two gradients are parallelso d2= 2w23w2= 3600: w = 34.6 cm, d = 49.0 cm
    204060204060width w, cmdepth d, cm34.6 by 49.0(a) at the best beam the two gradients are parallelso d2= 2w23w2= 3600: w = 34.6 cm, d = 49.0 cm
    The line meets the arc at w ≈ 34.6 and d ≈ 49.0 centimeters.
  4. 4.(b) The strongest beam has S = k × √1200 × 2400 ≈ 83138k. The square beam has w = d, so 2w2 = 3600, w = √1800 ≈ 42.43 centimeters, and S = k × √1800 × 1800 ≈ 76368k.

    204060204060width w, cmdepth d, cm34.6 by 49.0square(a) at the best beam the two gradients are parallelso d2= 2w23w2= 3600: w = 34.6 cm, d = 49.0 cm(b) square: w = d = 42.4 cm
    204060204060width w, cmdepth d, cm34.6 by 49.0square(a) at the best beam the two gradients are parallelso d2= 2w23w2= 3600: w = 34.6 cm, d = 49.0 cm(b) square: w = d = 42.4 cm
    (b) The square beam, 42.4 centimeters each way, lies on a curve of lower strength.
  5. 5.The ratio is 8313876368 ≈ 1.089, so the strongest beam is about 8.9 percent stronger than the square one. Check: w2 + d2 = 1200 + 2400 = 3600, so the corners of the strongest beam lie on the log.

    204060204060width w, cmdepth d, cm34.6 by 49.0square8.9% stronger(a) at the best beam the two gradients are parallelso d2= 2w23w2= 3600: w = 34.6 cm, d = 49.0 cm(b) square: w = d = 42.4 cm83138/76368 = 1.089: 8.9% stronger
    204060204060width w, cmdepth d, cm34.6 by 49.0square8.9% stronger(a) at the best beam the two gradients are parallelso d2= 2w23w2= 3600: w = 34.6 cm, d = 49.0 cm(b) square: w = d = 42.4 cm83138/76368 = 1.089: 8.9% stronger
    The strongest beam is about 8.9 percent stronger than the square one.

Answer: (a) about 34.6 centimeters wide and 49.0 centimeters deep, with w2 = 1200 and d2 = 2400; (b) about 8.9 percent stronger than the square beam

Common mistakes

  • Maximizing wd2 with nothing linking w and d. Without the constraint the strength has no greatest value; the circle of the log is what ties the width to the depth.
  • Taking the square beam to be the strongest because it has the largest cross-section of any rectangle in the circle. The strength grows with the square of the depth, so it pays to give up some width for depth.

More partial derivatives problems, worked step by step →

Practice Lagrange Multipliers in the app