Of all the pens you could fence, boxes you could fold and cans you could roll, one is best. The derivative finds it. Scroll down: at each stop a short note explains the next idea, then the picture is yours to play with before the next one arrives.
Everything on this page follows from the assumptions and definitions below. They are granted, not proved, so judge each one for yourself. A step that leans on one is tagged with its number.
You are looking down at a field beside a river. You have 40 meters of fence and want a rectangular pen. The river closes one side, so the fence only has to cover the other three.
Call the depth of the pen x, the distance it reaches back from the river. Pick a depth and the rest is forced: whatever fence is left over becomes the side along the river.
A shallow pen is long and thin. A deep pen uses up the fence on its two sides and has almost nothing left for the third. Somewhere in between is the pen that holds the most.
Rests on
Try itDrag the dot on the fence, or use the slider. Find the largest area you can. What happens to the area at each extreme?
The area is A = x · y, where y is the side along the river. That has two variables, but they are not free. The fence ties them together:
2x + y = 40, so y = 40 − 2x
That equation is the constraint. Substitute it and the area depends on the depth alone:
A(x) = x(40 − 2x), 0 ≤ x ≤ 20
The interval matters. At x = 0 the pen has no depth, and at x = 20 the two sides use all the fence. Both ends give zero area.
A graph has appeared on the right. Every pen you can build is one point on that curve.
Try itDrag the pen and watch the dot ride along the curve. Where on the curve is the largest pen? What is the curve doing there?
The graph now carries a tangent line, and its slope is the derivative:
A′(x) = 40 − 4x
Where the slope is positive, a deeper pen holds more. Where it is negative, you have gone too far. The largest pen sits where the slope is exactly zero:
40 − 4x = 0, so x = 10 and y = 20
A number where the derivative is zero is a critical number. This one gives 200 m², more than either end of the interval, so it is the absolute maximum.
A new slider changes how much fence you have.
Rests on
Try itWith 40 m the best pen is twice as long as it is deep. Give yourself 60 m, then 80 m. Is the best pen always that shape?
Start with a flat square sheet, 12 cm on a side. Cut the same small square out of each corner and fold the four flaps up. You have a box with no lid.
The side of each cut square is x, and it becomes the height of the box. The top picture is the flat sheet with the cuts in orange. The bottom picture is the box it folds into.
A small cut makes a wide, shallow tray. A big cut makes a tall box with almost no floor. You want the cut that holds the most.
Rests on
Try itDrag the corner of the orange square. Find the cut with the largest volume. Is it closer to a tray or to a tall box?
Each cut takes x off both ends of a side, so the floor of the box is 12 − 2x on a side and the height is x:
V(x) = x(12 − 2x)², 0 ≤ x ≤ 6
Multiply it out, differentiate and factor:
V′(x) = 12x² − 96x + 144 = 12(x − 2)(x − 6)
There are two places where the slope is zero. At x = 6 the cuts meet in the middle and nothing is left for a floor. At x = 2 the box holds 128 cm³, and that is the most it can.
Try itSet the cut to 2 cm and compare the floor with the height. Then look at the graph near x = 6: the slope is zero there too. Why is that not the answer?
A zero slope marks a candidate, not a winner. On a closed interval the method is always the same:
A new slider makes the sheet longer, up to 24 cm, while its short side stays 12 cm. The cut still cannot pass 6 cm. The derivative no longer factors nicely, so step 4 on the right uses the quadratic formula, and one of its two answers falls outside the interval.
Rests on
Try itStretch the sheet from 12 cm to 24 cm. The sheet doubles in size. How much does the best cut change?
A can has to hold 500 cm³. It can be tall and thin or short and wide, and every one of those shapes holds the same amount. They do not use the same amount of metal.
This time you are after a minimum: the least surface area. You control the radius r. The height adjusts so the volume stays at 500 cm³.
The interval is different too. The radius can be any positive number, so there are no ends to check. The picture shows radii from 2 cm to 9 cm.
Rests on
Try itDrag the side of the can. Find the least metal you can. Then look at the shape of that can: how does its height compare with its width?
The metal is two circles and a side: S = 2πr² + 2πrh. The constraint is the volume, πr²h = 500, so h = 500/(πr²). Substitute:
S(r) = 2πr² + 1000/r, r > 0
The first term is the two ends, which grow with the radius. The second is the side, which shrinks. Differentiate and set the slope to zero:
S′(r) = 4πr − 1000/r² = 0, so r³ = 250/π and r ≈ 4.30 cm
Put that radius back into the constraint and the height comes out as h = 2r. The best can is exactly as tall as it is wide.
Try itDrag the radius toward 4.3 cm. The dot snaps to the exact critical number when you get close. Compare the height with the diameter.
With no ends to compare against, a zero slope needs another argument. Take one more derivative:
S″(r) = 4π + 2000/r³
That is positive for every positive radius, so the graph bends upward everywhere. A curve that bends upward everywhere and has one flat spot has its lowest point there.
Two new controls: the volume, and whether the can has a top. Without a top it is a cup, with one circle of metal and not two.
Rests on
Try itPredict first: will the best cup be taller or flatter than the best can? Switch the top to Open and find out. Then change the volume. Does the best shape change?
The best value sits where the slope is zero, and a curve with zero slope is nearly level for a while on either side. So a near miss costs almost nothing.
The pen is back, set to a depth of 9 m where the best is 10 m. That is a 10% miss. The area is 198 m², which is 99% of the best possible.
For the pen the rule is exact: miss the best depth by some fraction and you lose the square of that fraction of the area. A 10% miss costs 1%. A 20% miss costs 4%.
Try itMove the pen to 8 m and check the 4%. Then try the box and the can: go 10% off the best value in each and see how little you lose.
All three problems went the same way:
The answers are only as good as the stories. The pen has no gate and the river bank is straight. The cardboard has no thickness and needs no tabs to hold its corners. The can has no seams, and its top is no thicker than its side. Change a story and the best shape changes with it. The recipe stays the same.
Everything is unlocked now. Play as long as you like, then scroll on to finish.
Rests on
Try itPick a problem and predict before you look: if you double what you are given (the fence, the sheet, the volume), does the best size double?
| Claim | Status | Rests on | Detail |
|---|---|---|---|
| The pen: A(x) = x(L − 2x) is largest at x = L/4, where the side along the river is twice the depth. With 40 m of fence that is 10 m by 20 m, 200 m² (stops 2 and 3). | ✓ Proved | A1, D1, D2 | A(x) = x(L - 2x) has A'(x) = L - 4x, zero only at x = L/4, where the river side is 2x and A = L^2/8 (200 m^2 for 40 m); both ends give 0. |
| The box: V(x) = x(12 − 2x)² has V′(x) = 12(x − 2)(x − 6). The best cut is 2 cm, for 128 cm³ (stop 5). | ✓ Proved | A2, D1, D2 | V(x) = x(12 - 2x)^2 has V'(x) = 12x^2 - 96x + 144 = 12(x - 2)(x - 6); V(2) = 128 and V(0) = V(6) = 0, so 2 cm is the best cut. |
| A longer sheet: the derivative’s two roots come from the quadratic formula, and only the smaller one is inside the interval (stop 6). | ✓ Proved | A2, D1, D2 | For a 12 by b sheet V'(x) = 12x^2 - 4(12 + b)x + 12b, with roots ((12 + b) -/+ sqrt(144 - 12b + b^2))/6; for b from 12 to 24 the smaller root is inside (0, 6) and the larger is not (best cuts 12: 2.000, 14: 2.148, 16: 2.263, 18: 2.354, 20: 2.427, 22: 2.487, 24: 2.536; doubling the sheet moves the best cut by a factor of 1.27). |
| The can: S(r) = 2πr² + 2V/r is smallest where r³ = V/(2π), and there h = 2r. S″(r) is positive for every r > 0 (stops 8 and 9). | ✓ Proved | A3, D1, D2 | S(r) = 2 pi r^2 + 2V/r has S'(r) = 4 pi r - 2V/r^2, zero at r = (V/(2 pi))^(1/3), where h = 2r; S''(r) = 4 pi + 4V/r^3 > 0. For 500 cm^3, r = 4.301 cm. |
| The cup: with no top the least metal is where h = r, flatter than the can (stop 9). | ✓ Proved | A4 | With no top, S(r) = pi r^2 + 2V/r is least at r = (V/pi)^(1/3), where h = r: flatter than the closed can, and the same shape for every volume. |
| Missing the best depth of the pen by a fraction costs the square of that fraction of the area: 10% costs 1%, 20% costs 4% (stop 10). | ✓ Proved | A1 | A pen whose depth misses L/4 by a fraction e has (1 - e^2) of the largest area: 9 m gives 198 m^2 (99%), 8 m gives 192 m^2 (96%). |
| The numbers the tool shows as you drag. | ✓ Checked independently | — | The page's own functions, run at 63 settings across the three problems, match SymPy's values, slopes and best sizes to 3.7e-15 (relative); the on-screen difference-quotient check is within 1.5e-08. |
| Units: m² for the pen, cm³ for the box, cm² for the can. | Reviewed | — | A length times a length, three lengths multiplied, and an area. |
| The sentences on the cards. | Reviewed | — | Each card was read against the formulas, looking for anything assumed but not listed. No objection stands. |
| A1, A2, A3, A4, D1, D2 | Assumed | — | Granted, not proved. Whether they suit a real pen, box or can is yours to judge. |
Proved: SymPy reduced the difference between the two sides to zero. Checked independently: the page’s own functions were run against SymPy’s exact answers. Checked numerically: evidence, not proof. Reviewed: a model or a person read it. Assumed: an assumption or a definition, granted and not proved. Checks run 2026-11-12 with SymPy 1.14.0; rerun them with interactives/checks/optimization.py. Cards read by Claude Fable 5.2, 2026-11-11. How it’s checked
Part of Calc Practice: free Calculus 1 practice. Try the optimization problems or see more interactives.