---
title: Lagrange multipliers
heading: Optimizing under a constraint
eyebrow: A9 · Lesson 12 · Lagrange multipliers
xp: 40
---

::: hook
A current of 3 A arrives at two resistors in parallel and has to split between them. Of all the ways it could divide, the one nature picks is the one that wastes the least power. You can find that split with a constraint: minimize the total heat $I_1^2R_1 + I_2^2R_2$ while keeping $I_1 + I_2 = 3$. The answer comes out as the ordinary current divider rule, and the method, **Lagrange multipliers**, works for any problem with a "subject to" in it: the most area for a given length of wire, the least material for a given volume.
:::

::: play
- A total current $I$ splits as $I_1$ through $R_1$ and $I - I_1$ through $R_2$. The curve is the total power against $I_1$.
- The marker is the current-divider split, $I_1 = I\frac{R_2}{R_1 + R_2}$. Is it at the bottom of the curve?
- Change the resistors and check again.
:::
:::

```sim plot
view: graph
x: I1 = 0..3 A
y: P = 0..40 W
slider: R1 = 1..10 step 0.5 = 2 Ω
slider: R2 = 1..10 step 0.5 = 4 Ω
plot: I1^2*R1 + (3 - I1)^2*R2 | label: total power
marker: x = 3*R2/(R1 + R2) | label: current divider
readout: least power, W = 9*R1*R2/(R1 + R2) | digits: 4
```

::: predict
## You want the largest rectangle you can fence with 40 m of wire. What shape is it?

- [x] A 10 m square
- [ ] A long thin rectangle
- [ ] 15 m by 5 m
- [ ] Any rectangle gives the same area

::: reveal
A 10 m square, with area 100 m². Maximize $xy$ subject to $2x + 2y = 40$: the multiplier condition $(y, x) = \lambda(2, 2)$ forces $x = y$. A 15 by 5 rectangle encloses only 75 m².
:::
:::

::: nameit
## The method

To find the largest or smallest $f(x, y)$ on the curve $g(x, y) = c$, solve

$$\nabla f = \lambda\nabla g \qquad g(x, y) = c$$

for $x$, $y$ and the **Lagrange multiplier** $\lambda$: three equations, three unknowns.

**Why it works.** Walk along the constraint curve. At the best point, $f$ can't increase in either direction along it, so $\nabla f$ has no component along the curve: it points straight across it. So does $\nabla g$, since $g$ is constant along the curve. Two vectors both perpendicular to the curve are parallel: $\nabla f = \lambda\nabla g$. Geometrically, the level curve of $f$ just touches the constraint curve.

## What $\lambda$ means

$\lambda$ is how fast the best value changes as the constraint is loosened: $\lambda = \frac{df_\text{best}}{dc}$. Economists call it a shadow price. In the current-splitting problem, $\lambda$ is twice the voltage across the pair: the extra power per extra amp.

## Minimum heat

Minimize $I_1^2R_1 + I_2^2R_2$ with $I_1 + I_2 = I$: $(2I_1R_1, 2I_2R_2) = \lambda(1, 1)$, so $I_1R_1 = I_2R_2$. The two resistors get **equal voltages**, which is exactly what Kirchhoff's laws give. Current divides in the way that dissipates the least power, and

$$I_1 = I\frac{R_2}{R_1 + R_2} \qquad P_\text{min} = I^2\frac{R_1R_2}{R_1 + R_2}$$

the power in the parallel combination.
:::

::: example
## Maximize $xy$ subject to $x + y = 10$.

::: solution
1. **Lagrange's condition.**
   $$(y, x) = \lambda(1, 1)$$
   so $x = y = \lambda$.
2. **Apply the constraint.** $x + y = 10$ gives $x = y = 5$, so the maximum is 25, with $\lambda = 5$.
3. **Check what $\lambda$ means.** With $x + y = c$ the best is $c^2/4$, whose derivative at $c = 10$ is 5.

**Answer:** the maximum is 25, at $x = y = 5$.
:::
:::

::: example
## 3 A splits between 2 Ω and 4 Ω. Find the least-power split.

::: solution
1. **Split the current.**
   $$\begin{aligned} I_1 &= 3 \times \frac{4}{6} \\ &= 2\ \text{A} \end{aligned}$$
   and $I_2 = 1$ A, both resistors at 4 V.
2. **Total power.**
   $$\begin{aligned} P &= 4 \times 2 + 1 \times 4 \\ &= 12\ \text{W} \end{aligned}$$
   the same as $9 \times \frac{8}{6}$.
3. **The multiplier.**
   $$\begin{aligned} \lambda &= 2I_1R_1 \\ &= 8 \end{aligned}$$
   which is twice the 4 V across them.

**Answer:** 2 A through the 2 Ω resistor and 1 A through the 4 Ω, for 12 W in all.
:::
:::

::: example
## Find the closed box with surface area 6 m² that holds the most.

::: solution
1. **Set up the problem.** Maximize $V = xyz$ with
   $$\begin{aligned} g &= 2(xy + yz + zx) \\ &= 6 \end{aligned}$$
2. **Lagrange's condition.** $\nabla V = \lambda\nabla g$ gives
   $$\begin{aligned} yz &= 2\lambda(y + z) \\ xz &= 2\lambda(x + z) \\ xy &= 2\lambda(x + y) \end{aligned}$$
3. **Solve.** Dividing pairs shows $x = y = z$, so $6x^2 = 6$ and $x = 1$.
4. **Read the answer.** Symmetric problems often have symmetric answers, but the multiplier method proves it.

**Answer:** the best box is a 1 m cube, holding $V = 1$ m³.
:::
:::

::: check
given: c = 8 | 12 | 20
answer: c^2/4

## What is the largest value of $xy$ with $x + y = \given{c}$?

::: right
Right. $x = y = c/2$, giving $c^2/4$ = {answer}.
:::

::: misses
- [c^2/2] Each factor is $c/2$, so the product is $c^2/4$.
- [any] Not yet. $\nabla(xy) = \lambda\nabla(x + y)$ gives $x = y$.
:::
:::

::: check
given: I = 2 | 5; R1 = 2 | 10; R2 = 3 | 5
answer: I*R2/(R1 + R2)
unit: A
tolerance: 0.5%

## {I} A splits between {R1} Ω and {R2} Ω so as to dissipate the least power. How much goes through the {R1} Ω resistor?

::: right
Right. Equal voltages: $I_1 = I\frac{R_2}{R_1 + R_2}$ = {answer}, the current divider.
:::

::: misses
- [I*R1/(R1 + R2)] More current takes the easier path: the smaller resistor gets more.
- [I/2] An even split isn't the least-power one unless the resistors are equal.
- [any] Not yet. $\nabla P = \lambda\nabla(I_1 + I_2)$ gives $I_1R_1 = I_2R_2$.
:::
:::

::: check
given: I = 2 | 4; R1 = 3 | 6; R2 = 6 | 12
answer: I^2*R1*R2/(R1 + R2)
unit: W
tolerance: 0.5%

## What is that least power, for {I} A between {R1} Ω and {R2} Ω?

::: right
Right. $I^2\frac{R_1R_2}{R_1 + R_2}$ = {answer}: the power in the parallel combination.
:::

::: misses
- [I^2*(R1 + R2)] That's the series combination.
- [any] Not yet. Substitute the best split.
:::
:::

::: check
given: c = 6 | 10 | 16
answer: c/2

## For the largest $xy$ with $x + y = \given{c}$, what is the multiplier $\lambda$?

::: right
Right. $\lambda = y = c/2$ = {answer}, which is also $\frac{d}{dc}\frac{c^2}{4}$.
:::

::: misses
- [c^2/4] That's the best value; $\lambda$ is how fast it grows with $c$.
- [any] Not yet. From $y = \lambda$.
:::
:::

::: check
given: P = 40 | 100 | 24
answer: P^2/16
unit: m²
tolerance: 0.5%

## What is the largest area a rectangle with perimeter {P} m can have, in m²?

::: right
Right. A square of side $P/4$: area $\frac{P^2}{16}$ = {answer}.
:::

::: misses
- [P^2/4] The side is $P/4$, not $P/2$.
- [any] Not yet. Maximize $xy$ with $2x + 2y = P$.
:::
:::

::: check
given: r = 1 | 3 | 5
answer: r*sqrt(2)
tolerance: 0.5%

## What is the largest value of $x + y$ on the circle $x^2 + y^2 = \given{r}^2$?

::: right
Right. $(1, 1) = \lambda(2x, 2y)$ gives $x = y = \frac{r}{\sqrt 2}$, so $x + y = r\sqrt 2$ = {answer}.
:::

::: misses
- [2*r] The point $(r, r)$ isn't on the circle.
- [r] That's at $(r, 0)$; moving along the circle does better.
- [any] Not yet. $\nabla(x + y) = \lambda\nabla(x^2 + y^2)$.
:::
:::

::: check
kind: parts
given: S = 24 | 54 | 96

## A closed box has surface area {S} m².

::: part
answer: sqrt(S/6)
unit: m
tolerance: 0.5%

### What side gives the largest volume?

::: misses
- [S/6] $6x^2 = S$.
- [any] The best box is a cube.
:::
:::

::: part
answer: (S/6)^1.5
unit: m³
tolerance: 0.5%

### What is that volume?

::: misses
- [any] $x^3$.
:::
:::
:::

::: check
kind: derivation
vars: I = 1..5, R1 = 1..10, R2 = 1..10

## Current $I$ splits between $R_1$ and $R_2$ to minimize $R_1i_1^2 + R_2i_2^2$ with $i_1 + i_2 = I$.

::: step
answer: I*R2/(R1 + R2)

### What is $i_1$?
:::

::: step
answer: I^2*R1*R2/(R1 + R2)

### What is the minimum power?
:::

::: right
Right. The least-power split is the current divider, and the power is $I^2$ times the parallel resistance.
:::
:::

::: explain
## Why does a current split between parallel resistors in the way that minimizes the total power?

::: model
The real split is set by Kirchhoff's laws: both resistors see the same voltage, so $I_1R_1 = I_2R_2$. The Lagrange condition for minimizing $I_1^2R_1 + I_2^2R_2$ subject to a fixed total current is $2I_1R_1 = 2I_2R_2 = \lambda$, which is the same equal-voltage condition. So the physical split and the least-power split coincide. Maxwell noticed this; it holds for any resistor network, which is one reason resistor networks are well behaved: their equations are the condition for a minimum of a positive definite quantity.
:::
:::

::: practice

::: check
given: s = 3..30 int
answer: (s/3)^3
tolerance: 0.5%

## What is the largest value of $xyz$ with $x + y + z = \given{s}$, for positive $x$, $y$, $z$?

::: misses
- [any] $x = y = z$.
:::
:::

::: check
given: I = 3 | 6; R = 4 | 10
answer: I/2
unit: A

## {I} A splits between two equal {R} Ω resistors with the least power. How much goes through each?

::: misses
- [any] Equal resistors share equally.
:::
:::

::: check
given: c = 2..20 int
answer: c^2/2
tolerance: 0.5%

## What is the smallest value of $x^2 + y^2$ with $x + y = \given{c}$?

::: misses
- [c^2/4] That's the largest $xy$. Here $x = y = c/2$ gives $2(c/2)^2$.
- [any] $x = y = c/2$.
:::
:::
:::
