Part IV · Calculus Chapter 27 of 60
Extrema and optimization
An inventors’ contest: a box from a sheet, a speed camera on a highway, a lifeguard on a beach, a tin can and the square root of two on a calculator with no square-root key. Each task has infinitely many options, and the derivative finds the best.
Builds on: 26 · The derivative
You will learn
- find the largest and smallest values of a function with the derivative
- understand the theorems of Fermat, Rolle and Lagrange and what they imply about the shape of a graph
- solve applied optimization problems and find roots of equations by Newton’s method
The last chapter ended with the box problem. Equal little squares of side $x$ are cut from the corners of a $30 \times 30$ cm sheet of cardboard and the edges are folded up. The cut can be anything from zero to fifteen centimetres, and each gives its own box. Which of the infinitely many boxes holds the most?
Picture an inventors’ contest. The jury sets five tasks, and in each one you have to find the best option among infinitely many: the roomiest box, the fastest route, the cheapest can. You can’t try everything, and guessing is risky. The winner will have one tool, the derivative, and one idea going back to Pierre de Fermat: at the top of a hill the tangent is horizontal. Each task will add a new rule to this idea, and by the end of the contest we’ll have assembled a complete rulebook for finding the best.
Task one: the box
The volume of the box is the area of the base times the height. The base is a square of side $30 - 2x$, the height is $x$, so
$$V(x) = x\,(30 - 2x)^2, \qquad 0 < x < 15.$$Let’s compute for whole-number cuts: $V(1) = 784$, $V(2) = 1352$, $V(3) = 1728$, $V(4) = 1936$, $V(5) = 2000$, $V(6) = 1944$, $V(7) = 1792$ cubic centimetres. It looks as if the best cut is about five centimetres. But perhaps at $x = 4.9$ or $5.03$ the volume is even larger? The table won’t tell us, but the derivative will.
Near the top the graph becomes flat, and a small error in the cut hardly changes the volume: at $x = 4.5$ we get $1984.5$ cm³, at $x = 5.5$, $1985.5$ cm³, only one per cent less than the best, although the cut was off by ten per cent. This observation is much older than calculus. In 1615 Johannes Kepler published the New Stereometry of Wine Barrels: he was working out which barrel, for a given length of the measuring rod merchants inserted through the bung-hole, holds the most wine, and he noticed that near the largest volume small changes in the dimensions barely change the capacity. Around 1636 Pierre de Fermat turned this idea into a method. Today it’s written like this.
A point $c$ is a local maximum of a function $f$ if $f(x) \le f(c)$ for all $x$ in some interval around $c$, and a local minimum if $f(x) \ge f(c)$. Maxima and minima together are called extrema (from the Latin extremum, “outermost”). The word “local” means that $f(c)$ is compared only with its neighbours: the top of a small hill is a maximum, even if there’s a mountain somewhere nearby.
If a function $f$ has a local extremum at a point $c$ and is differentiable at that point, then $f'(c) = 0$.
The trick is to look at the signs of the secants’ slopes to the left and right of the top, and squeeze the derivative between them.
Points where the derivative is zero or doesn’t exist are called critical points. By Fermat’s theorem, a local extremum inside an interval can occur only at a critical point.
Let’s find the critical points of the volume. Expand the brackets: $V(x) = 4x^3 - 120x^2 + 900x$, so $V'(x) = 12x^2 - 240x + 900 = 12(x - 5)(x - 15)$. On the interval $(0, 15)$ the derivative vanishes only at $x = 5$. So if the volume has a largest value, it’s reached at $x = 5$, and it’s $2000$ cm³.
A small “if” remains. Fermat’s theorem says where a maximum can be, but doesn’t promise there is one. The function $\frac1x$ on the interval $(0, 1)$ has no largest value: it grows without bound. The function $x$ on the same interval has none either, although it’s bounded: you can get arbitrarily close to one but never reach it. Existence is guaranteed by a theorem that needs a closed interval with its ends and continuity.
A function continuous on a closed interval $[a, b]$ attains a largest and a smallest value on it.
For the box, add the ends: $V(0) = V(15) = 0$ (a flat sheet, and a sheet with nothing left of it). The function $V$ is continuous on $[0, 15]$, so by the extreme value theorem there is a largest value. At the ends the volume is zero, so the largest value is reached inside, and there, by Fermat’s theorem, the derivative is zero. The only candidate is $x = 5$. Answer: cut out squares of side $5$ cm, giving a $20 \times 20 \times 5$ box of volume $2000$ cm³. For a sheet of side $a$ the same calculation gives $x = \frac a6$.
The derivative of a function at a point $c$ is zero. What can be said for certain?
Fermat’s theorem is a necessary condition: at an extremum the derivative is zero (if it exists), but an extremum doesn’t follow from $f'(c) = 0$. The cubic $y = x^3$ briefly becomes horizontal at zero and keeps on rising. And extrema occur where there’s no derivative too, as with $|x|$ at zero. So the list of candidates includes all the critical points and the ends of the interval.
Task two: the speed camera
On a country highway there are two cameras ten kilometres apart. Each records a car’s number plate and the time. A car covered the stretch in six minutes, that is, at an average speed of $10 : \frac{6}{60} = 100$ km/h, where the limit is $90$. A fine arrives. The driver is indignant: “I was watching the speedometer, it never showed more than ninety!” The jury asks the inventors to settle the dispute. Intuition is on the camera’s side, but proving it is no five-minute job.
Let’s start with a special case that’s simpler: the car set off and came back to the same point, or, on the graph, the function’s values at the ends of the interval are equal. Then somewhere it must have stopped or turned round.
Let a function $f$ be continuous on the closed interval $[a, b]$, differentiable on the open interval $(a, b)$, and let $f(a) = f(b)$. Then there’s a point $c \in (a, b)$ at which $f'(c) = 0$.
The idea: the largest or smallest value must turn up inside the interval, and there Fermat’s theorem works.
Now the general case. The average speed over the interval $[a, b]$ is the slope of the chord joining the ends of the distance graph. The claim about the camera reads: somewhere on the interval the tangent is parallel to the chord.
Let a function $f$ be continuous on the closed interval $[a, b]$ and differentiable on the open interval $(a, b)$. Then there’s a point $c \in (a, b)$ at which $f(b) - f(a) = f'(c)\,(b - a)$.
The trick: subtract the chord from the function. The picture “tilts” so that the chord becomes horizontal, and we’re in the setting of Rolle’s theorem.
Lagrange published this theorem in 1797, in the same Theory of Analytic Functions where the prime appeared. Its main strength isn’t in cameras but in its consequences: it turns information about the derivative at each point into information about the function itself over a whole interval. The first consequence is something we only saw on graphs in the last chapter.
If $f'(x) > 0$ at every point of an interval, then $f$ is increasing on it; if $f'(x) < 0$, decreasing. If $f'(x) = 0$ at every point of the interval, then $f$ is constant on it.
Take any two points $x_1 < x_2$ in the interval. The function is differentiable on the whole interval, so on $[x_1, x_2]$ it’s continuous (a differentiable function is continuous) and the conditions of Lagrange’s theorem hold: $f(x_2) - f(x_1) = f'(c)(x_2 - x_1)$ for some point $c$ between them. The factor $x_2 - x_1$ is positive. If the derivative is positive everywhere, then $f'(c) > 0$ too, the product is positive and $f(x_2) > f(x_1)$: a larger argument gives a larger value, which is what increasing means. For $f' < 0$ the product is negative, and the function decreases. For $f' = 0$ we get $f(x_2) = f(x_1)$ for any two points: the function is constant.
The last statement looks obvious: if the speed is zero all the time, the car is standing still. But it can’t be proved without Lagrange’s theorem, and it’s needed in analysis all the time. For example, it says that two functions with equal derivatives differ by a constant: the derivative of their difference is zero. This idea will become the main one in the chapter on the integral.
The jury’s report: the shape of the graph
One answer isn’t enough for the jury; it wants to know why it’s the best. Let’s collect the rules by which derivatives describe the shape of a graph: where it rises, where it turns and which way it bends.
Let $f$ be continuous at a point $c$ and differentiable near it. If the derivative changes sign from plus to minus as we pass through $c$, then $c$ is a local maximum; from minus to plus, a local minimum. If the sign doesn’t change, there’s no extremum.
Let the derivative be positive to the left of $c$ and negative to the right. By the test for monotonicity the function increases to the left of $c$, so for $x < c$ we have $f(x) < f(c)$: the values grow as they approach $f(c)$, and by continuity $f(c)$ is the limit of these values and larger than each of them. To the right of $c$ the function decreases, and for $x > c$ also $f(x) < f(c)$. So near $c$ all the values are less than $f(c)$: that’s a maximum. For a change from minus to plus the argument is the mirror image. If the sign is the same on both sides, the function is monotonic in the same direction on both sides of $c$, and $f(c)$ lies between the neighbouring values rather than above or below them all.
Let’s check on the cubic $f(x) = x^3 - 3x$. The derivative $f'(x) = 3x^2 - 3 = 3(x - 1)(x + 1)$ is positive for $x < -1$, negative between $-1$ and $1$, and positive again for $x > 1$. So there’s a maximum at $-1$, $f(-1) = 2$, and a minimum at $1$, $f(1) = -2$. The largest value on a closed interval is found like this: find the critical points inside, compute the values there and at the ends, and choose the largest. The rulebook is short, but it works for any continuous function with finitely many critical points: by the extreme value theorem the largest value exists, and by Fermat’s theorem it’s either at an end or at a critical point.
Find the largest value of $f(x) = x^3 - 3x$ on the interval $[0, 2]$.
The critical points: $f'(x) = 3(x - 1)(x + 1) = 0$ at $x = \pm 1$, and only $x = 1$ is in the interval. The values: $f(0) = 0$, $f(1) = -2$, $f(2) = 8 - 6 = 2$. The largest is $2$, at the right end. The critical point $x = 1$ turned out to be a minimum, so looking for the answer only among the zeros of the derivative would have been a mistake.
The derivative of the derivative is called the second derivative and written $f''(x)$. If the first derivative is velocity, the second is acceleration: how fast the slope is changing. For $x^3 - 3x$ the second derivative is $6x$.
A function is convex on an interval if every chord of its graph on that interval lies on or above the graph itself: the graph looks like a cup, as $y = x^2$ does. A function is concave if its chords lie on or below the graph: it looks like a cap, as $y = -x^2$ does. (Schoolbooks sometimes say “concave up” and “concave down”.) A point where the direction of bending changes is called a point of inflection.
If $f''(x) > 0$ on an interval, then $f$ is convex on it, and the graph lies above each of its tangents (except at the point of contact). If $f''(x) < 0$, then $f$ is concave and lies below its tangents.
Let $f'' > 0$. Then, by the test for monotonicity applied to $f'$, the first derivative is increasing. Compare the graph with the tangent at a point $a$: the difference $f(x) - f(a) - f'(a)(x - a)$ equals, by Lagrange’s theorem, $f'(c)(x - a) - f'(a)(x - a) = (f'(c) - f'(a))(x - a)$, where $c$ lies between $a$ and $x$. For $x > a$ the point $c$ is to the right of $a$, the derivative has grown, $f'(c) - f'(a) > 0$, and both factors are positive. For $x < a$ both factors are negative. In both cases the difference is positive: the graph is above the tangent. The condition on chords follows. Take the chord between points $p < q$ and any point $a$ between them. The tangent at $a$ runs below the graph, including below the ends of the chord; the chord joins two points lying above the tangent, so at the point $a$ it’s above the tangent too, that is, above $f(a)$. For $f'' < 0$ all the inequalities are reversed.
If $f'(c) = 0$ and $f''(c) > 0$, then $c$ is a local minimum; if $f'(c) = 0$ and $f''(c) < 0$, a local maximum.
Let $f''(c) > 0$. By the definition of the second derivative $\frac{f'(x) - f'(c)}{x - c} \to f''(c) > 0$, so for $x$ close enough to $c$ this fraction is positive: near a positive limit the values are positive too. Since $f'(c) = 0$, the fraction equals $\frac{f'(x)}{x - c}$. So for $x < c$ the derivative $f'(x)$ is negative, and for $x > c$ positive: it changes sign from minus to plus, and by the sufficient condition there’s a minimum at $c$. The case $f''(c) < 0$ is the mirror image. But if $f''(c) = 0$, the theorem says nothing: for $x^4$, $-x^4$ and $x^3$ at zero $f' = f'' = 0$, yet in the first case there’s a minimum, in the second a maximum, and in the third no extremum.
For $x^3 - 3x$ the second derivative $6x$ is negative at $-1$ (a maximum, a cap), positive at $1$ (a minimum, a cup), and changes sign at zero: that’s a point of inflection, where the curve turns from a cap into a cup. The trainer has three levels: critical points, points of maximum and minimum, and the largest and smallest values on an interval. If you need the full picture of a graph with asymptotes and convexity, the solver will help.
Task three: the lifeguard
A lifeguard stands on the sand $18$ metres from the water’s edge. In the sea, $16$ metres out and $46$ metres further along the beach, someone is drowning. Run in a straight line? Then there’s too much swimming, and a person swims several times slower than they run. Run along the sand to the point directly opposite the swimmer? Then there’s too much running. The best route is somewhere in between, and it bends at the water’s edge.
In 2003 the American mathematician Timothy Pennings published a paper in the College Mathematics Journal with a question for a title: “Do Dogs Know Calculus?” His Welsh corgi Elvis, on the shore of Lake Michigan, didn’t chase a ball thrown into the water in a straight line: he ran along the sand and leapt into the water at some point. Pennings measured the speeds (about $6.4$ m/s on sand and about $0.9$ m/s swimming), calculated the optimal point of entry, and compared it with where Elvis actually jumped. The agreement was astonishingly good. The dog, of course, didn’t compute any derivatives, but he did solve the problem.
Let’s do the calculation. Let the lifeguard $L$ be at distance $a$ from the shore, the swimmer $S$ at distance $b$, with $d$ between them along the shore. If you enter the water at the point $P$, a distance $x$ from the point of the shore nearest the lifeguard, then by Pythagoras’ theorem the run takes $\frac{\sqrt{a^2 + x^2}}{v_1}$ and the swim $\frac{\sqrt{b^2 + (d - x)^2}}{v_2}$, where $v_1$ and $v_2$ are the speeds on land and in water. We need the smallest value of the sum
$$T(x) = \frac{\sqrt{a^2 + x^2}}{v_1} + \frac{\sqrt{b^2 + (d - x)^2}}{v_2}.$$The function $T(x)$ has exactly one point of minimum on the interval $[0, d]$, and there $\frac{\sin\alpha}{v_1} = \frac{\sin\beta}{v_2}$, where $\alpha$ and $\beta$ are the angles the path on land and in water makes with the perpendicular to the shore.
The idea: the derivative of each leg of the route with respect to the position of $P$ turns out to be the sine of an angle, a ratio of sides in a right triangle.
Task four: the can
A canning factory wants a $330$ ml can, $V = 330$ cm³, using as little tin as possible. A can is a cylinder with base radius $r$ and height $h$. The tin goes into two discs (the base and the lid) and the side wall, whose unrolled shape is a $2\pi r \times h$ rectangle:
$$S = 2\pi r^2 + 2\pi r h.$$There are two variables here, but they’re linked: the volume $\pi r^2 h = V$ is fixed, so $h = \frac{V}{\pi r^2}$. Substitute and we get a function of one variable, $S(r) = 2\pi r^2 + \frac{2V}{r}$ for $r > 0$. Its derivative $S'(r) = 4\pi r - \frac{2V}{r^2}$ vanishes when $r^3 = \frac{V}{2\pi}$. To the left of this point $S' < 0$, to the right $S' > 0$: it’s a minimum, and the smallest value on the whole ray $r > 0$, because to the left the function decreases and to the right it increases. The most interesting thing is the height at the optimum:
$$h = \frac{V}{\pi r^2} = \frac{2\pi r^3}{\pi r^2} = 2r.$$The cheapest can is the one whose height equals its diameter: in profile it looks like a square. For $330$ ml we get $r \approx 3.74$ cm and $h \approx 7.5$ cm, and such a can takes about $264$ cm² of tin.
Look in the fridge: an ordinary $330$ ml can is about $6.6$ cm across and $11.5$ cm tall, noticeably taller than the “square” one. The engineers haven’t made a mistake; their problem is just different. The base and lid of an aluminium can are two to three times thicker than the thin wall: the lid has to hold the pressure of a fizzy drink and carry the ring pull. If a square centimetre of the ends costs $k$ times as much as the wall, the same calculation gives $h = 2kr$: the dearer the lids, the more a tall, narrow can pays off. And a can has to be comfortable to hold in the hand. The derivative honestly solves the problem it’s given, so setting the problem right is half the invention.
An open-topped tank with a square base and a volume of $32$ dm³ is to be made from as little metal as possible. What should the side of the base be (in decimetres)?
Let the side of the base be $x$ and the height $y$; then $x^2 y = 32$ and $y = \frac{32}{x^2}$. The metal: the base $x^2$ and four walls $4xy$, in all $S(x) = x^2 + \frac{128}{x}$. The derivative $S'(x) = 2x - \frac{128}{x^2}$ is zero at $x^3 = 64$, that is, $x = 4$; to the left it’s negative, to the right positive, so it’s a minimum. The tank is $4 \times 4 \times 2$ dm: without a lid it comes out half as tall as it is wide.
Task five: a root without the key
The last task is an invention for a calculator. It has four operations and no square-root key. How do you find $\sqrt2$, that is, the root of the equation $x^2 - 2 = 0$? The idea comes from the magnifying glass of the last chapter: near any point the graph almost coincides with its tangent. Finding where a curve crosses the axis is hard; finding where a line crosses it is easy. Replace the curve with its tangent, find where the tangent crosses the axis, and repeat from the new point.
The tangent to the graph $y = f(x)$ at the point $x_n$ is the line $y = f(x_n) + f'(x_n)(x - x_n)$. It crosses the $x$-axis where $y = 0$, that is, at $x = x_n - \frac{f(x_n)}{f'(x_n)}$. That’s the next approximation.
This is the very Babylonian method, or Heron’s method, from the chapter on the square root of two: there we got it from rectangles and proved that the error is roughly squared at each step. Now it’s clear where it comes from, and how to build the same kind of recipe for any equation. For $\sqrt[3]{2}$ take $f(x) = x^3 - 2$ and get $x_{n+1} = \frac{2x_n^3 + 2}{3x_n^2}$. For the equation $\cos x = x$, which no formula solves, take $f(x) = \cos x - x$, and in four steps from $x_0 = 1$ you find the root $0.7390851\ldots$ Quadratic convergence is a general property of the method.
Let $f(r) = 0$, and on an interval $I$ around $r$ let $|f'(x)| \ge m > 0$ and $|f''(x)| \le M$. If the approximation $x_n$ lies in $I$, the next approximation satisfies $|x_{n+1} - r| \le \frac{M}{m}\,|x_n - r|^2$.
The idea: apply Lagrange’s theorem twice. By the method’s formula $x_{n+1} - r = x_n - r - \frac{f(x_n)}{f'(x_n)} = \frac{f'(x_n)(x_n - r) - f(x_n)}{f'(x_n)}$. Since $f(r) = 0$, by Lagrange’s theorem $f(x_n) = f(x_n) - f(r) = f'(c)(x_n - r)$ for some point $c$ between $r$ and $x_n$. Substitute: the numerator is $\bigl(f'(x_n) - f'(c)\bigr)(x_n - r)$. Apply Lagrange’s theorem again, now to the function $f'$ on the interval between $c$ and $x_n$: $f'(x_n) - f'(c) = f''(d)(x_n - c)$, and $|f''(d)| \le M$. The point $c$ lies between $r$ and $x_n$, so $|x_n - c| \le |x_n - r|$. Putting it together: $|x_{n+1} - r| \le \frac{M \cdot |x_n - r| \cdot |x_n - r|}{m}$, as required.
If the error is already less than $\frac{m}{M} \cdot 10^{-k}$, the next one will be less than $\frac{m}{M} \cdot 10^{-2k}$: the number of correct digits roughly doubles. Near a root Newton’s method is one of the fastest known ways of solving equations, and calculators and computers use it or its relatives.
The theorem’s conditions aren’t a formality. Start the method for $x^3 - 2x + 2 = 0$ at zero: the tangent leads to one, and from one back to zero, and so on for ever. For $\arctan x = 0$ from the point $x_0 = 1.5$ the tangents lead further and further away with each step: the theorem promises success only near the root, and how near isn’t always clear in advance. In practice Newton’s method is often combined with the reliable but slow bisection from the chapter on limits.
A patent dispute
Every inventors’ contest has its patent disputes, and calculus is no exception. In 1696 the first textbook of the differential calculus came out in Paris, Analysis of the Infinitely Small for the Understanding of Curved Lines. Its author was given as the Marquis Guillaume de l’Hôpital. The marquis was an able mathematician, and in the preface he thanked Leibniz and the Bernoulli brothers. After his death Johann Bernoulli claimed that most of the book was his own work, and he wasn’t much believed. Correspondence published in the twentieth century showed that Bernoulli was telling the truth: under an agreement of 1694 he sent the marquis his discoveries in return for an annual salary, and the marquis could do with them as he pleased. The most famous of them has gone down in history under l’Hôpital’s name. It helps compute limits of the form “zero over zero”.
Let $f(a) = g(a) = 0$, let $f$ and $g$ be differentiable at the point $a$, and let $g'(a) \ne 0$. Then $\lim\limits_{x \to a} \dfrac{f(x)}{g(x)} = \dfrac{f'(a)}{g'(a)}$.
The idea: near $a$ both functions almost coincide with their tangents, and the tangents pass through $(a, 0)$, so the ratio of the functions is almost the ratio of the slopes. Rigorously: since $f(a) = g(a) = 0$, for $x \ne a$ we can write $\frac{f(x)}{g(x)} = \frac{f(x) - f(a)}{g(x) - g(a)} = \frac{(f(x) - f(a))/(x - a)}{(g(x) - g(a))/(x - a)}$. As $x \to a$ the numerator tends to $f'(a)$ and the denominator to $g'(a) \ne 0$, and the limit of a quotient is the quotient of the limits. Note that the denominator $g(x)$ doesn’t vanish for $x$ close to $a$: otherwise the fraction $\frac{g(x) - g(a)}{x - a}$ would be zero arbitrarily close to $a$ and couldn’t tend to $g'(a) \ne 0$.
For example, $\lim\limits_{x \to 1} \frac{\ln x}{x - 1} = \frac{1/1}{1} = 1$, and $\lim\limits_{x \to 2} \frac{x^3 - 8}{x - 2} = \frac{3 \cdot 4}{1} = 12$. There’s also a stronger version: if $f$ and $g$ tend to zero and the limit of the ratio of the derivatives $\frac{f'(x)}{g'(x)}$ exists, then $\frac{f(x)}{g(x)}$ tends to the same number. It’s proved through a generalisation of Lagrange’s theorem, Cauchy’s mean value theorem, and it works even when $f'(a)$ and $g'(a)$ don’t exist or are zero. That’s covered in the chapter on rigorous analysis.
Can the limit $\lim\limits_{x \to 0} \frac{x + 1}{x + 2}$ be found by l’Hôpital’s rule?
At zero the numerator is $1$ and the denominator $2$, the function is continuous, and the limit is $\frac12$. L’Hôpital’s rule applies only to indeterminate forms. A similar trap is to “prove” by l’Hôpital that $\frac{\sin x}{x} \to 1$: that needs the derivative of the sine at zero, which in the last chapter we derived precisely from this limit. The argument goes round in a circle.
Where next
All the problems in this chapter went one way: we know a function, we find its rate of change, and from the rate, where the function is largest. Life often poses the reverse problem. A dashcam recorded the speedometer readings for the whole trip: at every moment we know the speed, but the odometer is broken. How far did the car go? If the speed were constant, a multiplication would do. But the needle was moving all the time. Lagrange’s theorem has already hinted that a function is determined by its derivative up to a constant; what remains is to learn how to recover it. That’s the job of the chapter on the integral.