Ran Wei/ Calculus/Module 8
中文
Calculus · Part II · Derivatives

Module 8The shape of a graph and optimisation

Use derivatives to find the largest and smallest values of a function, to see where its graph rises, falls and bends, and to solve optimisation problems from geometry, physics and economics. You will prove the Mean Value Theorem and the tests that rest on it, sketch graphs from their derivatives, and minimise a function the way machine learning does, by gradient descent.

⏱ 270 minYou need: Modules 1 to 7, in particular the Intermediate and Extreme Value Theorems and asymptotes (Module 3), the rules of differentiation (Modules 4 to 6) and linearisation (Module 7)

In this module you will

  • Find the absolute extreme values of a continuous function on a closed interval with the closed interval method
  • Prove Rolle’s theorem and the Mean Value Theorem, and use them to prove the tests for increasing and constant functions
  • Classify critical numbers with the first and second derivative tests, and find intervals of concavity and inflection points
  • Sketch a graph from its domain, intercepts, symmetry, asymptotes and the signs of its first and second derivatives
  • Solve optimisation problems, and justify that the answer is an absolute maximum or minimum
  • Minimise a function by gradient descent, and explain how the step size decides whether it converges
1

Maximum and minimum values

Many questions ask for a best value. What shape of can holds a given volume with the least metal? Which path does light take between two points? How many units should a factory make to keep the cost of each unit as low as possible? Which setting of a machine-learning model makes its error smallest? Each question asks for the largest or the smallest value of a function, and derivatives answer it. Example 4.8 found the horizontal tangents of a graph by solving f′(x)=0.f'(x) = 0\mathclose{\text{.}} This module shows why that finds the peaks and the valleys, and what the signs of f′f' and f′′f'' say about the whole shape of a graph.

Figure 8.1 shows a function on the interval [−1,5.5].[-1, 5.5]\mathclose{\text{.}} Its highest point is at the left end; its lowest point is at x=5,x = 5\mathclose{\text{,}} where the tangent is horizontal. In between, the peak at x=2x = 2 and the valley at x=0x = 0 are the highest and lowest points near them, but not of the whole graph; there too the tangent is horizontal.

The graph of f(x) = tfrac14x^4 - tfrac73x^3 + 5x^2 on [-1, 5.5]. The largest value is at the endpoint x = -1, the smallest at x = 5; the peak at x = 2 and the valley at x = 0 are only local. At the three points inside the interval the tangent (dashed) is horizontal; at the endpoints it need not be.
Figure 8.1

The graph of f(x)=14x4−73x3+5x2f(x) = \tfrac14x^4 - \tfrac73x^3 + 5x^2 on [−1,5.5].[-1, 5.5]\mathclose{\text{.}} The largest value is at the endpoint x=−1,x = -1\mathclose{\text{,}} the smallest at x=5;x = 5\mathclose{\text{;}} the peak at x=2x = 2 and the valley at x=0x = 0 are only local. At the three points inside the interval the tangent (dashed) is horizontal; at the endpoints it need not be.

Definition 8.1Absolute and local extrema

Let cc be a number in the domain DD of a function f.f\mathclose{\text{.}}

  • f(c)f(c) is the absolute maximum value of ff if f(c)≥f(x)f(c) \ge f(x) for every xx in D,D\mathclose{\text{,}} and the absolute minimum value if f(c)≤f(x)f(c) \le f(x) for every xx in D.D\mathclose{\text{.}}
  • f(c)f(c) is a local maximum value of ff if f(c)≥f(x)f(c) \ge f(x) for every xx in some open interval that contains cc and lies in D,D\mathclose{\text{,}} and a local minimum value if f(c)≤f(x)f(c) \le f(x) for every xx in such an interval.

Maximum and minimum values are extreme values, or extrema (singular extremum). The absolute maximum value of ff on an interval II is the absolute maximum value of ff with its domain cut down to I,I\mathclose{\text{,}} and similarly for the others.

Absolute extrema are also called global. The maximum value on an interval of Module 3 is the absolute maximum on that interval. “Local” means “compared with the points on both sides”, so in this series an endpoint of the domain is never a local extremum; some books allow it, so check the convention when you read elsewhere.

Some examples. x2x^2 has the absolute minimum value 0, at 0, which is also a local minimum; it has no maximum value. x3x^3 has no extremum at all: every interval around a number cc contains points where x3x^3 is larger than c3c^3 and points where it is smaller. cos⁡x\cos x has the absolute maximum value 1, at x=0,±2π,±4π,…,x = 0, \pm2\pi, \pm4\pi, \dots\mathclose{\text{,}} and the absolute minimum value −1,-1\mathclose{\text{,}} at x=±π,±3π,…;x = \pm\pi, \pm3\pi, \dots\mathclose{\text{;}} these are local extrema too. In Figure 8.1, the absolute maximum value is f(−1)=9112≈7.58,f(-1) = \tfrac{91}{12} \approx 7.58\mathclose{\text{,}} which is not a local maximum, since −1-1 is an endpoint; f(5)=−12512≈−10.42f(5) = -\tfrac{125}{12} \approx -10.42 is the absolute minimum and a local minimum; f(2)=163f(2) = \tfrac{16}{3} is a local maximum and f(0)=0f(0) = 0 a local minimum.

Every local extremum in Figure 8.1 sits where the tangent is horizontal. That is no accident.

Theorem 8.1Fermat’s theorem

If ff has a local maximum or a local minimum at c,c\mathclose{\text{,}} and f′(c)f'(c) exists, then f′(c)=0.f'(c) = 0\mathclose{\text{.}}

Proof

Suppose first that f(c)f(c) is a local maximum value: f(x)≤f(c)f(x) \le f(c) for every xx in an open interval around c.c\mathclose{\text{.}} For every h≠0h \ne 0 small enough that c+hc + h lies in that interval, f(c+h)−f(c)≤0,f(c + h) - f(c) \le 0\mathclose{\text{,}} so the difference quotient

f(c+h)−f(c)h\frac{f(c + h) - f(c)}{h}

is ≤0\le 0 when h>0h > 0 and ≥0\ge 0 when h<0.h < 0\mathclose{\text{.}} As h→0h \to 0 it tends to f′(c).f'(c)\mathclose{\text{.}} If f′(c)f'(c) were positive, then for all small enough hh the quotients would lie within f′(c)/2f'(c)/2 of f′(c),f'(c)\mathclose{\text{,}} so they would be positive; but they are not, for h>0.h > 0\mathclose{\text{.}} If f′(c)f'(c) were negative, the quotients with small h<0h < 0 would be negative, which they are not either. So f′(c)=0.f'(c) = 0\mathclose{\text{.}} If f(c)f(c) is a local minimum value, −f-f has a local maximum at c,c\mathclose{\text{,}} and the first part gives −f′(c)=0.-f'(c) = 0\mathclose{\text{.}}

∎
Watch out

Fermat’s theorem says only this: at a local extremum where f′f' exists, f′=0.f' = 0\mathclose{\text{.}} It does not work backwards, and it says nothing where its hypotheses fail.

  • A horizontal tangent without an extremum. For f(x)=x3,f(x) = x^3\mathclose{\text{,}} f′(0)=0,f'(0) = 0\mathclose{\text{,}} but there is no extremum at 0, as above.
  • An extremum without a derivative. ∣x∣\abs{x} has its absolute minimum at 0, where it has no derivative (Module 4).
  • An extremum at an endpoint. On [0,1],[0, 1]\mathclose{\text{,}} f(x)=xf(x) = x has its absolute maximum at 1, where the slope is 1. An endpoint is not a local extremum, so the theorem does not apply there.

So the candidates for local extrema are the points where f′=0f' = 0 and the points where f′f' does not exist.

Definition 8.2Critical number

A critical number of ff is a number cc in the domain of ff at which f′(c)=0f'(c) = 0 or f′(c)f'(c) does not exist.

Some books say critical point. In these words, Fermat’s theorem says: every local extremum is at a critical number. Not every critical number gives an extremum (x3x^3 at 0 does not), so the critical numbers are only the candidates.

Example 8.1Critical numbers✓ Checked

Find the critical numbers of (a) f(x)=2x3−3x2−12x+1f(x) = 2x^3 - 3x^2 - 12x + 1 and (b) g(x)=x2/3(x−5),g(x) = x^{2/3}(x - 5)\mathclose{\text{,}} where x2/3=(x3)2x^{2/3} = \big(\sqrt[3]{x}\big)^2 with the real cube root, as in Module 4.

(a) ff is a polynomial, differentiable everywhere, so its critical numbers are the solutions of f′(x)=0:f'(x) = 0\mathclose{\text{:}}

f′(x)=6x2−6x−12=6(x2−x−2)=6(x−2)(x+1).\begin{aligned} f'(x) &= 6x^2 - 6x - 12 \\ &= 6(x^2 - x - 2) = 6(x - 2)(x + 1). \end{aligned}

The critical numbers are −1-1 and 2.2\mathclose{\text{.}}

(b) Multiply out, g(x)=x5/3−5x2/3,g(x) = x^{5/3} - 5x^{2/3}\mathclose{\text{,}} and use the power rule for real exponents (Module 6), which holds for powers of the real cube root at every x≠0:x \ne 0\mathclose{\text{:}}

g′(x)=53x2/3−103x−1/3=53x−1/3(x−2)=5(x−2)3x3,x≠0.\begin{aligned} g'(x) &= \tfrac53 x^{2/3} - \tfrac{10}{3}x^{-1/3} \\ &= \tfrac53 x^{-1/3}(x - 2) = \frac{5(x - 2)}{3\sqrt[3]{x}}, \quad x \ne 0. \end{aligned}

(To factor, write x2/3=x−1/3⋅x.)x^{2/3} = x^{-1/3}\cdot x\mathclose{\text{.)}} So g′(x)=0g'(x) = 0 at x=2.x = 2\mathclose{\text{.}} At 0, gg is defined, g(0)=0,g(0) = 0\mathclose{\text{,}} but g′(0)g'(0) does not exist: the difference quotient

g(h)−g(0)h=h2/3(h−5)h=h−5h3\frac{g(h) - g(0)}{h} = \frac{h^{2/3}(h - 5)}{h} = \frac{h - 5}{\sqrt[3]{h}}

tends to −∞-\infty as h→0+h \to 0^+ and to ∞\infty as h→0−:h \to 0^-\mathclose{\text{:}} a cusp like that of x2/3x^{2/3} in Module 4, but pointing upwards. The critical numbers of gg are 0 and 2.

The closed interval method

The Extreme Value Theorem of Module 3 promised that a function continuous on a closed interval [a,b][a, b] has an absolute maximum value and an absolute minimum value there. Fermat’s theorem says where to look for them.

Theorem 8.2The closed interval method

Let ff be continuous on a closed interval [a,b].[a, b]\mathclose{\text{.}} Then ff has an absolute maximum value and an absolute minimum value on [a,b],[a, b]\mathclose{\text{,}} and each of them is a value of ff at an endpoint, aa or b,b\mathclose{\text{,}} or at a critical number of ff in (a,b).(a, b)\mathclose{\text{.}}

Proof

By the Extreme Value Theorem, ff takes its absolute maximum value on [a,b][a, b] at some cc in [a,b].[a, b]\mathclose{\text{.}} If cc is aa or b,b\mathclose{\text{,}} there is nothing more to prove. Otherwise a<c<b,a < c < b\mathclose{\text{,}} and f(c)≥f(x)f(c) \ge f(x) for every xx in the open interval (a,b),(a, b)\mathclose{\text{,}} which contains c,c\mathclose{\text{,}} so f(c)f(c) is a local maximum value. If f′(c)f'(c) does not exist, cc is a critical number; if it exists, it is 0 by Fermat’s theorem, and cc is a critical number again. The same argument works for the minimum.

∎
Key idea

The closed interval method. To find the absolute maximum and minimum values of a continuous function ff on [a,b]:[a, b]\mathclose{\text{:}}

  1. Find the critical numbers of ff in (a,b).(a, b)\mathclose{\text{.}}
  2. Evaluate ff at each of them, and at aa and b.b\mathclose{\text{.}}
  3. The largest of these values is the absolute maximum value; the smallest is the absolute minimum value.

No test of the critical numbers is needed: you compare a short list of numbers.

Example 8.2The closed interval method✓ Checked

Find the absolute maximum and minimum values of (a) f(x)=2x3−3x2−12x+1f(x) = 2x^3 - 3x^2 - 12x + 1 on [−2,3][-2, 3] and (b) g(x)=x2/3(x−5)g(x) = x^{2/3}(x - 5) on [−1,4],[-1, 4]\mathclose{\text{,}} the functions of Example 8.1.

(a) ff is a polynomial, so it is continuous, and both of its critical numbers, −1-1 and 2, lie in (−2,3).(-2, 3)\mathclose{\text{.}} The values at them and at the endpoints:

xx −2-2 −1-1 22 33
f(x)f(x) −3-3 88 −19-19 −8-8

For instance f(−1)=−2−3+12+1=8.f(-1) = -2 - 3 + 12 + 1 = 8\mathclose{\text{.}} The absolute maximum value is 8, at x=−1,x = -1\mathclose{\text{,}} and the absolute minimum value is −19,-19\mathclose{\text{,}} at x=2;x = 2\mathclose{\text{;}} here both are inside the interval.

(b) The real cube root is continuous everywhere (Module 3), so gg is continuous on [−1,4],[-1, 4]\mathclose{\text{,}} and both of its critical numbers, 0 and 2, lie in (−1,4).(-1, 4)\mathclose{\text{.}} Since (−1)2/3=(−13)2=(−1)2=1,(-1)^{2/3} = \big(\sqrt[3]{-1}\big)^2 = (-1)^2 = 1\mathclose{\text{,}} 42/3=1634^{2/3} = \sqrt[3]{16} and 22/3=43:2^{2/3} = \sqrt[3]{4}\mathclose{\text{:}}

xx −1-1 00 22 44
g(x)g(x) −6-6 00 −343≈−4.762-3\sqrt[3]{4} \approx -4.762 −163≈−2.520-\sqrt[3]{16} \approx -2.520

The absolute maximum value is 0, at the cusp x=0,x = 0\mathclose{\text{,}} where g′g' does not exist; the absolute minimum value is −6,-6\mathclose{\text{,}} at the endpoint x=−1.x = -1\mathclose{\text{.}} Solving g′(x)=0g'(x) = 0 alone would have found neither.

Watch out

Three slips with the closed interval method. Forgetting the endpoints: the minimum in Example 8.2(b) is at one. Forgetting the points where f′f' does not exist: the maximum there is at one. And using critical numbers outside the interval: on [0,3][0, 3] the function of part (a) has only the critical number 2, its values f(0)=1,f(0) = 1\mathclose{\text{,}} f(2)=−19f(2) = -19 and f(3)=−8f(3) = -8 give the maximum value 1, and the number f(−1)=8f(-1) = 8 is not a value of ff on [0,3][0, 3] at all. Finally, the method needs a function continuous on a closed interval. 1/x1/x is not even defined at 0, which lies in [−1,1],[-1, 1]\mathclose{\text{,}} and it has no maximum value there: 1/x→∞1/x \to \infty as x→0+.x \to 0^+\mathclose{\text{.}}

Compute itThe closed interval method with SymPy

sp.solve(expr, x) returns a list of the solutions of the equation expr=0.\text{expr} = 0\mathclose{\text{.}} With it, the closed interval method for Example 8.2(a) takes a few lines:

Python
import sympy as sp
x = sp.symbols('x')
f = 2*x**3 - 3*x**2 - 12*x + 1
crit = sp.solve(sp.diff(f, x), x)       # where f'(x) = 0
print(crit)
for c in [-2] + crit + [3]:             # the critical numbers and the endpoints
    print(c, f.subs(x, c))
Output
[-1, 2]
-2 -3
-1 8
2 -19
3 -8

Both critical numbers lie in (−2,3);(-2, 3)\mathclose{\text{;}} in general, keep only those in the interval. Now part (b). Python, and SymPy too, take x2/3x^{2/3} of a negative number to be complex, as Section 1.7 showed for (−8)1/3,(-8)^{1/3}\mathclose{\text{,}} so write x2/3x^{2/3} as sp.cbrt(x**2), the cube root of x2≥0,x^2 \ge 0\mathclose{\text{,}} which is real for every x:x\mathclose{\text{:}}

Python
g = sp.cbrt(x**2)*(x - 5)
dg = sp.simplify(sp.diff(g, x))
print(dg)
print(sp.solve(dg, x), dg.subs(x, 0))
print(sp.N((x**sp.Rational(2, 3)*(x - 5)).subs(x, -1)), g.subs(x, -1))
Output
5*(x - 2)*(x**2)**(1/3)/(3*x)
[2] nan
3.0 - 5.19615242270663*I -6

SymPy’s derivative looks different from Example 8.1, but for x≠0,x \ne 0\mathclose{\text{,}} (x2)1/3/x=1/x3,(x^2)^{1/3}/x = 1/\sqrt[3]{x}\mathclose{\text{,}} so it is 5(x−2)3x3.\dfrac{5(x - 2)}{3\sqrt[3]{x}}\mathclose{\text{.}} solve finds the zero 2 of g′g' but not the critical number 0, where g′g' does not exist; substituting 0 gives nan. Look for the points where f′f' is undefined yourself. The last line shows the trap: x**sp.Rational(2, 3) at −1-1 is the complex number 3−5.196i,3 - 5.196i\mathclose{\text{,}} not g(−1)=−6.g(-1) = -6\mathclose{\text{.}}

2

The Mean Value Theorem

On some roads, speed is checked by average speed cameras. One camera records the time at which a car passes it, a second camera a known distance further on does the same, and the car’s average speed is the distance divided by the time. Suppose, hypothetically, that the cameras are 5 km apart, the limit is 80 km/h, and a car passes the second camera 3 minutes after the first. Its average speed is

5 km120 h=100 km/h.\frac{5 \text{ km}}{\tfrac{1}{20} \text{ h}} = 100 \text{ km/h}.

Its driver may protest that no camera saw them at 100 km/h. But at some instant between the cameras the speedometer did show exactly 100 km/h. The theorem that guarantees it, the Mean Value Theorem, connects an average rate of change with an instantaneous one, and it is the key to the rest of this module. Its special case comes first.

Theorem 8.3Rolle’s theorem

Let ff be continuous on [a,b][a, b] and differentiable on (a,b),(a, b)\mathclose{\text{,}} with f(a)=f(b).f(a) = f(b)\mathclose{\text{.}} Then there is a number cc in (a,b)(a, b) with f′(c)=0.f'(c) = 0\mathclose{\text{.}}

Proof

By the Extreme Value Theorem, ff has an absolute maximum value and an absolute minimum value on [a,b].[a, b]\mathclose{\text{.}} If both are taken at the endpoints, they are equal, since f(a)=f(b);f(a) = f(b)\mathclose{\text{;}} then the largest and the smallest values of ff on [a,b][a, b] are the same number, ff is constant, and f′(c)=0f'(c) = 0 for every cc in (a,b).(a, b)\mathclose{\text{.}} Otherwise one of them is taken at a point cc inside the interval. As in the proof of Theorem 8.2, f(c)f(c) is then a local extremum; f′(c)f'(c) exists, because ff is differentiable on (a,b);(a, b)\mathclose{\text{;}} so f′(c)=0f'(c) = 0 by Fermat’s theorem.

∎

In pictures (Figure 8.2, left): a smooth graph that starts and ends at the same height must turn round somewhere in between, and where it turns, its tangent is horizontal.

Left: Rolle's theorem for f(x) = x^3 - 3x on [a, b] = [-2, 1], where f(a) = f(b) = -2: the tangent at c = -1 is horizontal. Right: the Mean Value Theorem for the same function on [-2, 2]: the secant from (-2, -2) to (2, 2) has slope 1, and so have the tangents at c1 = -2/sqrt3 and c2 = 2/sqrt3. The Mean Value Theorem is Rolle's theorem tilted: the secant takes the place of the horizontal segment, and the tangents parallel to it the place of the horizontal tangent.
Figure 8.2

Left: Rolle’s theorem for f(x)=x3−3xf(x) = x^3 - 3x on [a,b]=[−2,1],[a, b] = [-2, 1]\mathclose{\text{,}} where f(a)=f(b)=−2:f(a) = f(b) = -2\mathclose{\text{:}} the tangent at c=−1c = -1 is horizontal. Right: the Mean Value Theorem for the same function on [−2,2]:[-2, 2]\mathclose{\text{:}} the secant from (−2,−2)(-2, -2) to (2,2)(2, 2) has slope 1, and so have the tangents at c1=−2/3c_1 = -2/\sqrt3 and c2=2/3.c_2 = 2/\sqrt3\mathclose{\text{.}} The Mean Value Theorem is Rolle’s theorem tilted: the secant takes the place of the horizontal segment, and the tangents parallel to it the place of the horizontal tangent.

Each hypothesis is needed. Without continuity on the closed interval: f(x)=xf(x) = x for 0≤x<10 \le x < 1 with f(1)=0f(1) = 0 has f(0)=f(1),f(0) = f(1)\mathclose{\text{,}} but f′(x)=1f'(x) = 1 on (0,1).(0, 1)\mathclose{\text{.}} Without differentiability: ∣x∣\abs{x} on [−1,1][-1, 1] has equal values at the ends, but its derivative is −1-1 or 1 wherever it exists. Without f(a)=f(b):f(a) = f(b)\mathclose{\text{:}} xx on [0,1][0, 1] has slope 1 everywhere.

Example 8.3Exactly one root✓ Checked

Show that the equation x5+3x−1=0x^5 + 3x - 1 = 0 has exactly one real solution.

Let f(x)=x5+3x−1,f(x) = x^5 + 3x - 1\mathclose{\text{,}} a polynomial, so continuous and differentiable everywhere.

At least one. f(0)=−1<0f(0) = -1 < 0 and f(1)=3>0,f(1) = 3 > 0\mathclose{\text{,}} so by the Intermediate Value Theorem (Module 3) there is a solution between 0 and 1.

At most one. Suppose there were two, r<s,r < s\mathclose{\text{,}} with f(r)=f(s)=0.f(r) = f(s) = 0\mathclose{\text{.}} By Rolle’s theorem on [r,s][r, s] there would be a cc between them with f′(c)=0.f'(c) = 0\mathclose{\text{.}} But f′(x)=5x4+3≥3f'(x) = 5x^4 + 3 \ge 3 for every x,x\mathclose{\text{,}} so f′f' is never 0. So there is exactly one solution; Newton’s method (Module 7) gives x≈0.33199.x \approx 0.33199\mathclose{\text{.}}

Now tilt the picture. In Figure 8.2, right, the ends of the graph are at different heights, and the secant line joining them has slope 1. Somewhere in between, at c1c_1 and at c2,c_2\mathclose{\text{,}} the tangent is parallel to the secant.

Theorem 8.4The Mean Value Theorem

Let ff be continuous on [a,b][a, b] and differentiable on (a,b).(a, b)\mathclose{\text{.}} Then there is a number cc in (a,b)(a, b) with

f′(c)=f(b)−f(a)b−a,f'(c) = \frac{f(b) - f(a)}{b - a},

that is, f(b)−f(a)=f′(c)(b−a).f(b) - f(a) = f'(c)(b - a)\mathclose{\text{.}}

Proof

Let m=f(b)−f(a)b−a,m = \dfrac{f(b) - f(a)}{b - a}\mathclose{\text{,}} the slope of the secant line, and let

h(x)=f(x)−(f(a)+m(x−a)),h(x) = f(x) - \big(f(a) + m(x - a)\big),

the height of the graph above the secant line. Like f,f\mathclose{\text{,}} hh is continuous on [a,b][a, b] and differentiable on (a,b),(a, b)\mathclose{\text{,}} because it is ff minus a linear function. At the ends, h(a)=0h(a) = 0 and h(b)=f(b)−f(a)−m(b−a)=0.h(b) = f(b) - f(a) - m(b - a) = 0\mathclose{\text{.}} By Rolle’s theorem there is a cc in (a,b)(a, b) with h′(c)=0.h'(c) = 0\mathclose{\text{.}} Since h′(c)=f′(c)−m,h'(c) = f'(c) - m\mathclose{\text{,}} this says f′(c)=m.f'(c) = m\mathclose{\text{.}}

∎

The mean in the name is the average: the average rate of change of ff over [a,b][a, b] equals its instantaneous rate of change at some point inside.

Example 8.4Average speed cameras✓ Checked

Prove the claim about the car that passed the two cameras, 5 km apart, 3 minutes apart.

Measure time tt in hours from the moment the car passes the first camera, and let s(t)s(t) be the distance in kilometres that it has travelled by then. So s(0)=0s(0) = 0 and s(120)=5.s\big(\tfrac{1}{20}\big) = 5\mathclose{\text{.}} A car does not jump, and its velocity s′(t)s'(t) exists at every instant (it is what the speedometer shows), so ss is continuous on [0,120]\big[0, \tfrac{1}{20}\big] and differentiable on (0,120).\big(0, \tfrac{1}{20}\big)\mathclose{\text{.}} By the Mean Value Theorem there is a time cc between 0 and 120\tfrac{1}{20} with

s′(c)=s(120)−s(0)120−0=51/20=100 km/h.s'(c) = \frac{s\big(\tfrac{1}{20}\big) - s(0)}{\tfrac{1}{20} - 0} = \frac{5}{1/20} = 100 \text{ km/h}.

At that instant the car was travelling at 100 km/h, 20 km/h over the limit. The theorem does not say when; it says that the instant exists.

Watch out

The Mean Value Theorem says that a suitable cc exists, not where it is, and there may be several: two in Figure 8.2. And it needs its hypotheses. On [−1,2],[-1, 2]\mathclose{\text{,}} ∣x∣\abs{x} has secant slope 2−12−(−1)=13,\dfrac{2 - 1}{2 - (-1)} = \dfrac13\mathclose{\text{,}} but its derivative is −1-1 or 1 wherever it exists, never 13:\tfrac13\mathclose{\text{:}} ∣x∣\abs{x} is not differentiable at 0, inside the interval.

Consequences

The Mean Value Theorem turns information about f′f' into information about f.f\mathclose{\text{.}} The first consequence: a function whose derivative is 0 everywhere on an interval does not change. Read as a statement about motion, it says that an object whose velocity is 0 throughout a time interval does not move; but even this needs a proof, and the proof needs the Mean Value Theorem.

Theorem 8.5Functions with zero derivative

If f′(x)=0f'(x) = 0 for every xx in an open interval I,I\mathclose{\text{,}} then ff is constant on I.I\mathclose{\text{.}}

Proof

Let x1<x2x_1 < x_2 be two numbers in I.I\mathclose{\text{.}} Since ff is differentiable on I,I\mathclose{\text{,}} it is continuous on [x1,x2][x_1, x_2] (Theorem 4.1) and differentiable on (x1,x2).(x_1, x_2)\mathclose{\text{.}} By the Mean Value Theorem, f(x2)−f(x1)=f′(c)(x2−x1)f(x_2) - f(x_1) = f'(c)(x_2 - x_1) for some cc between them, and f′(c)=0.f'(c) = 0\mathclose{\text{.}} So f(x1)=f(x2):f(x_1) = f(x_2)\mathclose{\text{:}} any two values of ff on II are equal.

∎
Theorem 8.6Functions with equal derivatives

If f′(x)=g′(x)f'(x) = g'(x) for every xx in an open interval I,I\mathclose{\text{,}} then f−gf - g is constant on I:I\mathclose{\text{:}} there is a number CC with f(x)=g(x)+Cf(x) = g(x) + C for every xx in I.I\mathclose{\text{.}}

Proof

(f−g)′=f′−g′=0(f - g)' = f' - g' = 0 on I,I\mathclose{\text{,}} so f−gf - g is constant on II by Theorem 8.5.

∎

So two functions with the same derivative on an interval differ by a constant: their graphs are vertical shifts of each other. Module 10 builds on this; it is why every antiderivative ends in “+ C+\,C”.

Example 8.5An identity from derivatives✓ Checked

Show that arcsin⁡x+arccos⁡x=π2\arcsin x + \arccos x = \dfrac{\pi}{2} for every xx in [−1,1].[-1, 1]\mathclose{\text{.}}

Let F(x)=arcsin⁡x+arccos⁡x.F(x) = \arcsin x + \arccos x\mathclose{\text{.}} For −1<x<1,-1 < x < 1\mathclose{\text{,}} the derivatives of Module 6 give

F′(x)=11−x2−11−x2=0,F'(x) = \frac{1}{\sqrt{1 - x^2}} - \frac{1}{\sqrt{1 - x^2}} = 0,

so by Theorem 8.5, FF is constant on (−1,1).(-1, 1)\mathclose{\text{.}} Its value at 0 is 0+π2,0 + \dfrac{\pi}{2}\mathclose{\text{,}} so F(x)=π2F(x) = \dfrac{\pi}{2} for −1<x<1.-1 < x < 1\mathclose{\text{.}} At the ends, F(1)=π2+0F(1) = \dfrac{\pi}{2} + 0 and F(−1)=−π2+π=π2.F(-1) = -\dfrac{\pi}{2} + \pi = \dfrac{\pi}{2}\mathclose{\text{.}} So F(x)=π2F(x) = \dfrac{\pi}{2} on all of [−1,1].[-1, 1]\mathclose{\text{.}} Module 6 proved the same identity from the addition formula; here a derivative of 0 proves it.

Watch out

The interval matters. Module 6 found that arctan⁡x+arctan⁡1x\arctan x + \arctan\dfrac1x has derivative 0 at every x≠0,x \ne 0\mathclose{\text{,}} yet it equals π2\dfrac{\pi}{2} for x>0x > 0 and −π2-\dfrac{\pi}{2} for x<0.x < 0\mathclose{\text{.}} Its domain, (−∞,0)∪(0,∞),(-\infty, 0) \cup (0, \infty)\mathclose{\text{,}} is two intervals, and Theorem 8.5 applies to each one separately, with a constant of its own.

Going deeperCauchy’s mean value theorem and the proof of L’Hôpital’s rule

Module 7 stated L’Hôpital’s rule in general, proved it only in its simple form, and promised the general proof here. It rests on a mean value theorem for two functions at once.

Theorem 8.7Cauchy’s mean value theorem

Let ff and gg be continuous on [a,b][a, b] and differentiable on (a,b).(a, b)\mathclose{\text{.}} Then there is a number cc in (a,b)(a, b) with

(f(b)−f(a))g′(c)=(g(b)−g(a))f′(c).\big(f(b) - f(a)\big)g'(c) = \big(g(b) - g(a)\big)f'(c).

If also g′(x)≠0g'(x) \ne 0 for every xx in (a,b),(a, b)\mathclose{\text{,}} then g(b)≠g(a),g(b) \ne g(a)\mathclose{\text{,}} and

f(b)−f(a)g(b)−g(a)=f′(c)g′(c).\frac{f(b) - f(a)}{g(b) - g(a)} = \frac{f'(c)}{g'(c)}.
Proof

Let h(x)=(f(b)−f(a))g(x)−(g(b)−g(a))f(x).h(x) = \big(f(b) - f(a)\big)g(x) - \big(g(b) - g(a)\big)f(x)\mathclose{\text{.}} It is continuous on [a,b][a, b] and differentiable on (a,b),(a, b)\mathclose{\text{,}} and multiplying out shows that h(a)=f(b)g(a)−f(a)g(b)=h(b).h(a) = f(b)g(a) - f(a)g(b) = h(b)\mathclose{\text{.}} By Rolle’s theorem, h′(c)=0h'(c) = 0 for some cc in (a,b),(a, b)\mathclose{\text{,}} which is the first equation. If g′≠0g' \ne 0 on (a,b),(a, b)\mathclose{\text{,}} then g(b)≠g(a),g(b) \ne g(a)\mathclose{\text{,}} since otherwise Rolle’s theorem would give a zero of g′;g'\mathclose{\text{;}} so you may divide by (g(b)−g(a))g′(c).\big(g(b) - g(a)\big)g'(c)\mathclose{\text{.}}

∎

With g(x)=xg(x) = x it is the Mean Value Theorem. Recall the general rule, as Theorem 7.5 states it: let ff and gg be differentiable on an open interval II containing a,a\mathclose{\text{,}} except possibly at a,a\mathclose{\text{,}} with g′(x)≠0g'(x) \ne 0 for x≠ax \ne a in I;I\mathclose{\text{;}} if f(x)/g(x)f(x)/g(x) has the form 0/00/0 or ∞/∞\infty/\infty as x→a,x \to a\mathclose{\text{,}} and f′(x)/g′(x)→L,f'(x)/g'(x) \to L\mathclose{\text{,}} a real number or ±∞,\pm\infty\mathclose{\text{,}} then f(x)/g(x)→L;f(x)/g(x) \to L\mathclose{\text{;}} and the same holds for one-sided limits and for x→±∞.x \to \pm\infty\mathclose{\text{.}}

Proof of L’Hôpital’s rule

The form 0/0,0/0\mathclose{\text{,}} from the right. Suppose that ff and gg are differentiable on (a,b),(a, b)\mathclose{\text{,}} g′≠0g' \ne 0 there, f(x)→0f(x) \to 0 and g(x)→0g(x) \to 0 as x→a+,x \to a^+\mathclose{\text{,}} and f′(x)/g′(x)→L.f'(x)/g'(x) \to L\mathclose{\text{.}} Give ff and gg the values f(a)=g(a)=0;f(a) = g(a) = 0\mathclose{\text{;}} this changes no limit as x→a+,x \to a^+\mathclose{\text{,}} and makes ff and gg continuous on [a,y][a, y] for every yy in (a,b).(a, b)\mathclose{\text{.}} By Cauchy’s theorem on [a,y],[a, y]\mathclose{\text{,}} there is a cyc_y with a<cy<ya < c_y < y and

f(y)g(y)=f(y)−f(a)g(y)−g(a)=f′(cy)g′(cy).\frac{f(y)}{g(y)} = \frac{f(y) - f(a)}{g(y) - g(a)} = \frac{f'(c_y)}{g'(c_y)}.

Let LL be a real number and ε>0.\varepsilon > 0\mathclose{\text{.}} There is a δ>0,\delta > 0\mathclose{\text{,}} with a+δ≤b,a + \delta \le b\mathclose{\text{,}} such that ∣f′(t)/g′(t)−L∣<ε\abs{f'(t)/g'(t) - L} < \varepsilon whenever a<t<a+δ.a < t < a + \delta\mathclose{\text{.}} For a<y<a+δ,a < y < a + \delta\mathclose{\text{,}} the number cyc_y lies in (a,a+δ)(a, a + \delta) too, so ∣f(y)/g(y)−L∣<ε;\abs{f(y)/g(y) - L} < \varepsilon\mathclose{\text{;}} that is, f(y)/g(y)→Lf(y)/g(y) \to L as y→a+.y \to a^+\mathclose{\text{.}} If L=∞,L = \infty\mathclose{\text{,}} the same argument with “f′(t)/g′(t)>Mf'(t)/g'(t) > M” in place of “∣f′(t)/g′(t)−L∣<ε\abs{f'(t)/g'(t) - L} < \varepsilon”, for an arbitrary M,M\mathclose{\text{,}} shows f(y)/g(y)>Mf(y)/g(y) > M for a<y<a+δ;a < y < a + \delta\mathclose{\text{;}} L=−∞L = -\infty is the same.

Other directions. From the left, use [y,a][y, a] in the same way. A two-sided limit is a pair of one-sided limits. For x→∞,x \to \infty\mathclose{\text{,}} with I=(b,∞),I = (b, \infty)\mathclose{\text{,}} where you may take b>0b > 0 by shrinking I,I\mathclose{\text{,}} put F(t)=f(1/t)F(t) = f(1/t) and G(t)=g(1/t)G(t) = g(1/t) for 0<t<1/b.0 < t < 1/b\mathclose{\text{.}} By the chain rule F′(t)=−f′(1/t)/t2F'(t) = -f'(1/t)/t^2 and G′(t)=−g′(1/t)/t2≠0,G'(t) = -g'(1/t)/t^2 \ne 0\mathclose{\text{,}} so F′(t)/G′(t)=f′(1/t)/g′(1/t)→LF'(t)/G'(t) = f'(1/t)/g'(1/t) \to L as t→0+,t \to 0^+\mathclose{\text{,}} and the case above gives F(t)/G(t)→L,F(t)/G(t) \to L\mathclose{\text{,}} which says that f(x)/g(x)→Lf(x)/g(x) \to L as x→∞.x \to \infty\mathclose{\text{.}} For x→−∞x \to -\infty use t=−1/x.t = -1/x\mathclose{\text{.}}

The form ∞/∞,\infty/\infty\mathclose{\text{,}} from the right, with LL real. Now ∣g(x)∣→∞\abs{g(x)} \to \infty as x→a+.x \to a^+\mathclose{\text{.}} Let 0<ε<1,0 < \varepsilon < 1\mathclose{\text{,}} choose δ\delta as before, and fix y=a+δy = a + \delta (shrinking δ\delta first if necessary, so that y<b).y < b\mathclose{\text{).}} For a<x<y,a < x < y\mathclose{\text{,}} Cauchy’s theorem on [x,y][x, y] gives a cc between xx and yy with

Q=f(x)−f(y)g(x)−g(y)=f′(c)g′(c),Q = \frac{f(x) - f(y)}{g(x) - g(y)} = \frac{f'(c)}{g'(c)},

so ∣Q−L∣<ε\abs{Q - L} < \varepsilon and ∣Q∣<∣L∣+1.\abs{Q} < \abs{L} + 1\mathclose{\text{.}} For xx so close to aa that g(x)≠0,g(x) \ne 0\mathclose{\text{,}} solving f(x)=Q(g(x)−g(y))+f(y)f(x) = Q\big(g(x) - g(y)\big) + f(y) for the ratio gives

f(x)g(x)−L=(Q−L)−Q g(y)g(x)+f(y)g(x).\frac{f(x)}{g(x)} - L = (Q - L) - Q\,\frac{g(y)}{g(x)} + \frac{f(y)}{g(x)}.

Since yy is fixed and ∣g(x)∣→∞,\abs{g(x)} \to \infty\mathclose{\text{,}} the last two fractions tend to 0 as x→a+;x \to a^+\mathclose{\text{;}} for xx close enough to aa each is smaller than ε\varepsilon in size, and then ∣f(x)/g(x)−L∣<ε+(∣L∣+1)ε+ε=(∣L∣+3)ε.\abs{f(x)/g(x) - L} < \varepsilon + (\abs{L} + 1)\varepsilon + \varepsilon = (\abs{L} + 3)\varepsilon\mathclose{\text{.}} As ε\varepsilon is arbitrary, f(x)/g(x)→L.f(x)/g(x) \to L\mathclose{\text{.}} If L=∞,L = \infty\mathclose{\text{,}} take an arbitrary M>0M > 0 and choose yy in (a,b)(a, b) so that f′(t)/g′(t)>2Mf'(t)/g'(t) > 2M for a<t<y;a < t < y\mathclose{\text{;}} then Q>2MQ > 2M for every xx in (a,y).(a, y)\mathclose{\text{.}} For xx close enough to a,a\mathclose{\text{,}} also 1−g(y)/g(x)>121 - g(y)/g(x) > \tfrac12 and ∣f(y)/g(x)∣<1,\abs{f(y)/g(x)} < 1\mathclose{\text{,}} so f(x)/g(x)=Q(1−g(y)/g(x))+f(y)/g(x)>M−1;f(x)/g(x) = Q\big(1 - g(y)/g(x)\big) + f(y)/g(x) > M - 1\mathclose{\text{;}} as MM is arbitrary, f(x)/g(x)→∞.f(x)/g(x) \to \infty\mathclose{\text{.}} If L=−∞,L = -\infty\mathclose{\text{,}} apply this to −f.-f\mathclose{\text{.}} The other directions follow as for 0/0.0/0\mathclose{\text{.}}

∎

The proof of the form ∞/∞\infty/\infty used only ∣g(x)∣→∞,\abs{g(x)} \to \infty\mathclose{\text{,}} not f(x)→±∞:f(x) \to \pm\infty\mathclose{\text{:}} the rule holds whenever ∣g(x)∣→∞\abs{g(x)} \to \infty and f′/g′f'/g' has a limit.

3

Increasing and decreasing functions

Module 4 observed that where a graph rises its tangents slope upwards, and promised a partial converse: where f′>0f' > 0 on an interval, ff rises. The Mean Value Theorem delivers it.

Definition 8.3Increasing and decreasing functions

A function ff is increasing on an interval II if f(x1)<f(x2)f(x_1) < f(x_2) whenever x1<x2x_1 < x_2 in I,I\mathclose{\text{,}} and decreasing on II if f(x1)>f(x2)f(x_1) > f(x_2) whenever x1<x2x_1 < x_2 in I.I\mathclose{\text{.}}

These are the definitions of Section 4.3. Some books call them strictly increasing and decreasing, and use “increasing” for the weaker f(x1)≤f(x2);f(x_1) \le f(x_2)\mathclose{\text{;}} this series follows Module 4.

Theorem 8.8The increasing/decreasing test

Let ff be continuous on an interval II and differentiable at every point of II that is not an endpoint of I.I\mathclose{\text{.}}

  • If f′(x)>0f'(x) > 0 at every such point, ff is increasing on I.I\mathclose{\text{.}}
  • If f′(x)<0f'(x) < 0 at every such point, ff is decreasing on I.I\mathclose{\text{.}}
Proof

Let x1<x2x_1 < x_2 be in I.I\mathclose{\text{.}} Then ff is continuous on [x1,x2][x_1, x_2] and differentiable on (x1,x2),(x_1, x_2)\mathclose{\text{,}} whose points are not endpoints of I.I\mathclose{\text{.}} By the Mean Value Theorem, f(x2)−f(x1)=f′(c)(x2−x1)f(x_2) - f(x_1) = f'(c)(x_2 - x_1) for some cc between x1x_1 and x2.x_2\mathclose{\text{.}} If f′>0,f' > 0\mathclose{\text{,}} both factors are positive, so f(x2)>f(x1).f(x_2) > f(x_1)\mathclose{\text{.}} If f′<0,f' < 0\mathclose{\text{,}} the product is negative, so f(x2)<f(x1).f(x_2) < f(x_1)\mathclose{\text{.}}

∎

The endpoints may belong to I:I\mathclose{\text{:}} x2x^2 is increasing on [0,∞),[0, \infty)\mathclose{\text{,}} since its derivative 2x2x is positive for x>0,x > 0\mathclose{\text{,}} although it is 0 at the endpoint 0. A single zero of f′f' inside an interval does not spoil the conclusion either: x3x^3 is increasing on (−∞,0](-\infty, 0] and on [0,∞),[0, \infty)\mathclose{\text{,}} so for x1<0<x2,x_1 < 0 < x_2\mathclose{\text{,}} x13<0<x23,x_1^3 < 0 < x_2^3\mathclose{\text{,}} and x3x^3 is increasing on all of R,\R\mathclose{\text{,}} although its derivative is 0 at 0. The same argument covers any finite number of zeros.

To use the test you need the intervals on which f′f' has one sign. If f′f' is continuous on an interval and never 0 there, it cannot change sign there, because by the Intermediate Value Theorem a change of sign would need a zero in between. Every derivative in this module is continuous wherever it exists, so it can change sign only at critical numbers and at points outside the domain of f.f\mathclose{\text{.}} Mark those points on the number line; they cut it into intervals, and the sign of f′f' at one test point of each interval is its sign on the whole interval. A table of these signs is a sign chart.

Good to know

Not every derivative is continuous. The function x2sin⁡(1/x)x^2\sin(1/x) of Exercise 4.11, with the value 0 at 0, has a derivative at every point; but for x≠0x \ne 0 its derivative is 2xsin⁡(1/x)−cos⁡(1/x),2x\sin(1/x) - \cos(1/x)\mathclose{\text{,}} which keeps swinging between values near −1-1 and near 1 as x→0,x \to 0\mathclose{\text{,}} so it is not continuous at 0.

Example 8.6Where a cubic rises and falls✓ Checked

Find where g(x)=2x3−9x2+12x−4g(x) = 2x^3 - 9x^2 + 12x - 4 is increasing and where it is decreasing.

Example 4.8 found g′(x)=6x2−18x+12=6(x−1)(x−2),g'(x) = 6x^2 - 18x + 12 = 6(x - 1)(x - 2)\mathclose{\text{,}} which is continuous and 0 only at 1 and 2. The sign chart reads the sign of g′g' from the signs of its factors:

Interval x−1x - 1 x−2x - 2 g′(x)g'(x) gg
x<1x < 1 −- −- ++ increasing
1<x<21 < x < 2 ++ −- −- decreasing
x>2x > 2 ++ ++ ++ increasing

Since gg is continuous, Theorem 8.8 lets you include the endpoints: gg is increasing on (−∞,1](-\infty, 1] and on [2,∞),[2, \infty)\mathclose{\text{,}} and decreasing on [1,2].[1, 2]\mathclose{\text{.}} In particular the graph falls all the way from (1,1)(1, 1) to (2,0),(2, 0)\mathclose{\text{,}} as Module 4 promised.

The first derivative test

In Example 8.6 the graph rises to x=1x = 1 and then falls: so g(1)g(1) is a local maximum. Then it falls to x=2x = 2 and rises again: g(2)g(2) is a local minimum. That reasoning works at every critical number.

Theorem 8.9The first derivative test

Let cc be a critical number of f,f\mathclose{\text{,}} let ff be continuous at c,c\mathclose{\text{,}} and let ff be differentiable on an open interval around c,c\mathclose{\text{,}} except possibly at cc itself.

  • If f′f' changes from positive to negative at cc (that is, f′(x)>0f'(x) > 0 for x<cx < c and f′(x)<0f'(x) < 0 for x>c,x > c\mathclose{\text{,}} in that interval), then f(c)f(c) is a local maximum value.
  • If f′f' changes from negative to positive at c,c\mathclose{\text{,}} then f(c)f(c) is a local minimum value.
  • If f′f' has the same sign on both sides of c,c\mathclose{\text{,}} then ff has no local extremum at c.c\mathclose{\text{.}}
Proof

Let the interval be (p,q).(p, q)\mathclose{\text{.}} Suppose f′>0f' > 0 on (p,c)(p, c) and f′<0f' < 0 on (c,q).(c, q)\mathclose{\text{.}} On (p,c],(p, c]\mathclose{\text{,}} ff is continuous (it is differentiable on (p,c)(p, c) and continuous at c),c\mathclose{\text{),}} so by Theorem 8.8 it is increasing there: f(x)<f(c)f(x) < f(c) for p<x<c.p < x < c\mathclose{\text{.}} In the same way ff is decreasing on [c,q):[c, q)\mathclose{\text{:}} f(x)<f(c)f(x) < f(c) for c<x<q.c < x < q\mathclose{\text{.}} So f(c)≥f(x)f(c) \ge f(x) on all of (p,q),(p, q)\mathclose{\text{,}} a local maximum. The second case is the same with the inequalities reversed. In the third, if f′>0f' > 0 on both sides, ff is increasing on (p,c](p, c] and on [c,q),[c, q)\mathclose{\text{,}} so for p<x<c<y<q,p < x < c < y < q\mathclose{\text{,}} f(x)<f(c)<f(y):f(x) < f(c) < f(y)\mathclose{\text{:}} every open interval around cc contains points where ff is smaller than f(c)f(c) and points where it is larger, and f(c)f(c) is not an extremum. The case f′<0f' < 0 is the same.

∎
Example 8.7A local maximum at a cusp✓ Checked

Find the local extreme values of g(x)=x2/3(x−5),g(x) = x^{2/3}(x - 5)\mathclose{\text{,}} the function of Examples 8.1 and 8.2.

Its critical numbers are 0 and 2, and g′(x)=5(x−2)3x3g'(x) = \dfrac{5(x - 2)}{3\sqrt[3]{x}} for x≠0.x \ne 0\mathclose{\text{.}} The cube root has the sign of x:x\mathclose{\text{:}}

Interval x−2x - 2 x3\sqrt[3]{x} g′(x)g'(x) gg
x<0x < 0 −- −- ++ increasing
0<x<20 < x < 2 −- ++ −- decreasing
x>2x > 2 ++ ++ ++ increasing

gg is continuous at 0, and g′g' changes from positive to negative there, so g(0)=0g(0) = 0 is a local maximum value, at a cusp where g′g' does not exist. At 2, g′g' changes from negative to positive, so g(2)=−343≈−4.762g(2) = -3\sqrt[3]{4} \approx -4.762 is a local minimum value.

The same reasoning proves inequalities that are hard to prove by algebra.

Example 8.8An inequality for exe^x✓ Checked

Show that ex≥1+xe^x \ge 1 + x for every real x,x\mathclose{\text{,}} with equality only at x=0.x = 0\mathclose{\text{.}}

Let f(x)=ex−1−x.f(x) = e^x - 1 - x\mathclose{\text{.}} Then f′(x)=ex−1.f'(x) = e^x - 1\mathclose{\text{.}} Since exe^x is increasing and e0=1,e^0 = 1\mathclose{\text{,}} f′(x)<0f'(x) < 0 for x<0x < 0 and f′(x)>0f'(x) > 0 for x>0.x > 0\mathclose{\text{.}} By Theorem 8.8, ff is decreasing on (−∞,0](-\infty, 0] and increasing on [0,∞),[0, \infty)\mathclose{\text{,}} so f(x)>f(0)=0f(x) > f(0) = 0 for every x≠0.x \ne 0\mathclose{\text{.}} That is, ex>1+xe^x > 1 + x for x≠0,x \ne 0\mathclose{\text{,}} and e0=1+0.e^0 = 1 + 0\mathclose{\text{.}} Geometrically, the graph of exe^x lies above its tangent line y=1+xy = 1 + x at 0, the linearisation of Module 7; Section 8.4 explains why.

Watch out

Two slips with sign charts. First, f′f' can also change sign at a point outside the domain, such as a vertical asymptote, and there is no extremum there: f(x)=1/x2f(x) = 1/x^2 has f′(x)=−2/x3,f'(x) = -2/x^3\mathclose{\text{,}} positive for x<0x < 0 and negative for x>0,x > 0\mathclose{\text{,}} but ff has no maximum, since 0 is not in its domain and f(x)→∞f(x) \to \infty as x→0.x \to 0\mathclose{\text{.}} Put such points on the chart, but never call them extrema. Second, “increasing on (−∞,0)(-\infty, 0) and on (0,∞)(0, \infty)” is not “increasing on (−∞,0)∪(0,∞)(-\infty, 0) \cup (0, \infty)”: −1/x-1/x is increasing on each interval, yet −1/(−1)=1-1/(-1) = 1 is larger than −1/1=−1.-1/1 = -1\mathclose{\text{.}}

4

Concavity

The sign of f′f' says whether a graph rises or falls; it does not say how it bends. Both halves of the graph in Figure 8.3 rise, but the left half bends upwards, like the inside of a bowl, and the right half bends downwards, like a dome. The curve is the sigmoid function of machine learning,

σ(x)=11+e−x,\sigma(x) = \frac{1}{1 + e^{-x}},

read “sigma of x”, which turns any real number into a number between 0 and 1. By the chain rule, σ′(x)=e−x(1+e−x)2.\sigma'(x) = \dfrac{e^{-x}}{(1 + e^{-x})^2}\mathclose{\text{.}} Here are its slopes:

xx−3-3−2-2−1-100112233
σ′(x)\sigma'(x)0.045180.045180.10500.10500.19660.19660.250.250.19660.19660.10500.10500.045180.04518

From left to right the slopes increase up to x=0x = 0 and then decrease. Where the slopes increase, the curve bends upwards and lies above its tangent lines; where they decrease, it bends downwards and lies below them (Figure 8.3).

Top: the sigmoid y = sigma(x) with tangent lines at four points. For x < 0 (green) the graph is concave up and lies above its tangents; for x > 0 (purple) it is concave down and lies below them. The concavity changes at the inflection point (0, tfrac12). Bottom: the slopes sigma'(x) increase for x < 0 and decrease for x > 0; they are largest, tfrac14, at the inflection point.
Figure 8.3

Top: the sigmoid y=σ(x)y = \sigma(x) with tangent lines at four points. For x<0x < 0 (green) the graph is concave up and lies above its tangents; for x>0x > 0 (purple) it is concave down and lies below them. The concavity changes at the inflection point (0,12).(0, \tfrac12)\mathclose{\text{.}} Bottom: the slopes σ′(x)\sigma'(x) increase for x<0x < 0 and decrease for x>0;x > 0\mathclose{\text{;}} they are largest, 14,\tfrac14\mathclose{\text{,}} at the inflection point.

Definition 8.4Concavity

Let ff be differentiable on an open interval I.I\mathclose{\text{.}} The graph of ff is concave up on II if f′f' is increasing on I,I\mathclose{\text{,}} and concave down on II if f′f' is decreasing on I.I\mathclose{\text{.}}

In optimisation and machine learning a function whose graph is concave up is called convex, and one whose graph is concave down is called concave. Those two words are a little broader: they also allow straight stretches, so a straight line counts as both convex and concave. Since f′′f'' is the derivative of f′,f'\mathclose{\text{,}} Theorem 8.8 applied to f′f' gives a test.

Theorem 8.10The concavity test

If f′′(x)>0f''(x) > 0 for every xx in an open interval I,I\mathclose{\text{,}} the graph of ff is concave up on I.I\mathclose{\text{.}} If f′′(x)<0f''(x) < 0 for every xx in I,I\mathclose{\text{,}} it is concave down on I.I\mathclose{\text{.}}

Proof

f′f' is differentiable on I,I\mathclose{\text{,}} with derivative f′′,f''\mathclose{\text{,}} so it is continuous on I;I\mathclose{\text{;}} by Theorem 8.8 applied to f′,f'\mathclose{\text{,}} it is increasing on II if f′′>0f'' > 0 and decreasing if f′′<0.f'' < 0\mathclose{\text{.}}

∎

The tangent lines of Figure 8.3 behave as they do for every function.

Theorem 8.11Concavity and tangent lines

If the graph of ff is concave up on an open interval I,I\mathclose{\text{,}} then for every cc in II it lies above its tangent line at c:c\mathclose{\text{:}}

f(x)>f(c)+f′(c)(x−c)f(x) > f(c) + f'(c)(x - c)

for every x≠cx \ne c in I.I\mathclose{\text{.}} If it is concave down on I,I\mathclose{\text{,}} it lies below its tangent lines. In particular, if the graph is concave up on II and f′(c)=0,f'(c) = 0\mathclose{\text{,}} then f(c)f(c) is the absolute minimum value of ff on I,I\mathclose{\text{,}} taken only at c;c\mathclose{\text{;}} if it is concave down and f′(c)=0,f'(c) = 0\mathclose{\text{,}} f(c)f(c) is the absolute maximum value.

Proof

Let x>cx > c be in I.I\mathclose{\text{.}} By the Mean Value Theorem, f(x)−f(c)=f′(t)(x−c)f(x) - f(c) = f'(t)(x - c) for some tt in (c,x).(c, x)\mathclose{\text{.}} Since f′f' is increasing and t>c,t > c\mathclose{\text{,}} f′(t)>f′(c);f'(t) > f'(c)\mathclose{\text{;}} multiplying by x−c>0x - c > 0 gives f(x)−f(c)>f′(c)(x−c).f(x) - f(c) > f'(c)(x - c)\mathclose{\text{.}} If x<c,x < c\mathclose{\text{,}} the Mean Value Theorem on [x,c][x, c] gives f(c)−f(x)=f′(t)(c−x)f(c) - f(x) = f'(t)(c - x) with x<t<c,x < t < c\mathclose{\text{,}} so f′(t)<f′(c),f'(t) < f'(c)\mathclose{\text{,}} and f(c)−f(x)<f′(c)(c−x),f(c) - f(x) < f'(c)(c - x)\mathclose{\text{,}} which rearranges to the same inequality. When f′(c)=0f'(c) = 0 the tangent line is y=f(c),y = f(c)\mathclose{\text{,}} so f(x)>f(c)f(x) > f(c) for every other xx in I.I\mathclose{\text{.}} The concave-down case is the same with the inequalities reversed.

∎

The points where the concavity changes have a name.

Definition 8.5Inflection point

A point (c,f(c))(c, f(c)) of the graph of ff is an inflection point if ff is continuous at cc and the graph changes concavity at c:c\mathclose{\text{:}} for some δ>0\delta > 0 it is concave up on (c−δ,c)(c - \delta, c) and concave down on (c,c+δ),(c, c + \delta)\mathclose{\text{,}} or concave down and then concave up.

Theorem 8.12The second derivative at an inflection point

If (c,f(c))(c, f(c)) is an inflection point and f′′(c)f''(c) exists, then f′′(c)=0.f''(c) = 0\mathclose{\text{.}}

Proof

Say the graph is concave up on (c−δ,c)(c - \delta, c) and concave down on (c,c+δ),(c, c + \delta)\mathclose{\text{,}} so that f′f' is increasing on the first interval and decreasing on the second. Since f′′(c)f''(c) exists, f′f' is differentiable at c,c\mathclose{\text{,}} hence continuous there. For c−δ<x<y<c,c - \delta < x < y < c\mathclose{\text{,}} f′(x)<f′(y),f'(x) < f'(y)\mathclose{\text{,}} and letting y→cy \to c gives f′(x)≤f′(c);f'(x) \le f'(c)\mathclose{\text{;}} in the same way f′(x)≤f′(c)f'(x) \le f'(c) for c<x<c+δ.c < x < c + \delta\mathclose{\text{.}} So f′f' has a local maximum at c,c\mathclose{\text{,}} and by Fermat’s theorem, applied to f′,f'\mathclose{\text{,}} its derivative there is 0: f′′(c)=0.f''(c) = 0\mathclose{\text{.}} The other case gives a local minimum of f′,f'\mathclose{\text{,}} with the same conclusion.

∎

So the candidates for inflection points are the points where f′′=0f'' = 0 and the points where f′′f'' does not exist, and a sign chart of f′′f'' decides. The proof also shows that the slope f′f' has a local maximum or minimum at an inflection point where f′′f'' exists: compared with its neighbourhood, the graph is steepest there, or least steep.

Example 8.9The bend of the sigmoid✓ Checked

For σ(x)=11+e−x,\sigma(x) = \dfrac{1}{1 + e^{-x}}\mathclose{\text{,}} show that σ′=σ(1−σ),\sigma' = \sigma(1 - \sigma)\mathclose{\text{,}} find σ′′,\sigma''\mathclose{\text{,}} the intervals of concavity and the inflection point, and the largest value of σ′.\sigma'\mathclose{\text{.}}

Since 1−σ(x)=1+e−x−11+e−x=e−x1+e−x,1 - \sigma(x) = \dfrac{1 + e^{-x} - 1}{1 + e^{-x}} = \dfrac{e^{-x}}{1 + e^{-x}}\mathclose{\text{,}}

σ(x)(1−σ(x))=11+e−x⋅e−x1+e−x=e−x(1+e−x)2=σ′(x).\begin{aligned} \sigma(x)\big(1 - \sigma(x)\big) &= \frac{1}{1 + e^{-x}}\cdot\frac{e^{-x}}{1 + e^{-x}} \\ &= \frac{e^{-x}}{(1 + e^{-x})^2} = \sigma'(x). \end{aligned}

Differentiate σ′=σ−σ2,\sigma' = \sigma - \sigma^2\mathclose{\text{,}} using the chain rule on σ2:\sigma^2\mathclose{\text{:}}

σ′′=σ′−2σσ′=σ′(1−2σ).\sigma'' = \sigma' - 2\sigma\sigma' = \sigma'(1 - 2\sigma).

Since σ′>0,\sigma' > 0\mathclose{\text{,}} σ′′\sigma'' has the sign of 1−2σ.1 - 2\sigma\mathclose{\text{.}} Now 1−2σ(x)>01 - 2\sigma(x) > 0 exactly when σ(x)<12,\sigma(x) < \tfrac12\mathclose{\text{,}} that is, when 1+e−x>2,1 + e^{-x} > 2\mathclose{\text{,}} that is, when e−x>1,e^{-x} > 1\mathclose{\text{,}} that is, when x<0.x < 0\mathclose{\text{.}} So σ′′>0\sigma'' > 0 for x<0x < 0 and σ′′<0\sigma'' < 0 for x>0:x > 0\mathclose{\text{:}} the graph is concave up on (−∞,0)(-\infty, 0) and concave down on (0,∞),(0, \infty)\mathclose{\text{,}} and (0,σ(0))=(0,12)\big(0, \sigma(0)\big) = \big(0, \tfrac12\big) is an inflection point. Finally, σ′\sigma' is increasing on (−∞,0](-\infty, 0] and decreasing on [0,∞)[0, \infty) (Theorem 8.8 applied to σ′,\sigma'\mathclose{\text{,}} whose derivative is σ′′),\sigma''\mathclose{\text{),}} so its absolute maximum value is σ′(0)=14:\sigma'(0) = \tfrac14\mathclose{\text{:}} the sigmoid is steepest at its inflection point, as the table above showed.

In machine learning, σ(x)\sigma(x) turns a score xx into a probability. Its slope is at most 14\tfrac14 and very small when ∣x∣\abs{x} is large, which matters when a model is trained by following slopes, as in Section 8.7.

Watch out

Three slips with inflection points. f′′(c)=0f''(c) = 0 is not enough: x4x^4 has f′′(x)=12x2,f''(x) = 12x^2\mathclose{\text{,}} which is 0 at 0 but positive on both sides, so the graph is concave up on both sides and has no inflection point. f′′f'' need not exist at an inflection point: x1/3x^{1/3} has f′′(x)=−29x−5/3,f''(x) = -\tfrac29x^{-5/3}\mathclose{\text{,}} positive for x<0x < 0 and negative for x>0,x > 0\mathclose{\text{,}} so the origin is an inflection point (with a vertical tangent) although f′′(0)f''(0) does not exist. A change of concavity at a point outside the domain is not an inflection point: 1/x1/x is concave down for x<0x < 0 and concave up for x>0,x > 0\mathclose{\text{,}} but has no point at 0. And concave up is not increasing: e−xe^{-x} is concave up and decreasing.

The second derivative test

At a critical number where f′(c)=0,f'(c) = 0\mathclose{\text{,}} the tangent is horizontal. If the graph is concave up there, it lies above the horizontal tangent near c,c\mathclose{\text{,}} a valley; if it is concave down, it lies below, a peak. That is the idea of a second test, which needs no sign chart of f′.f'\mathclose{\text{.}}

Theorem 8.13The second derivative test

Suppose that f′(c)=0f'(c) = 0 and f′′(c)f''(c) exists.

  • If f′′(c)>0,f''(c) > 0\mathclose{\text{,}} f(c)f(c) is a local minimum value.
  • If f′′(c)<0,f''(c) < 0\mathclose{\text{,}} f(c)f(c) is a local maximum value.
  • If f′′(c)=0,f''(c) = 0\mathclose{\text{,}} the test gives no information.
Proof

Suppose f′′(c)>0.f''(c) > 0\mathclose{\text{.}} Since f′(c)=0,f'(c) = 0\mathclose{\text{,}}

f′′(c)=lim⁡x→cf′(x)−f′(c)x−c=lim⁡x→cf′(x)x−c>0.f''(c) = \lim_{x\to c}\frac{f'(x) - f'(c)}{x - c} = \lim_{x\to c}\frac{f'(x)}{x - c} > 0.

So, as in the proof of Fermat’s theorem, there is a δ>0\delta > 0 such that f′(x)x−c>0\dfrac{f'(x)}{x - c} > 0 whenever 0<∣x−c∣<δ:0 < \abs{x - c} < \delta\mathclose{\text{:}} then f′(x)<0f'(x) < 0 for c−δ<x<cc - \delta < x < c and f′(x)>0f'(x) > 0 for c<x<c+δ.c < x < c + \delta\mathclose{\text{.}} ff is differentiable near cc (as f′′(c)f''(c) exists), so the first derivative test gives a local minimum. If f′′(c)<0,f''(c) < 0\mathclose{\text{,}} the signs reverse and give a local maximum. For the third case, the three functions x4,x^4\mathclose{\text{,}} −x4-x^4 and x3x^3 all have f′(0)=f′′(0)=0,f'(0) = f''(0) = 0\mathclose{\text{,}} and they have a minimum, a maximum and neither at 0.

∎
Example 8.10When the second derivative test fails✓ Checked

Find the local extrema and the inflection points of f(x)=x4−4x3.f(x) = x^4 - 4x^3\mathclose{\text{.}}

The derivatives are

f′(x)=4x3−12x2=4x2(x−3),f′′(x)=12x2−24x=12x(x−2).\begin{aligned} f'(x) &= 4x^3 - 12x^2 = 4x^2(x - 3), \\ f''(x) &= 12x^2 - 24x = 12x(x - 2). \end{aligned}

Extrema. The critical numbers are 0 and 3. At 3, f′′(3)=108−72=36>0,f''(3) = 108 - 72 = 36 > 0\mathclose{\text{,}} so f(3)=81−108=−27f(3) = 81 - 108 = -27 is a local minimum value. At 0, f′′(0)=0,f''(0) = 0\mathclose{\text{,}} and the test says nothing. Use the first derivative test instead: for x<0x < 0 and for 0<x<3,0 < x < 3\mathclose{\text{,}} 4x2>04x^2 > 0 and x−3<0,x - 3 < 0\mathclose{\text{,}} so f′(x)<0f'(x) < 0 on both sides of 0. There is no extremum at 0: the graph flattens out for a moment as it falls. In fact ff is decreasing on (−∞,3](-\infty, 3] and increasing on [3,∞),[3, \infty)\mathclose{\text{,}} so −27-27 is the absolute minimum value.

Concavity. f′′(x)=12x(x−2)f''(x) = 12x(x - 2) is positive for x<0,x < 0\mathclose{\text{,}} negative for 0<x<20 < x < 2 and positive for x>2.x > 2\mathclose{\text{.}} The graph is concave up on (−∞,0),(-\infty, 0)\mathclose{\text{,}} concave down on (0,2)(0, 2) and concave up on (2,∞),(2, \infty)\mathclose{\text{,}} with inflection points (0,0)(0, 0) and (2,f(2))=(2,−16).(2, f(2)) = (2, -16)\mathclose{\text{.}} At the origin the graph has a horizontal tangent and an inflection point at once.

Tip

Which test should you use? The second derivative test is quick when f′′f'' is easy to compute, and it decides most critical numbers where f′(c)=0.f'(c) = 0\mathclose{\text{.}} The first derivative test decides whenever f′f' keeps one sign on each side of c,c\mathclose{\text{,}} as it does for every function in this module, even where f′′(c)=0f''(c) = 0 or f′(c)f'(c) does not exist. Its sign chart also tells you where ff increases and decreases.

5

Curve sketching

A computer draws a graph by plotting many points; it does not tell you which features matter, and it can miss them between its points or outside its window. The derivatives find the features, and with them you can sketch a graph that shows everything important.

Key idea

A checklist for sketching y=f(x).y = f(x)\mathclose{\text{.}}

  1. Domain: where is ff defined?
  2. Intercepts: the yy-intercept f(0),f(0)\mathclose{\text{,}} if 0 is in the domain; the xx-intercepts, the solutions of f(x)=0,f(x) = 0\mathclose{\text{,}} when you can find them.
  3. Symmetry: is ff even, f(−x)=f(x),f(-x) = f(x)\mathclose{\text{,}} or odd, f(−x)=−f(x)f(-x) = -f(x) (Section 1.4)? Is it periodic?
  4. Asymptotes: vertical, horizontal and oblique (Module 3).
  5. Increase and decrease: a sign chart of f′.f'\mathclose{\text{.}}
  6. Local extrema: the first or the second derivative test.
  7. Concavity and inflection points: a sign chart of f′′.f''\mathclose{\text{.}}
  8. Sketch: draw the asymptotes, plot the points found, and join them with a curve that rises, falls and bends as the charts say.
Example 8.11Sketching a rational function✓ Checked

Sketch the graph of f(x)=x2x2−4.f(x) = \dfrac{x^2}{x^2 - 4}\mathclose{\text{.}}

  1. Domain. x2−4=0x^2 - 4 = 0 at x=±2,x = \pm2\mathclose{\text{,}} so the domain is all x≠±2.x \ne \pm2\mathclose{\text{.}}

  2. Intercepts. f(0)=0,f(0) = 0\mathclose{\text{,}} and f(x)=0f(x) = 0 only when x2=0:x^2 = 0\mathclose{\text{:}} the only intercept is the origin.

  3. Symmetry. f(−x)=f(x):f(-x) = f(x)\mathclose{\text{:}} ff is even, and its graph is symmetric about the yy-axis.

  4. Asymptotes. As x→±∞,x \to \pm\infty\mathclose{\text{,}} dividing the top and the bottom by x2x^2 gives f(x)=11−4/x2→1:f(x) = \dfrac{1}{1 - 4/x^2} \to 1\mathclose{\text{:}} the line y=1y = 1 is a horizontal asymptote. Since f(x)−1=4x2−4,f(x) - 1 = \dfrac{4}{x^2 - 4}\mathclose{\text{,}} which is positive for ∣x∣>2,\abs{x} > 2\mathclose{\text{,}} the graph approaches it from above. As x→2+,x \to 2^+\mathclose{\text{,}} the top tends to 4 and the bottom to 0 through positive values, so f(x)→∞;f(x) \to \infty\mathclose{\text{;}} as x→2−,x \to 2^-\mathclose{\text{,}} f(x)→−∞.f(x) \to -\infty\mathclose{\text{.}} By symmetry, f(x)→∞f(x) \to \infty as x→−2−x \to -2^- and f(x)→−∞f(x) \to -\infty as x→−2+.x \to -2^+\mathclose{\text{.}} The lines x=±2x = \pm2 are vertical asymptotes.

  5. Increase and decrease. By the quotient rule (Module 5),

    f′(x)=2x(x2−4)−x2⋅2x(x2−4)2=−8x(x2−4)2.f'(x) = \frac{2x(x^2 - 4) - x^2\cdot 2x}{(x^2 - 4)^2} = \frac{-8x}{(x^2 - 4)^2}.

    The denominator is positive, so f′(x)>0f'(x) > 0 for x<0x < 0 and f′(x)<0f'(x) < 0 for x>0x > 0 (x≠±2).x \ne \pm2\mathclose{\text{).}} So ff is increasing on (−∞,−2)(-\infty, -2) and on (−2,0],(-2, 0]\mathclose{\text{,}} and decreasing on [0,2)[0, 2) and on (2,∞).(2, \infty)\mathclose{\text{.}}

  6. Local extrema. The only critical number is 0, where f′f' changes from positive to negative: f(0)=0f(0) = 0 is a local maximum value. It is not an absolute maximum, since f(x)→∞f(x) \to \infty as x→2+.x \to 2^+\mathclose{\text{.}}

  7. Concavity. Write f′(x)=−8x(x2−4)−2f'(x) = -8x(x^2 - 4)^{-2} and use the product and chain rules:

    f′′(x)=−8(x2−4)−2+32x2(x2−4)−3=−8(x2−4)+32x2(x2−4)3=8(3x2+4)(x2−4)3.\begin{aligned} f''(x) &= -8(x^2 - 4)^{-2} + 32x^2(x^2 - 4)^{-3} \\ &= \frac{-8(x^2 - 4) + 32x^2}{(x^2 - 4)^3} = \frac{8(3x^2 + 4)}{(x^2 - 4)^3}. \end{aligned}

    The top is always positive, so f′′f'' has the sign of x2−4:x^2 - 4\mathclose{\text{:}} the graph is concave up on (−∞,−2)(-\infty, -2) and (2,∞),(2, \infty)\mathclose{\text{,}} and concave down on (−2,2).(-2, 2)\mathclose{\text{.}} The concavity changes only at ±2,\pm2\mathclose{\text{,}} which are not in the domain: no inflection points.

  8. Sketch. Figure 8.4, left: two outer branches above y=1,y = 1\mathclose{\text{,}} concave up, falling from the vertical asymptotes towards y=1;y = 1\mathclose{\text{;}} a middle branch, concave down, with its peak at the origin and plunging to −∞-\infty at both asymptotes. Two more points help: f(±1)=−13f(\pm1) = -\tfrac13 and f(±3)=95.f(\pm3) = \tfrac95\mathclose{\text{.}}

Example 8.12Sketching xe−xx e^{-x}✓ Checked

Sketch the graph of f(x)=xe−x.f(x) = xe^{-x}\mathclose{\text{.}}

  1. Domain. All real x.x\mathclose{\text{.}}
  2. Intercepts. e−x>0,e^{-x} > 0\mathclose{\text{,}} so f(x)=0f(x) = 0 only at x=0:x = 0\mathclose{\text{:}} the origin.
  3. Symmetry. f(−1)=−ef(-1) = -e and f(1)=e−1,f(1) = e^{-1}\mathclose{\text{,}} so ff is neither even nor odd.
  4. Asymptotes. ff is continuous, so there are no vertical asymptotes. As x→∞,x \to \infty\mathclose{\text{,}} xe−x=xex→0,xe^{-x} = \dfrac{x}{e^x} \to 0\mathclose{\text{,}} because exponentials grow faster than powers (Module 7, by L’Hôpital’s rule): the xx-axis is a horizontal asymptote on the right. As x→−∞,x \to -\infty\mathclose{\text{,}} x→−∞x \to -\infty and e−x→∞,e^{-x} \to \infty\mathclose{\text{,}} so f(x)→−∞.f(x) \to -\infty\mathclose{\text{.}}
  5. Increase and decrease. By the product rule, f′(x)=e−x−xe−x=(1−x)e−x.f'(x) = e^{-x} - xe^{-x} = (1 - x)e^{-x}\mathclose{\text{.}} Since e−x>0,e^{-x} > 0\mathclose{\text{,}} f′f' has the sign of 1−x:1 - x\mathclose{\text{:}} ff is increasing on (−∞,1](-\infty, 1] and decreasing on [1,∞).[1, \infty)\mathclose{\text{.}}
  6. Extrema. So f(1)=e−1=1e≈0.368f(1) = e^{-1} = \tfrac1e \approx 0.368 is not only a local maximum value but the absolute maximum value: ff rises to it and falls after it.
  7. Concavity. f′′(x)=−e−x−(1−x)e−x=(x−2)e−x,f''(x) = -e^{-x} - (1 - x)e^{-x} = (x - 2)e^{-x}\mathclose{\text{,}} negative for x<2x < 2 and positive for x>2.x > 2\mathclose{\text{.}} The graph is concave down on (−∞,2)(-\infty, 2) and concave up on (2,∞),(2, \infty)\mathclose{\text{,}} with an inflection point at (2,2e−2)≈(2,0.271).\big(2, 2e^{-2}\big) \approx (2, 0.271)\mathclose{\text{.}}
  8. Sketch. Figure 8.4, right: rising steeply from −∞-\infty through the origin, peaking at (1,1e),\big(1, \tfrac1e\big)\mathclose{\text{,}} and decaying towards the xx-axis, the bend reversing at x=2.x = 2\mathclose{\text{.}}
The two sketches. Left: y = dfrac{x^2}{x^2 - 4}, with vertical asymptotes x = pm2, horizontal asymptote y = 1 (dashed), and a local maximum at the origin; it is concave up outside [-2, 2] and concave down inside, without inflection points. Right: y = xe^{-x}, with its maximum tfrac1e at x = 1 and its inflection point at x = 2.
Figure 8.4

The two sketches. Left: y=x2x2−4,y = \dfrac{x^2}{x^2 - 4}\mathclose{\text{,}} with vertical asymptotes x=±2,x = \pm2\mathclose{\text{,}} horizontal asymptote y=1y = 1 (dashed), and a local maximum at the origin; it is concave up outside [−2,2][-2, 2] and concave down inside, without inflection points. Right: y=xe−x,y = xe^{-x}\mathclose{\text{,}} with its maximum 1e\tfrac1e at x=1x = 1 and its inflection point at x=2.x = 2\mathclose{\text{.}}

The widget below does the sign charts for you, numerically. Use it to check a sketch, not to replace one: it looks only at its window and at the points of its grid.

Try it

The curve is blue where ff is increasing and orange where it is decreasing; the background is green where the graph is concave up and purple where it is concave down. Dots mark the critical numbers, squares the inflection points, and the two charts below the graph give the signs of f′f' and f′′.f''\mathclose{\text{.}} Choose x4−4x3x^4 - 4x^3 and compare with Example 8.10: the flat point at 0 is a critical number but not an extremum, and it is also an inflection point. Choose x e−xx\,e^{-x} and compare with Example 8.12. Then type x^2/(x^2 - 4) (Example 8.11), and x^(2/3)(x - 5), the function of Example 8.7 (unlike Python, the widget takes x2/3x^{2/3} with the real cube root, as this series does), and move the point with the slider to read f(x),f(x)\mathclose{\text{,}} f′(x)f'(x) and f′′(x).f''(x)\mathclose{\text{.}}

Compute itCurve sketching with SymPy

SymPy does the algebra of a sketch. Declare xx real, so that solve looks only for real solutions:

Python
import sympy as sp
x = sp.symbols('x', real=True)
f = x**2/(x**2 - 4)
d1 = sp.factor(sp.diff(f, x))
d2 = sp.factor(sp.diff(f, x, 2))
print(d1)
print(d2)
print(sp.solve(d1, x), sp.solve(d2, x))
print(sp.limit(f, x, sp.oo), sp.limit(f, x, 2, '+'), sp.limit(f, x, 2, '-'))
Output
-8*x/((x - 2)**2*(x + 2)**2)
8*(3*x**2 + 4)/((x - 2)**3*(x + 2)**3)
[0] []
1 oo -oo

These are the derivatives of Example 8.11, with x2−4x^2 - 4 factored; f′′=0f'' = 0 has no real solution. solve also solves inequalities, which gives the sign charts:

Python
print(sp.solve(d1 > 0, x))
print(sp.solve(d2 < 0, x))
z = sp.symbols('z')                  # a symbol with no assumptions
print(sp.solve(3*z**2 + 4, z))
Output
(x < 0) & Ne(x, -2)
(-2 < x) & (x < 2)
[-2*sqrt(3)*I/3, 2*sqrt(3)*I/3]

Read & as “and” and Ne(x, -2) as x≠−2:x \ne -2\mathclose{\text{:}} f′>0f' > 0 for x<0,x < 0\mathclose{\text{,}} x≠−2,x \ne -2\mathclose{\text{,}} and f′′<0f'' < 0 on (−2,2),(-2, 2)\mathclose{\text{,}} as in the example. Without real=True, solve returns complex solutions too: 3z2+4=03z^2 + 4 = 0 has the solutions ±23i,\pm\tfrac{2}{\sqrt3}i\mathclose{\text{,}} where i2=−1,i^2 = -1\mathclose{\text{,}} which are of no use on a graph.

6

Optimisation problems

An optimisation problem in words becomes a problem about the extreme values of a function. The closed interval method handles a continuous function on a closed interval; many problems, though, live on open or unbounded intervals, such as all lengths r>0.r > 0\mathclose{\text{.}} There the next theorem, or Theorem 8.11, shows that a critical number gives the absolute extremum.

Theorem 8.14The first derivative test for absolute extrema

Let ff be continuous on an interval I,I\mathclose{\text{,}} let cc be in I,I\mathclose{\text{,}} and let ff be differentiable at every point of II except possibly cc and the endpoints of I.I\mathclose{\text{.}} If f′(x)>0f'(x) > 0 at every such x<cx < c and f′(x)<0f'(x) < 0 at every such x>c,x > c\mathclose{\text{,}} then f(c)f(c) is the absolute maximum value of ff on I,I\mathclose{\text{,}} taken only at c.c\mathclose{\text{.}} If f′(x)<0f'(x) < 0 for x<cx < c and f′(x)>0f'(x) > 0 for x>c,x > c\mathclose{\text{,}} f(c)f(c) is the absolute minimum value, taken only at c.c\mathclose{\text{.}}

Proof

The points of II that are ≤c\le c form an interval on which ff is continuous, and f′>0f' > 0 at those of them that are not endpoints; by Theorem 8.8, ff is increasing there, so f(x)<f(c)f(x) < f(c) for every x<cx < c in I.I\mathclose{\text{.}} In the same way ff is decreasing on the points of II that are ≥c,\ge c\mathclose{\text{,}} so f(x)<f(c)f(x) < f(c) for x>c.x > c\mathclose{\text{.}} So f(x)<f(c)f(x) < f(c) for every x≠cx \ne c in I.I\mathclose{\text{.}} The minimum is the same.

∎
Key idea

Solving an optimisation problem.

  1. Read the problem and draw a picture. Name the quantities, with their units.
  2. Write the quantity to be made largest or smallest as a function of the others.
  3. Use the conditions of the problem to make it a function of one variable, and find the interval of values the variable can take.
  4. Find the critical numbers in that interval.
  5. Show that you have the absolute extremum: by the closed interval method if the interval is closed and bounded; otherwise by the sign of the derivative on each side (Theorem 8.14) or by concavity (Theorem 8.11).
  6. Answer the question that was asked, with units, and check that the answer makes sense.
Example 8.13The biggest box from a sheet✓ Checked

Suppose a rectangular sheet of cardboard is 24 cm by 45 cm. Cut a square of side xx cm from each corner and fold up the sides to make an open box. Which xx gives the largest volume?

The base of the box is (45−2x)(45 - 2x) by (24−2x)(24 - 2x) cm and its height is xx cm, so its volume is

V(x)=x(24−2x)(45−2x) cm3.V(x) = x(24 - 2x)(45 - 2x) \text{ cm}^3.

The cuts need x≥0x \ge 0 and 24−2x≥0,24 - 2x \ge 0\mathclose{\text{,}} so 0≤x≤120 \le x \le 12 (at the ends the box is flat, with volume 0). Numbers first:

xx112233445566778810101212
V(x)V(x)946946164016402106210623682368245024502376237621702170185618561000100000

The best cut seems to be near 5 cm. Now calculus. Expand: V(x)=4x3−138x2+1080x,V(x) = 4x^3 - 138x^2 + 1080x\mathclose{\text{,}} so

V′(x)=12x2−276x+1080=12(x2−23x+90)=12(x−5)(x−18).\begin{aligned} V'(x) &= 12x^2 - 276x + 1080 \\ &= 12(x^2 - 23x + 90) = 12(x - 5)(x - 18). \end{aligned}

The critical numbers are 5 and 18, and only 5 lies in [0,12].[0, 12]\mathclose{\text{.}} By the closed interval method, compare V(0)=0,V(0) = 0\mathclose{\text{,}} V(5)=5⋅14⋅35=2450V(5) = 5 \cdot 14 \cdot 35 = 2450 and V(12)=0:V(12) = 0\mathclose{\text{:}} the largest volume is 2450 cm³, about 2.45 litres, with cuts of 5 cm, for a box 35 cm by 14 cm by 5 cm deep. The critical number 18 is a value of xx for which no box exists.

Example 8.14A can with the least metal✓ Checked

A cylindrical can must hold 330 cm³ (330 ml, a common size for drinks). Which radius rr and height hh need the least metal, that is, the least surface area, top and bottom included?

The area is A=2πr2+2πrh:A = 2\pi r^2 + 2\pi rh\mathclose{\text{:}} two discs and the side, which unrolls into a rectangle of width 2πr2\pi r and height h.h\mathclose{\text{.}} The volume condition πr2h=330\pi r^2h = 330 gives h=330πr2,h = \dfrac{330}{\pi r^2}\mathclose{\text{,}} so

A(r)=2πr2+2πr⋅330πr2=2πr2+660r,r>0.A(r) = 2\pi r^2 + 2\pi r\cdot\frac{330}{\pi r^2} = 2\pi r^2 + \frac{660}{r}, \qquad r > 0.

The interval (0,∞)(0, \infty) is not closed: no closed interval method. Differentiate:

A′(r)=4πr−660r2=4πr3−660r2,A'(r) = 4\pi r - \frac{660}{r^2} = \frac{4\pi r^3 - 660}{r^2},

which is 0 when r3=6604π=165π,r^3 = \dfrac{660}{4\pi} = \dfrac{165}{\pi}\mathclose{\text{,}} at r∗=165/π3≈3.745r^* = \sqrt[3]{165/\pi} \approx 3.745 cm. For r<r∗r < r^* the top 4πr3−6604\pi r^3 - 660 is negative, and for r>r∗r > r^* it is positive, so by Theorem 8.14, A(r∗)A(r^*) is the absolute minimum. The height is then

h=330πr∗2=330πr∗3 r∗=330165 r∗=2r∗≈7.49 cm,h = \frac{330}{\pi r^{*2}} = \frac{330}{\pi r^{*3}}\,r^* = \frac{330}{165}\,r^* = 2r^* \approx 7.49 \text{ cm},

using πr∗3=165,\pi r^{*3} = 165\mathclose{\text{,}} and the area is A(r∗)≈264.4A(r^*) \approx 264.4 cm². The best can is exactly as tall as it is wide: its height equals its diameter. The same steps with any volume VV in place of 330 give r∗3=V/(2π)r^{*3} = V/(2\pi) and again h=2r∗.h = 2r^*\mathclose{\text{.}} Real drinks cans are much taller than they are wide, so their makers weigh other things than the area of the metal.

Example 8.15The closest point on a parabola✓ Checked

Find the point of the parabola y=x2y = x^2 closest to the point (3,0).(3, 0)\mathclose{\text{.}}

The distance from (x,x2)(x, x^2) to (3,0)(3, 0) is (x−3)2+x4.\sqrt{(x - 3)^2 + x^4}\mathclose{\text{.}} The square root is increasing, so the distance is smallest where its square is smallest, and the square, free of the root, is easier to differentiate:

D(x)=(x−3)2+x4,x real.D(x) = (x - 3)^2 + x^4, \qquad x \text{ real}.

D′(x)=2(x−3)+4x3=2(2x3+x−3).D'(x) = 2(x - 3) + 4x^3 = 2(2x^3 + x - 3)\mathclose{\text{.}} Trying small integers, x=1x = 1 is a root of 2x3+x−3,2x^3 + x - 3\mathclose{\text{,}} and dividing by x−1x - 1 gives

D′(x)=2(x−1)(2x2+2x+3).D'(x) = 2(x - 1)(2x^2 + 2x + 3).

The quadratic factor has no real root, since its discriminant is 4−24<0,4 - 24 < 0\mathclose{\text{,}} so the only critical number is 1. And D′′(x)=12x2+2>0D''(x) = 12x^2 + 2 > 0 everywhere: DD is concave up on R,\R\mathclose{\text{,}} so by Theorem 8.11 its critical number gives the absolute minimum. The closest point is (1,1),(1, 1)\mathclose{\text{,}} at distance D(1)=4+1=5≈2.236.\sqrt{D(1)} = \sqrt{4 + 1} = \sqrt5 \approx 2.236\mathclose{\text{.}} A check: the segment from (3,0)(3, 0) to (1,1)(1, 1) has slope −12,-\tfrac12\mathclose{\text{,}} and the tangent to the parabola at (1,1)(1, 1) has slope 2; since 2⋅(−12)=−1,2 \cdot \big(-\tfrac12\big) = -1\mathclose{\text{,}} they are perpendicular, as the shortest path to a curve should be.

Example 8.16Snell’s law from the principle of least time✓ Checked

A lifeguard on a beach runs faster than she swims. To reach a swimmer in the sea as fast as possible she should not head straight for him: running a little further along the beach shortens the slow swim. Light faces the same problem when it passes from air into water, where it travels more slowly, and Fermat’s principle says that light takes the path of least time. Find the path.

Put the boundary on the xx-axis, the start A=(0,a)A = (0, a) above it and the end B=(d,−b)B = (d, -b) below it, with a,b,d>0.a, b, d > 0\mathclose{\text{.}} Light crosses the boundary at P=(x,0),P = (x, 0)\mathclose{\text{,}} travelling at speed v1v_1 from AA to PP and v2v_2 from PP to B.B\mathclose{\text{.}} Distance over speed gives the time:

T(x)=a2+x2v1+b2+(d−x)2v2.T(x) = \frac{\sqrt{a^2 + x^2}}{v_1} + \frac{\sqrt{b^2 + (d - x)^2}}{v_2}.

By the chain rule,

T′(x)=xv1a2+x2−d−xv2b2+(d−x)2.T'(x) = \frac{x}{v_1\sqrt{a^2 + x^2}} - \frac{d - x}{v_2\sqrt{b^2 + (d - x)^2}}.

Let θ1\theta_1 be the angle between APAP and the vertical, and θ2\theta_2 the angle between PBPB and the vertical. For 0<x<d0 < x < d the right triangles give sin⁡θ1=xa2+x2\sin\theta_1 = \dfrac{x}{\sqrt{a^2 + x^2}} and sin⁡θ2=d−xb2+(d−x)2,\sin\theta_2 = \dfrac{d - x}{\sqrt{b^2 + (d - x)^2}}\mathclose{\text{,}} so

T′(x)=0  ⟺  sin⁡θ1v1=sin⁡θ2v2.T'(x) = 0 \quad\iff\quad \frac{\sin\theta_1}{v_1} = \frac{\sin\theta_2}{v_2}.

This is Snell’s law of refraction. Is it a minimum? Differentiating again,

T′′(x)=a2v1(a2+x2)3/2+b2v2(b2+(d−x)2)3/2>0,T''(x) = \frac{a^2}{v_1(a^2 + x^2)^{3/2}} + \frac{b^2}{v_2\big(b^2 + (d - x)^2\big)^{3/2}} > 0,

so TT is concave up on R.\R\mathclose{\text{.}} Also T′(0)<0<T′(d),T'(0) < 0 < T'(d)\mathclose{\text{,}} so by the Intermediate Value Theorem T′T' has a zero between 0 and d,d\mathclose{\text{,}} and only one, since T′T' is increasing. By Theorem 8.11 that zero gives the absolute minimum of T:T\mathclose{\text{:}} the path of least time obeys Snell’s law. With numbers: light travels about 1.33 times as fast in air as in water (the refractive index of water is about 1.33), so take v1/v2=43,v_1/v_2 = \tfrac43\mathclose{\text{,}} a=3,a = 3\mathclose{\text{,}} b=4b = 4 and d=7.d = 7\mathclose{\text{.}} At x=4,x = 4\mathclose{\text{,}} sin⁡θ1=45\sin\theta_1 = \tfrac{4}{5} and sin⁡θ2=35,\sin\theta_2 = \tfrac{3}{5}\mathclose{\text{,}} and 4/53/5=43=v1v2:\dfrac{4/5}{3/5} = \tfrac43 = \dfrac{v_1}{v_2}\mathclose{\text{:}} the light enters the water at (4,0).(4, 0)\mathclose{\text{.}}

Example 8.17The cheapest cost per unit✓ Checked

Suppose that making qq units of a product per week costs C(q)=1800+6q+0.02q2C(q) = 1800 + 6q + 0.02q^2 pounds (a made-up cost: a fixed £1800, plus costs that grow faster than the output). How many units minimise the average cost A(q)=C(q)/q,A(q) = C(q)/q\mathclose{\text{,}} the cost per unit?

A(q)=1800q+6+0.02q,q>0.A(q) = \frac{1800}{q} + 6 + 0.02q, \qquad q > 0.

A′(q)=−1800q2+0.02,A'(q) = -\dfrac{1800}{q^2} + 0.02\mathclose{\text{,}} which is 0 when q2=90 000,q^2 = 90\,000\mathclose{\text{,}} at q=300.q = 300\mathclose{\text{.}} And A′′(q)=3600q3>0A''(q) = \dfrac{3600}{q^3} > 0 for q>0:q > 0\mathclose{\text{:}} AA is concave up on (0,∞),(0, \infty)\mathclose{\text{,}} so by Theorem 8.11, A(300)A(300) is the absolute minimum. The cheapest cost per unit is A(300)=6+6+6=18,A(300) = 6 + 6 + 6 = 18\mathclose{\text{,}} that is, £18, at 300 units a week.

Economists call the derivative C′(q)C'(q) the marginal cost: by linear approximation (Module 7), C(q+1)−C(q)≈C′(q),C(q + 1) - C(q) \approx C'(q)\mathclose{\text{,}} the cost of one more unit. Here C′(q)=6+0.04q,C'(q) = 6 + 0.04q\mathclose{\text{,}} and C′(300)=18:C'(300) = 18\mathclose{\text{:}} at the best output, the marginal cost equals the average cost. That is no coincidence. By the quotient rule,

A′(q)=qC′(q)−C(q)q2,A'(q) = \frac{qC'(q) - C(q)}{q^2},

which is 0 exactly when C′(q)=C(q)/q.C'(q) = C(q)/q\mathclose{\text{.}} While making one more unit costs less than the average, it pulls the average down; once it costs more, it pushes the average up.

Watch out

Three slips in optimisation. Ignoring the interval: in Example 8.13 the critical number 18 has no box, and in a problem on a closed interval the answer may be at an end. Stopping at a critical number: f′(c)=0f'(c) = 0 does not make f(c)f(c) the largest or the smallest value; say which theorem shows it, as the examples do. Answering a different question: if the problem asks for the dimensions of a can, the minimum area alone is not the answer.

7

Gradient descent

Every example so far solved f′(x)=0f'(x) = 0 by algebra. Often that is impossible: the equation has no formula for its solution, or, in machine learning, ff is the error of a model with millions of parameters. Then you can search instead: start somewhere and walk downhill.

Definition 8.6Gradient descent

To minimise a differentiable function f,f\mathclose{\text{,}} choose a starting point x0x_0 and a step size η>0,\eta > 0\mathclose{\text{,}} and compute

xk+1=xk−ηf′(xk),k=0,1,2,…x_{k+1} = x_k - \eta f'(x_k), \qquad k = 0, 1, 2, \dots

The Greek letter η\eta is read “eta”. In machine learning the step size is called the learning rate.

Why does this go downhill? If f′(xk)>0,f'(x_k) > 0\mathclose{\text{,}} the graph slopes upwards at xk,x_k\mathclose{\text{,}} and the step moves left; if f′(xk)<0,f'(x_k) < 0\mathclose{\text{,}} it slopes downwards, and the step moves right. By the linearisation of Module 7,

f(xk+1)≈f(xk)+f′(xk)(xk+1−xk)=f(xk)−ηf′(xk)2,\begin{aligned} f(x_{k+1}) &\approx f(x_k) + f'(x_k)(x_{k+1} - x_k) \\ &= f(x_k) - \eta f'(x_k)^2, \end{aligned}

which is less than f(xk)f(x_k) when f′(xk)≠0,f'(x_k) \ne 0\mathclose{\text{,}} at least when the step is small enough for the approximation to be good. And the steps stop moving exactly at critical numbers: xk+1=xkx_{k+1} = x_k means f′(xk)=0.f'(x_k) = 0\mathclose{\text{.}} How large should η\eta be? A parabola answers that completely.

Example 8.18Gradient descent on a parabola✓ Checked

Let f(x)=q2x2,f(x) = \tfrac{q}{2}x^2\mathclose{\text{,}} where q>0q > 0 is a constant, so that f′(x)=qx,f'(x) = qx\mathclose{\text{,}} f′′(x)=q,f''(x) = q\mathclose{\text{,}} and the minimum is at x=0.x = 0\mathclose{\text{.}} Show that gradient descent gives xk=(1−qη)kx0,x_k = (1 - q\eta)^kx_0\mathclose{\text{,}} and find the step sizes for which xkx_k approaches the minimum.

One step gives xk+1=xk−ηqxk=(1−qη)xk.x_{k+1} = x_k - \eta qx_k = (1 - q\eta)x_k\mathclose{\text{.}} Every step multiplies by the same factor 1−qη,1 - q\eta\mathclose{\text{,}} so after kk steps xk=(1−qη)kx0.x_k = (1 - q\eta)^kx_0\mathclose{\text{.}} Powers of a number between −1-1 and 1 shrink towards 0, and powers of a number beyond ±1\pm1 grow without bound. With x0≠0:x_0 \ne 0\mathclose{\text{:}}

Step size Factor 1−qη1 - q\eta The steps
0<η<1/q0 < \eta < 1/q between 0 and 1 approach 0 from one side; slowly if η\eta is small
η=1/q\eta = 1/q 0 land on 0 in one step
1/q<η<2/q1/q < \eta < 2/q between −1-1 and 0 zigzag about 0, closing in
η=2/q\eta = 2/q −1-1 bounce between x0x_0 and −x0-x_0 for ever
η>2/q\eta > 2/q below −1-1 zigzag outwards: diverge

So gradient descent finds the minimum exactly when 0<η<2/q:0 < \eta < 2/q\mathclose{\text{:}} the more sharply the parabola curves, the smaller the steps must be.

Near a minimum cc where f′′(c)>0,f''(c) > 0\mathclose{\text{,}} a function behaves much like this parabola, and the same rule applies there.

Key idea

A rule of thumb for the step size. Near a minimum cc with f′′(c)>0,f''(c) > 0\mathclose{\text{,}} the linearisation of f′f' at cc (Module 7) gives f′(x)≈f′′(c)(x−c),f'(x) \approx f''(c)(x - c)\mathclose{\text{,}} since f′(c)=0.f'(c) = 0\mathclose{\text{.}} So one step of gradient descent gives

xk+1−c≈(1−ηf′′(c))(xk−c),x_{k+1} - c \approx \big(1 - \eta f''(c)\big)(x_k - c),

the parabola of Example 8.18 with q=f′′(c).q = f''(c)\mathclose{\text{.}} Started close to c,c\mathclose{\text{,}} gradient descent settles at cc when 0<η<2/f′′(c),0 < \eta < 2/f''(c)\mathclose{\text{,}} and fastest when η\eta is near 1/f′′(c).1/f''(c)\mathclose{\text{.}} This argument is a rule of thumb, not a proof: the approximation holds only close to c.c\mathclose{\text{.}} (When f′′f'' is continuous near c,c\mathclose{\text{,}} the Mean Value Theorem applied to f′f' turns it into a proof that the steps converge for 0<η<2/f′′(c).)0 < \eta < 2/f''(c)\mathclose{\text{.)}}

Choosing η=1/f′′(xk)\eta = 1/f''(x_k) afresh at every step turns gradient descent into xk+1=xk−f′(xk)/f′′(xk):x_{k+1} = x_k - f'(x_k)/f''(x_k)\mathclose{\text{:}} Newton’s method (Module 7) for the equation f′(x)=0.f'(x) = 0\mathclose{\text{.}} It converges fast, but it needs f′′,f''\mathclose{\text{,}} which for a model with millions of parameters is too expensive to compute; gradient descent needs only f′.f'\mathclose{\text{.}}

Figure 8.5 tries three step sizes on

f(x)=12x2+e−x.f(x) = \tfrac12x^2 + e^{-x}.

Here f′(x)=x−e−xf'(x) = x - e^{-x} and f′′(x)=1+e−x>0,f''(x) = 1 + e^{-x} > 0\mathclose{\text{,}} so the graph is concave up and its one critical number, the solution x∗≈0.567143x^* \approx 0.567143 of x=e−xx = e^{-x} found by Newton’s method in Module 7, gives the absolute minimum (Theorem 8.11). Since e−x∗=x∗,e^{-x^*} = x^*\mathclose{\text{,}} f′′(x∗)=1+x∗≈1.567:f''(x^*) = 1 + x^* \approx 1.567\mathclose{\text{:}} the rule of thumb predicts convergence for η<2/1.567≈1.28,\eta < 2/1.567 \approx 1.28\mathclose{\text{,}} fastest near η≈0.64.\eta \approx 0.64\mathclose{\text{.}}

Gradient descent on f(x) = tfrac12x^2 + e^{-x} from x0 = 3; the dashed line marks the minimum at x^ approx 0.567. With eta = 0.1 the steps creep towards it: 12 steps reach only x approx 1.004. With eta = 0.6 the third step is already within 0.01 of it. With eta = 1.4 the steps jump from side to side of the minimum, further out on each side every time they return to it; the fourth step lands at x4 approx 10.15.
Figure 8.5

Gradient descent on f(x)=12x2+e−xf(x) = \tfrac12x^2 + e^{-x} from x0=3;x_0 = 3\mathclose{\text{;}} the dashed line marks the minimum at x∗≈0.567.x^* \approx 0.567\mathclose{\text{.}} With η=0.1\eta = 0.1 the steps creep towards it: 12 steps reach only x≈1.004.x \approx 1.004\mathclose{\text{.}} With η=0.6\eta = 0.6 the third step is already within 0.01 of it. With η=1.4\eta = 1.4 the steps jump from side to side of the minimum, further out on each side every time they return to it; the fourth step lands at x4≈10.15.x_4 \approx 10.15\mathclose{\text{.}}

Compute itGradient descent in Python

The method is a loop of one line. With f′(x)=x−e−x:f'(x) = x - e^{-x}\mathclose{\text{:}}

Python
import math

def df(x):                              # f(x) = x**2/2 + exp(-x)
    return x - math.exp(-x)

def gradient_descent(x, eta, steps):
    xs = [x]
    for _ in range(steps):
        x = x - eta*df(x)
        xs.append(x)
    return xs

for eta in (0.1, 0.6, 1.4):
    xs = gradient_descent(3.0, eta, 7)
    print(f"eta = {eta}:", " ".join(f"{v:.4g}" for v in xs))
Output
eta = 0.1: 3 2.705 2.441 2.206 1.996 1.81 1.646 1.5
eta = 0.6: 3 1.23 0.6673 0.5748 0.5676 0.5672 0.5671 0.5671
eta = 1.4: 3 -1.13 4.787 -1.903 10.15 -4.061 82.85 -33.14

With η=1.4\eta = 1.4 the next step lands near 3.5×1014,3.5 \times 10^{14}\mathclose{\text{,}} and two steps later math.exp fails with an overflow error: the number exe^{x} it is asked for is too large for a float. A program needs a rule for when to stop, usually when ∣f′(xk)∣\abs{f'(x_k)} is tiny. How many steps does each step size need until ∣f′(xk)∣<10−10?\abs{f'(x_k)} < 10^{-10}\mathclose{\text{?}}

Python
def steps_needed(eta, tol=1e-10):
    x, k = 3.0, 0
    while abs(df(x)) > tol and k < 10000:
        x, k = x - eta*df(x), k + 1
    return k

for eta in (0.1, 0.3, 0.6, 1.0, 1.2):
    print(f"eta = {eta}: {steps_needed(eta)} steps")
Output
eta = 0.1: 146 steps
eta = 0.3: 40 steps
eta = 0.6: 10 steps
eta = 1.0: 42 steps
eta = 1.2: 188 steps

The best step size is near 1/f′′(x∗)≈0.64,1/f''(x^*) \approx 0.64\mathclose{\text{,}} as the rule of thumb says. Smaller steps waste time; larger ones zigzag about the minimum and close in more slowly, and above about 1.28 they diverge.

In machine learning, xx is a long list of parameters, ff is the loss, a measure of the model’s error on its training data, f′f' becomes the gradient of Module 17, and η\eta is the learning rate. The lessons of this section carry over: too small a learning rate wastes computing time, too large a rate makes the loss blow up, and the curvature of the loss decides which is which. Module 17 extends gradient descent to several variables, and Module 18 studies step sizes and what goes wrong when a function curves much more steeply in some directions than in others. The Mathematical Foundations series treats gradient methods and convexity from the computing side.

Watch out

Gradient descent finds a critical number, not necessarily the absolute minimum. On a function with several valleys, small steps settle in the valley where they start, and the steps can stall where f′f' is nearly 0 without there being a minimum. For f(x)=x4−4x3f(x) = x^4 - 4x^3 of Example 8.10, started at x0=−1x_0 = -1 with η=0.01,\eta = 0.01\mathclose{\text{,}} it creeps towards the flat point 0, which is not a minimum at all; after 1000 steps it is still at x≈−0.0081,x \approx -0.0081\mathclose{\text{,}} and it never gets past 0 to the true minimum at 3.

8

What you learned

  • An absolute maximum or minimum is the largest or smallest value of ff on its whole domain (or on an interval); a local one is the largest or smallest among nearby values. By Fermat’s theorem, local extrema occur at critical numbers, where f′=0f' = 0 or f′f' does not exist; not every critical number gives an extremum.
  • The closed interval method: a continuous function on [a,b][a, b] takes its absolute extreme values at critical numbers inside the interval or at the endpoints; compare the values there.
  • Rolle’s theorem and the Mean Value Theorem: if ff is continuous on [a,b][a, b] and differentiable on (a,b),(a, b)\mathclose{\text{,}} then f′(c)=f(b)−f(a)b−af'(c) = \dfrac{f(b) - f(a)}{b - a} for some cc in (a,b).(a, b)\mathclose{\text{.}} An average rate of change is an instantaneous rate somewhere. Cauchy’s version proves L’Hôpital’s rule.
  • Consequences: f′=0f' = 0 on an interval makes ff constant there; equal derivatives on an interval mean that the functions differ by a constant; f′>0f' > 0 makes ff increasing and f′<0f' < 0 decreasing.
  • The first derivative test classifies a critical number by the change of sign of f′;f'\mathclose{\text{;}} the second derivative test by the sign of f′′(c)f''(c) when f′(c)=0,f'(c) = 0\mathclose{\text{,}} and it says nothing when f′′(c)=0.f''(c) = 0\mathclose{\text{.}}
  • f′′>0f'' > 0 makes the graph concave up (convex), lying above its tangents; f′′<0f'' < 0 concave down. Inflection points are where the concavity changes; f′′(c)=0f''(c) = 0 there if f′′(c)f''(c) exists, but f′′(c)=0f''(c) = 0 alone does not make one.
  • To sketch a graph: domain, intercepts, symmetry, asymptotes, sign charts of f′f' and f′′,f''\mathclose{\text{,}} extrema and inflection points.
  • Optimisation: write the quantity as a function of one variable on the interval its meaning allows, find the critical numbers, and justify the absolute extremum by the closed interval method, by the sign of f′f' on each side, or by concavity.
  • Gradient descent, xk+1=xk−ηf′(xk),x_{k+1} = x_k - \eta f'(x_k)\mathclose{\text{,}} walks downhill. As a rule of thumb, near a minimum cc it converges when 0<η<2/f′′(c),0 < \eta < 2/f''(c)\mathclose{\text{,}} fastest near η=1/f′′(c);\eta = 1/f''(c)\mathclose{\text{;}} too large a step makes it diverge, and it can settle at a local minimum or stall at a flat point.
9

Exercises

Exercise 8.1★The closed interval method

Find the absolute maximum and minimum values of each function on the given interval.

  • (a) f(x)=x3−12x+1f(x) = x^3 - 12x + 1 on [−3,5][-3, 5]
  • (b) g(x)=x−2sin⁡xg(x) = x - 2\sin x on [0,2π][0, 2\pi]
Show solution✓ Checked

(a) f′(x)=3x2−12=3(x−2)(x+2),f'(x) = 3x^2 - 12 = 3(x - 2)(x + 2)\mathclose{\text{,}} so the critical numbers are ±2,\pm2\mathclose{\text{,}} both in (−3,5).(-3, 5)\mathclose{\text{.}} The values:

xx −3-3 −2-2 22 55
f(x)f(x) 1010 1717 −15-15 6666

The absolute maximum value is 66, at the endpoint 5, and the absolute minimum value is −15,-15\mathclose{\text{,}} at 2. The local maximum at −2-2 is not the absolute maximum.

(b) g′(x)=1−2cos⁡x=0g'(x) = 1 - 2\cos x = 0 when cos⁡x=12,\cos x = \tfrac12\mathclose{\text{,}} which in (0,2π)(0, 2\pi) happens at x=π3x = \tfrac{\pi}{3} and x=5π3.x = \tfrac{5\pi}{3}\mathclose{\text{.}} With sin⁡π3=32\sin\tfrac{\pi}{3} = \tfrac{\sqrt3}{2} and sin⁡5π3=−32:\sin\tfrac{5\pi}{3} = -\tfrac{\sqrt3}{2}\mathclose{\text{:}}

xx 00 π/3\pi/3 5π/35\pi/3 2π2\pi
g(x)g(x) 00 π/3−3≈−0.685\pi/3 - \sqrt3 \approx -0.685 5π/3+3≈6.9685\pi/3 + \sqrt3 \approx 6.968 2π≈6.2832\pi \approx 6.283

The absolute maximum value is 5π3+3≈6.968,\tfrac{5\pi}{3} + \sqrt3 \approx 6.968\mathclose{\text{,}} at 5π3,\tfrac{5\pi}{3}\mathclose{\text{,}} and the absolute minimum value is π3−3≈−0.685,\tfrac{\pi}{3} - \sqrt3 \approx -0.685\mathclose{\text{,}} at π3.\tfrac{\pi}{3}\mathclose{\text{.}}

Exercise 8.2★The number c of the Mean Value Theorem
  • (a) Check that f(x)=x2−4xf(x) = x^2 - 4x satisfies the hypotheses of the Mean Value Theorem on [1,5],[1, 5]\mathclose{\text{,}} and find every cc that the theorem promises.
  • (b) The same for f(x)=1xf(x) = \dfrac1x on [1,3].[1, 3]\mathclose{\text{.}}
  • (c) Why does the theorem not apply to f(x)=∣x−1∣f(x) = \abs{x - 1} on [0,3]?[0, 3]\mathclose{\text{?}} Is there a cc anyway?
  • (d) Show that for every quadratic f(x)=px2+qx+r,f(x) = px^2 + qx + r\mathclose{\text{,}} p≠0,p \ne 0\mathclose{\text{,}} and every interval [a,b],[a, b]\mathclose{\text{,}} the number cc is the midpoint a+b2.\tfrac{a + b}{2}\mathclose{\text{.}}
Show solution✓ Checked

(a) A polynomial is continuous and differentiable everywhere. f(1)=−3f(1) = -3 and f(5)=5,f(5) = 5\mathclose{\text{,}} so the secant slope is 5−(−3)5−1=2,\dfrac{5 - (-3)}{5 - 1} = 2\mathclose{\text{,}} and f′(c)=2c−4=2f'(c) = 2c - 4 = 2 gives c=3,c = 3\mathclose{\text{,}} which lies in (1,5).(1, 5)\mathclose{\text{.}}

(b) 1x\dfrac1x is continuous and differentiable for x≠0,x \ne 0\mathclose{\text{,}} so on [1,3].[1, 3]\mathclose{\text{.}} The secant slope is 13−13−1=−13,\dfrac{\tfrac13 - 1}{3 - 1} = -\dfrac13\mathclose{\text{,}} and f′(c)=−1c2=−13f'(c) = -\dfrac{1}{c^2} = -\dfrac13 gives c2=3,c^2 = 3\mathclose{\text{,}} so c=3≈1.732c = \sqrt3 \approx 1.732 (the solution −3-\sqrt3 is not in the interval).

(c) ∣x−1∣\abs{x - 1} has a corner at x=1,x = 1\mathclose{\text{,}} inside (0,3),(0, 3)\mathclose{\text{,}} so it is not differentiable on (0,3).(0, 3)\mathclose{\text{.}} And no cc exists: the secant slope is 2−13−0=13,\dfrac{2 - 1}{3 - 0} = \dfrac13\mathclose{\text{,}} while f′(x)f'(x) is −1-1 for x<1x < 1 and 1 for x>1.x > 1\mathclose{\text{.}}

(d) The secant slope is

f(b)−f(a)b−a=p(b2−a2)+q(b−a)b−a=p(b+a)+q,\begin{aligned} \frac{f(b) - f(a)}{b - a} &= \frac{p(b^2 - a^2) + q(b - a)}{b - a} \\ &= p(b + a) + q, \end{aligned}

dividing by b−ab - a after factoring b2−a2=(b−a)(b+a).b^2 - a^2 = (b - a)(b + a)\mathclose{\text{.}} And f′(c)=2pc+qf'(c) = 2pc + q equals it exactly when c=a+b2.c = \tfrac{a + b}{2}\mathclose{\text{.}} This is Exercise 1.11 read backwards: the secant over [a,b][a, b] is parallel to the tangent at the midpoint.

Exercise 8.3★Rise, fall and bend of a cubic

Let f(x)=x3−6x2+9x+2.f(x) = x^3 - 6x^2 + 9x + 2\mathclose{\text{.}}

  • (a) Find the intervals on which ff is increasing or decreasing, and its local extreme values.
  • (b) Find the intervals of concavity and the inflection point.
  • (c) Show that the inflection point is the midpoint of the segment joining the local maximum and the local minimum points.
Show solution✓ Checked

(a) f′(x)=3x2−12x+9=3(x−1)(x−3).f'(x) = 3x^2 - 12x + 9 = 3(x - 1)(x - 3)\mathclose{\text{.}} As in Example 8.6, f′>0f' > 0 for x<1,x < 1\mathclose{\text{,}} f′<0f' < 0 for 1<x<3,1 < x < 3\mathclose{\text{,}} and f′>0f' > 0 for x>3.x > 3\mathclose{\text{.}} So ff is increasing on (−∞,1](-\infty, 1] and [3,∞)[3, \infty) and decreasing on [1,3].[1, 3]\mathclose{\text{.}} By the first derivative test, f(1)=1−6+9+2=6f(1) = 1 - 6 + 9 + 2 = 6 is a local maximum value and f(3)=27−54+27+2=2f(3) = 27 - 54 + 27 + 2 = 2 a local minimum value.

(b) f′′(x)=6x−12f''(x) = 6x - 12 is negative for x<2x < 2 and positive for x>2:x > 2\mathclose{\text{:}} concave down on (−∞,2),(-\infty, 2)\mathclose{\text{,}} concave up on (2,∞),(2, \infty)\mathclose{\text{,}} with the inflection point (2,f(2))=(2,4).(2, f(2)) = (2, 4)\mathclose{\text{.}}

(c) The midpoint of (1,6)(1, 6) and (3,2)(3, 2) is (1+32,6+22)=(2,4),\big(\tfrac{1 + 3}{2}, \tfrac{6 + 2}{2}\big) = (2, 4)\mathclose{\text{,}} the inflection point. (Every cubic with two critical numbers behaves like this: its graph is symmetric under a half turn about its inflection point.)

Exercise 8.4★When the second derivative test fails

Let g(x)=3x5−5x3.g(x) = 3x^5 - 5x^3\mathclose{\text{.}}

  • (a) Find the critical numbers of g,g\mathclose{\text{,}} and use the second derivative test where it works.
  • (b) At which critical number does the test fail? Decide what happens there with the first derivative test.
  • (c) Find the inflection points.
Show solution✓ Checked

(a) g′(x)=15x4−15x2=15x2(x−1)(x+1),g'(x) = 15x^4 - 15x^2 = 15x^2(x - 1)(x + 1)\mathclose{\text{,}} so the critical numbers are −1,-1\mathclose{\text{,}} 0 and 1. g′′(x)=60x3−30x=30x(2x2−1).g''(x) = 60x^3 - 30x = 30x(2x^2 - 1)\mathclose{\text{.}} At 1, g′′(1)=30>0:g''(1) = 30 > 0\mathclose{\text{:}} g(1)=3−5=−2g(1) = 3 - 5 = -2 is a local minimum value. At −1,-1\mathclose{\text{,}} g′′(−1)=−30<0:g''(-1) = -30 < 0\mathclose{\text{:}} g(−1)=−3+5=2g(-1) = -3 + 5 = 2 is a local maximum value.

(b) At 0, g′′(0)=0,g''(0) = 0\mathclose{\text{,}} and the test says nothing. For 0<∣x∣<1,0 < \abs{x} < 1\mathclose{\text{,}} 15x2>015x^2 > 0 and x2−1<0,x^2 - 1 < 0\mathclose{\text{,}} so g′(x)<0g'(x) < 0 on both sides of 0: by the first derivative test, no extremum at 0. (gg is decreasing on [−1,1].)[-1, 1]\mathclose{\text{.)}}

(c) g′′(x)=30x(2x2−1)=0g''(x) = 30x(2x^2 - 1) = 0 at x=0x = 0 and x=±12,x = \pm\tfrac{1}{\sqrt2}\mathclose{\text{,}} and g′′g'' changes sign at each, since these are three simple zeros of a polynomial. With g(12)=342−522=−742=−728≈−1.237,g\big(\tfrac{1}{\sqrt2}\big) = \tfrac{3}{4\sqrt2} - \tfrac{5}{2\sqrt2} = -\tfrac{7}{4\sqrt2} = -\tfrac{7\sqrt2}{8} \approx -1.237\mathclose{\text{,}} and gg odd, the inflection points are (0,0)(0, 0) and (±12,∓728).\big(\pm\tfrac{1}{\sqrt2}, \mp\tfrac{7\sqrt2}{8}\big)\mathclose{\text{.}}

Exercise 8.5★★A graph with an oblique asymptote

Sketch the graph of f(x)=x2x−1,f(x) = \dfrac{x^2}{x - 1}\mathclose{\text{,}} following the checklist of Section 8.5. (Hint: x2=(x−1)(x+1)+1.)x^2 = (x - 1)(x + 1) + 1\mathclose{\text{.)}}

Show solution✓ Checked
  1. Domain. All x≠1.x \ne 1\mathclose{\text{.}}
  2. Intercepts. f(0)=0,f(0) = 0\mathclose{\text{,}} and f(x)=0f(x) = 0 only at x=0.x = 0\mathclose{\text{.}}
  3. Symmetry. None: f(−1)=−12,f(-1) = -\tfrac12\mathclose{\text{,}} while f(1)f(1) is not even defined.
  4. Asymptotes. By the hint, f(x)=x+1+1x−1.f(x) = x + 1 + \dfrac{1}{x - 1}\mathclose{\text{.}} As x→±∞,x \to \pm\infty\mathclose{\text{,}} 1x−1→0,\dfrac{1}{x - 1} \to 0\mathclose{\text{,}} so y=x+1y = x + 1 is an oblique asymptote; the graph is above it for x>1x > 1 and below it for x<1.x < 1\mathclose{\text{.}} As x→1+,x \to 1^+\mathclose{\text{,}} f(x)→∞;f(x) \to \infty\mathclose{\text{;}} as x→1−,x \to 1^-\mathclose{\text{,}} f(x)→−∞:f(x) \to -\infty\mathclose{\text{:}} x=1x = 1 is a vertical asymptote.
  5. Increase and decrease. f′(x)=1−1(x−1)2=(x−1)2−1(x−1)2=x(x−2)(x−1)2.f'(x) = 1 - \dfrac{1}{(x - 1)^2} = \dfrac{(x - 1)^2 - 1}{(x - 1)^2} = \dfrac{x(x - 2)}{(x - 1)^2}\mathclose{\text{.}} The denominator is positive, so f′f' has the sign of x(x−2):x(x - 2)\mathclose{\text{:}} positive for x<0x < 0 and x>2,x > 2\mathclose{\text{,}} negative for 0<x<10 < x < 1 and 1<x<2.1 < x < 2\mathclose{\text{.}} So ff is increasing on (−∞,0](-\infty, 0] and [2,∞),[2, \infty)\mathclose{\text{,}} and decreasing on [0,1)[0, 1) and (1,2].(1, 2]\mathclose{\text{.}}
  6. Extrema. f(0)=0f(0) = 0 is a local maximum value and f(2)=4f(2) = 4 a local minimum value. Notice that the local minimum is larger than the local maximum: they are on different branches.
  7. Concavity. f′′(x)=2(x−1)3,f''(x) = \dfrac{2}{(x - 1)^3}\mathclose{\text{,}} negative for x<1x < 1 and positive for x>1:x > 1\mathclose{\text{:}} concave down on (−∞,1),(-\infty, 1)\mathclose{\text{,}} concave up on (1,∞),(1, \infty)\mathclose{\text{,}} and no inflection point, since 1 is not in the domain.
  8. Sketch. Two branches hugging the line y=x+1:y = x + 1\mathclose{\text{:}} on the left, rising to the peak (0,0)(0, 0) and plunging down the asymptote x=1;x = 1\mathclose{\text{;}} on the right, coming down from +∞+\infty to the valley (2,4)(2, 4) and rising along y=x+1.y = x + 1\mathclose{\text{.}}
Exercise 8.6★★Bounds from the Mean Value Theorem
  • (a) Show that ∣sin⁡b−sin⁡a∣≤∣b−a∣\abs{\sin b - \sin a} \le \abs{b - a} for all real aa and b.b\mathclose{\text{.}}
  • (b) Show that x1+x<ln⁡(1+x)<x\dfrac{x}{1 + x} < \ln(1 + x) < x for every x>0.x > 0\mathclose{\text{.}} (Apply the Mean Value Theorem to ln⁡\ln on [1,1+x].)[1, 1 + x]\mathclose{\text{.)}}
  • (c) Use (b) to bound ln⁡1.1,\ln 1.1\mathclose{\text{,}} and compare with its value.
Show solution✓ Checked

(a) If a=ba = b both sides are 0. Otherwise, the Mean Value Theorem for sin⁡\sin on the interval between aa and bb gives sin⁡b−sin⁡a=cos⁡c (b−a)\sin b - \sin a = \cos c\,(b - a) for some cc between them, and ∣cos⁡c∣≤1,\abs{\cos c} \le 1\mathclose{\text{,}} so ∣sin⁡b−sin⁡a∣=∣cos⁡c∣ ∣b−a∣≤∣b−a∣.\abs{\sin b - \sin a} = \abs{\cos c}\,\abs{b - a} \le \abs{b - a}\mathclose{\text{.}} In words: the sine never changes faster than its input, because its slope is never steeper than 1.

(b) ln⁡\ln is continuous and differentiable on (0,∞),(0, \infty)\mathclose{\text{,}} with derivative 1t\dfrac1t (Module 6). On [1,1+x][1, 1 + x] the Mean Value Theorem gives a cc with 1<c<1+x1 < c < 1 + x and

ln⁡(1+x)−ln⁡1=1c⋅x,\ln(1 + x) - \ln 1 = \frac1c\cdot x,

As ln⁡1=0,\ln 1 = 0\mathclose{\text{,}} this says ln⁡(1+x)=xc.\ln(1 + x) = \dfrac{x}{c}\mathclose{\text{.}} From 1<c<1+x,1 < c < 1 + x\mathclose{\text{,}} 11+x<1c<1;\dfrac{1}{1 + x} < \dfrac1c < 1\mathclose{\text{;}} multiplying by x>0x > 0 gives x1+x<ln⁡(1+x)<x.\dfrac{x}{1 + x} < \ln(1 + x) < x\mathclose{\text{.}}

(c) With x=0.1:x = 0.1\mathclose{\text{:}} 0.11.1≈0.0909<ln⁡1.1<0.1.\dfrac{0.1}{1.1} \approx 0.0909 < \ln 1.1 < 0.1\mathclose{\text{.}} In fact ln⁡1.1≈0.0953,\ln 1.1 \approx 0.0953\mathclose{\text{,}} between the two bounds.

Exercise 8.7★★Maximum power transfer

A battery with voltage VV and internal resistance r>0r > 0 drives a device of resistance R.R\mathclose{\text{.}} By Ohm’s law the current is I=VR+r,I = \dfrac{V}{R + r}\mathclose{\text{,}} and the power delivered to the device is P=I2R.P = I^2R\mathclose{\text{.}}

  • (a) Show that P(R)=V2R(R+r)2P(R) = \dfrac{V^2R}{(R + r)^2} is largest, over all R>0,R > 0\mathclose{\text{,}} when R=r,R = r\mathclose{\text{,}} and find the largest power.
  • (b) Suppose, hypothetically, that V=12V = 12 volts and r=0.5r = 0.5 ohms. Find the best RR and the largest power, in watts.
Show solution✓ Checked

(a) By the quotient rule,

P′(R)=V2 (R+r)2−R⋅2(R+r)(R+r)4=V2 (R+r)−2R(R+r)3=V2(r−R)(R+r)3,\begin{aligned} P'(R) &= V^2\,\frac{(R + r)^2 - R\cdot2(R + r)}{(R + r)^4} \\ &= V^2\,\frac{(R + r) - 2R}{(R + r)^3} = \frac{V^2(r - R)}{(R + r)^3}, \end{aligned}

cancelling one factor R+r.R + r\mathclose{\text{.}} For R>0R > 0 the denominator is positive, so P′(R)>0P'(R) > 0 for R<rR < r and P′(R)<0P'(R) < 0 for R>r.R > r\mathclose{\text{.}} By Theorem 8.14 (with I=(0,∞)),I = (0, \infty)\mathclose{\text{),}} P(r)P(r) is the absolute maximum:

P(r)=V2r(2r)2=V24r.P(r) = \frac{V^2r}{(2r)^2} = \frac{V^2}{4r}.

This is the maximum power transfer theorem of electrical engineering: a source delivers the most power to a load whose resistance matches its own.

(b) R=0.5R = 0.5 ohms, and P=1224⋅0.5=1442=72P = \dfrac{12^2}{4 \cdot 0.5} = \dfrac{144}{2} = 72 watts.

Exercise 8.8★★The best step for a central difference

Section 4.7 bounded the size of the error of the central difference of x3x^3 at 1, in floating point, by about E(h)=h2+εh,E(h) = h^2 + \dfrac{\varepsilon}{h}\mathclose{\text{,}} where ε=2−52≈2.2×10−16,\varepsilon = 2^{-52} \approx 2.2 \times 10^{-16}\mathclose{\text{,}} and stated that this bound is smallest at h=(ε/2)1/3.h = (\varepsilon/2)^{1/3}\mathclose{\text{.}}

  • (a) Prove it: show that EE has its absolute minimum on (0,∞)(0, \infty) at h∗=(ε/2)1/3,h^* = (\varepsilon/2)^{1/3}\mathclose{\text{,}} and that E(h∗)=3h∗2.E(h^*) = 3h^{*2}\mathclose{\text{.}}
  • (b) Compute h∗h^* and E(h∗),E(h^*)\mathclose{\text{,}} and compare with Section 4.7.
Show solution✓ Checked

(a) E′(h)=2h−εh2,E'(h) = 2h - \dfrac{\varepsilon}{h^2}\mathclose{\text{,}} which is 0 when 2h3=ε,2h^3 = \varepsilon\mathclose{\text{,}} that is, at h∗=(ε/2)1/3,h^* = (\varepsilon/2)^{1/3}\mathclose{\text{,}} its only critical number in (0,∞).(0, \infty)\mathclose{\text{.}} And E′′(h)=2+2εh3>0E''(h) = 2 + \dfrac{2\varepsilon}{h^3} > 0 for h>0,h > 0\mathclose{\text{,}} so EE is concave up on (0,∞),(0, \infty)\mathclose{\text{,}} and by Theorem 8.11 E(h∗)E(h^*) is the absolute minimum. Since h∗3=ε/2,h^{*3} = \varepsilon/2\mathclose{\text{,}} εh∗=εh∗2h∗3=2h∗2,\dfrac{\varepsilon}{h^*} = \dfrac{\varepsilon h^{*2}}{h^{*3}} = 2h^{*2}\mathclose{\text{,}} so E(h∗)=h∗2+2h∗2=3h∗2:E(h^*) = h^{*2} + 2h^{*2} = 3h^{*2}\mathclose{\text{:}} at the best step, the rounding part of the bound, ε/h∗,\varepsilon/h^*\mathclose{\text{,}} is twice the truncation part, h∗2.h^{*2}\mathclose{\text{.}}

(b) h∗=(2−53)1/3≈4.8×10−6h^* = \big(2^{-53}\big)^{1/3} \approx 4.8 \times 10^{-6} and E(h∗)=3h∗2≈6.9×10−11.E(h^*) = 3h^{*2} \approx 6.9 \times 10^{-11}\mathclose{\text{.}} Section 4.7 gave “about 5×10−65 \times 10^{-6}” and “about 7×10−117 \times 10^{-11}”, the same numbers rounded, and its table had its smallest central errors in size, about 10−10,10^{-10}\mathclose{\text{,}} near these steps.

Exercise 8.9★★Gradient descent by hand

A machine-learning model predicts y=wxy = wx from x,x\mathclose{\text{,}} with one parameter w.w\mathclose{\text{.}} On three (made-up) measurements (x,y)=(1,2),(x, y) = (1, 2)\mathclose{\text{,}} (2,3)(2, 3) and (3,7),(3, 7)\mathclose{\text{,}} its mean squared error is

L(w)=(w−2)2+(2w−3)2+(3w−7)23.L(w) = \frac{(w - 2)^2 + (2w - 3)^2 + (3w - 7)^2}{3}.
  • (a) Expand L,L\mathclose{\text{,}} and find the ww that minimises it.
  • (b) Show that gradient descent with step size η\eta satisfies wk+1−w∗=(1−283η)(wk−w∗),w_{k+1} - w^* = \big(1 - \tfrac{28}{3}\eta\big)(w_k - w^*)\mathclose{\text{,}} where w∗w^* is the minimiser. For which η\eta does it converge? Which η\eta lands on w∗w^* in one step?
  • (c) Starting from w0=0,w_0 = 0\mathclose{\text{,}} compute w1,w_1\mathclose{\text{,}} w2,w_2\mathclose{\text{,}} w3w_3 with η=0.05,\eta = 0.05\mathclose{\text{,}} and then with η=0.25.\eta = 0.25\mathclose{\text{.}}
Show solution✓ Checked

(a) Expanding the squares, (w2−4w+4)+(4w2−12w+9)+(9w2−42w+49)=14w2−58w+62,(w^2 - 4w + 4) + (4w^2 - 12w + 9) + (9w^2 - 42w + 49) = 14w^2 - 58w + 62\mathclose{\text{,}} so

L(w)=14w2−58w+623,L′(w)=28w−583.\begin{aligned} L(w) &= \frac{14w^2 - 58w + 62}{3}, \\ L'(w) &= \frac{28w - 58}{3}. \end{aligned}

L′(w)=0L'(w) = 0 at w∗=5828=2914≈2.071,w^* = \tfrac{58}{28} = \tfrac{29}{14} \approx 2.071\mathclose{\text{,}} and L′′(w)=283>0,L''(w) = \tfrac{28}{3} > 0\mathclose{\text{,}} so by Theorem 8.11 this is the absolute minimum.

(b) Since 58=28w∗,58 = 28w^*\mathclose{\text{,}} L′(w)=283(w−w∗),L'(w) = \tfrac{28}{3}(w - w^*)\mathclose{\text{,}} and one step gives

wk+1−w∗=(wk−w∗)−η⋅283(wk−w∗)=(1−283η)(wk−w∗).\begin{aligned} w_{k+1} - w^* &= (w_k - w^*) - \eta\cdot\tfrac{28}{3}(w_k - w^*) \\ &= \big(1 - \tfrac{28}{3}\eta\big)(w_k - w^*). \end{aligned}

This is Example 8.18 with q=L′′=283:q = L'' = \tfrac{28}{3}\mathclose{\text{:}} it converges exactly when 0<η<228/3=314≈0.214,0 < \eta < \tfrac{2}{28/3} = \tfrac{3}{14} \approx 0.214\mathclose{\text{,}} and η=328≈0.107\eta = \tfrac{3}{28} \approx 0.107 lands on w∗w^* in one step.

(c) By (b), wk=w∗−(1−283η)kw∗.w_k = w^* - \big(1 - \tfrac{28}{3}\eta\big)^k w^*\mathclose{\text{.}} With η=0.05\eta = 0.05 the factor is 1−1.43=815,1 - \tfrac{1.4}{3} = \tfrac{8}{15}\mathclose{\text{,}} and

w1=2930≈0.967,w2=667450≈1.482,w3=118616750≈1.757,\begin{aligned} w_1 &= \tfrac{29}{30} \approx 0.967, \\ w_2 &= \tfrac{667}{450} \approx 1.482, \\ w_3 &= \tfrac{11861}{6750} \approx 1.757, \end{aligned}

closing in on 2.071, each step removing the same fraction 715\tfrac{7}{15} of the remaining distance. With η=0.25,\eta = 0.25\mathclose{\text{,}} above 314,\tfrac{3}{14}\mathclose{\text{,}} the factor is 1−73=−43,1 - \tfrac73 = -\tfrac43\mathclose{\text{,}} and

w1=296≈4.833,w2=−2918≈−1.611,w3=37754≈6.981:\begin{aligned} w_1 &= \tfrac{29}{6} \approx 4.833, \\ w_2 &= -\tfrac{29}{18} \approx -1.611, \\ w_3 &= \tfrac{377}{54} \approx 6.981: \end{aligned}

each step overshoots further than the last.

Exercise 8.10★★★eπe^\pi or πe?\pi^e\mathclose{\text{?}}
  • (a) Find the absolute maximum value of f(x)=ln⁡xxf(x) = \dfrac{\ln x}{x} on (0,∞).(0, \infty)\mathclose{\text{.}}
  • (b) Without a calculator, decide which is larger, eπe^\pi or πe.\pi^e\mathclose{\text{.}}
  • (c) Module 6 found that y=x1/xy = x^{1/x} has a horizontal tangent at x=e.x = e\mathclose{\text{.}} Show that e1/ee^{1/e} is its absolute maximum value on (0,∞).(0, \infty)\mathclose{\text{.}}
Show solution✓ Checked

(a) By the quotient rule, f′(x)=1x⋅x−ln⁡xx2=1−ln⁡xx2.f'(x) = \dfrac{\frac1x\cdot x - \ln x}{x^2} = \dfrac{1 - \ln x}{x^2}\mathclose{\text{.}} Since ln⁡\ln is increasing with ln⁡e=1,\ln e = 1\mathclose{\text{,}} f′(x)>0f'(x) > 0 for 0<x<e0 < x < e and f′(x)<0f'(x) < 0 for x>e.x > e\mathclose{\text{.}} By Theorem 8.14 the absolute maximum value is f(e)=1e,f(e) = \dfrac{1}{e}\mathclose{\text{,}} and f(x)<1ef(x) < \dfrac1e for every x≠e.x \ne e\mathclose{\text{.}}

(b) Since π≠e,\pi \ne e\mathclose{\text{,}} (a) gives ln⁡ππ<1e.\dfrac{\ln\pi}{\pi} < \dfrac1e\mathclose{\text{.}} Multiply by eπ>0:e\pi > 0\mathclose{\text{:}} eln⁡π<π,e\ln\pi < \pi\mathclose{\text{,}} that is, ln⁡(πe)<ln⁡(eπ).\ln\big(\pi^e\big) < \ln\big(e^\pi\big)\mathclose{\text{.}} As ln⁡\ln is increasing, πe<eπ.\pi^e < e^\pi\mathclose{\text{.}} (In fact eπ≈23.14e^\pi \approx 23.14 and πe≈22.46.)\pi^e \approx 22.46\mathclose{\text{.)}}

(c) For x>0,x > 0\mathclose{\text{,}} x1/x=e(ln⁡x)/x,x^{1/x} = e^{(\ln x)/x}\mathclose{\text{,}} and eue^u is increasing in u.u\mathclose{\text{.}} By (a), the exponent (ln⁡x)/x(\ln x)/x is largest, 1e,\tfrac1e\mathclose{\text{,}} at x=e,x = e\mathclose{\text{,}} and smaller everywhere else; so x1/xx^{1/x} is largest at x=e,x = e\mathclose{\text{,}} with value e1/e≈1.4447.e^{1/e} \approx 1.4447\mathclose{\text{.}} This is the promise Module 6 made.

Exercise 8.11★★★The longest pipe round a corner

A corridor 2.7 m wide meets a corridor 0.8 m wide at a right angle. A straight pipe, carried level and thin enough to ignore its thickness, is to be moved from one corridor into the other. What is the longest pipe that fits round the corner?

Hint: a segment that touches the inner corner and makes the angle θ\theta with the walls of the wide corridor reaches the outer walls when its length is L(θ)=2.7sin⁡θ+0.8cos⁡θ,L(\theta) = \dfrac{2.7}{\sin\theta} + \dfrac{0.8}{\cos\theta}\mathclose{\text{,}} for 0<θ<π2.0 < \theta < \dfrac{\pi}{2}\mathclose{\text{.}} A pipe can pass the corner exactly when it is no longer than every such segment.

Show solution✓ Checked

The pipe passes exactly when its length is at most the smallest value of LL on (0,π2);\big(0, \tfrac{\pi}{2}\big)\mathclose{\text{;}} at the angle where LL is smallest, a longer pipe would jam. So minimise L.L\mathclose{\text{.}} By the chain rule,

L′(θ)=−2.7cos⁡θsin⁡2θ+0.8sin⁡θcos⁡2θ=0.8sin⁡3θ−2.7cos⁡3θsin⁡2θcos⁡2θ.\begin{aligned} L'(\theta) &= -\frac{2.7\cos\theta}{\sin^2\theta} + \frac{0.8\sin\theta}{\cos^2\theta} \\ &= \frac{0.8\sin^3\theta - 2.7\cos^3\theta}{\sin^2\theta\cos^2\theta}. \end{aligned}

The top equals cos⁡3θ (0.8tan⁡3θ−2.7),\cos^3\theta\,(0.8\tan^3\theta - 2.7)\mathclose{\text{,}} so L′(θ)=0L'(\theta) = 0 when tan⁡3θ=2.70.8=3.375=1.53,\tan^3\theta = \dfrac{2.7}{0.8} = 3.375 = 1.5^3\mathclose{\text{,}} that is, at tan⁡θ∗=1.5.\tan\theta^* = 1.5\mathclose{\text{.}} Since tan⁡\tan is increasing on (0,π2),\big(0, \tfrac{\pi}{2}\big)\mathclose{\text{,}} L′<0L' < 0 for θ<θ∗\theta < \theta^* and L′>0L' > 0 for θ>θ∗,\theta > \theta^*\mathclose{\text{,}} so by Theorem 8.14 L(θ∗)L(\theta^*) is the absolute minimum. A right triangle with legs 1 and 1.5 has hypotenuse 1+2.25=3.25=132,\sqrt{1 + 2.25} = \sqrt{3.25} = \tfrac{\sqrt{13}}{2}\mathclose{\text{,}} so sin⁡θ∗=313\sin\theta^* = \dfrac{3}{\sqrt{13}} and cos⁡θ∗=213,\cos\theta^* = \dfrac{2}{\sqrt{13}}\mathclose{\text{,}} and

L(θ∗)=2.7133+0.8132=(0.9+0.4)13=1.313≈4.687 m.\begin{aligned} L(\theta^*) &= \frac{2.7\sqrt{13}}{3} + \frac{0.8\sqrt{13}}{2} \\ &= (0.9 + 0.4)\sqrt{13} = 1.3\sqrt{13} \\ &\approx 4.687 \text{ m}. \end{aligned}

The longest pipe that fits is about 4.69 m. In general, for corridors of widths pp and qq the same steps give (p2/3+q2/3)3/2;(p^{2/3} + q^{2/3})^{3/2}\mathclose{\text{;}} check that it gives 4.687 here.

Exercise 8.12★★★The equation f′=kff' = kf
  • (a) Let kk be a constant, and let ff be differentiable on R\R with f′(x)=kf(x)f'(x) = kf(x) for every x.x\mathclose{\text{.}} Show that f(x)=f(0)ekxf(x) = f(0)e^{kx} for every x.x\mathclose{\text{.}} (Consider g(x)=f(x)e−kx.)g(x) = f(x)e^{-kx}\mathclose{\text{.)}}
  • (b) Deduce that exe^x is the only function with f′=ff' = f and f(0)=1.f(0) = 1\mathclose{\text{.}}
  • (c) In the same way, show that if f′(x)=2xf(x)f'(x) = 2xf(x) for every x,x\mathclose{\text{,}} then f(x)=f(0)ex2.f(x) = f(0)e^{x^2}\mathclose{\text{.}}
Show solution✓ Checked

(a) By the product rule and the chain rule,

g′(x)=f′(x)e−kx+f(x)⋅(−ke−kx)=(f′(x)−kf(x))e−kx=0\begin{aligned} g'(x) &= f'(x)e^{-kx} + f(x)\cdot\big(-ke^{-kx}\big) \\ &= \big(f'(x) - kf(x)\big)e^{-kx} = 0 \end{aligned}

for every x,x\mathclose{\text{,}} since f′=kf.f' = kf\mathclose{\text{.}} By Theorem 8.5, applied on the interval R,\R\mathclose{\text{,}} gg is constant: g(x)=g(0)=f(0)e0=f(0).g(x) = g(0) = f(0)e^0 = f(0)\mathclose{\text{.}} So f(x)e−kx=f(0),f(x)e^{-kx} = f(0)\mathclose{\text{,}} and multiplying by ekxe^{kx} gives f(x)=f(0)ekx.f(x) = f(0)e^{kx}\mathclose{\text{.}}

(b) With k=1k = 1 and f(0)=1,f(0) = 1\mathclose{\text{,}} (a) gives f(x)=ex.f(x) = e^x\mathclose{\text{.}} Module 6 showed that exe^x has these two properties; now no other function has them. In the same way, Module 6’s models of growth and decay, N(t)=N0ekt,N(t) = N_0e^{kt}\mathclose{\text{,}} are the only solutions of N′=kNN' = kN with N(0)=N0:N(0) = N_0\mathclose{\text{:}} a quantity that grows at a rate proportional to its size must grow exponentially. Module 13 meets such equations again.

(c) Let g(x)=f(x)e−x2.g(x) = f(x)e^{-x^2}\mathclose{\text{.}} Then

g′(x)=f′(x)e−x2−2xf(x)e−x2=(f′(x)−2xf(x))e−x2=0,\begin{aligned} g'(x) &= f'(x)e^{-x^2} - 2xf(x)e^{-x^2} \\ &= \big(f'(x) - 2xf(x)\big)e^{-x^2} = 0, \end{aligned}

so g(x)=g(0)=f(0)g(x) = g(0) = f(0) for every x,x\mathclose{\text{,}} and f(x)=f(0)ex2.f(x) = f(0)e^{x^2}\mathclose{\text{.}}

10

Check yourself

1
Suppose f′(3)=0.f'(3) = 0\mathclose{\text{.}} Which statement must be true?
2
The absolute maximum value of f(x)=x2−2xf(x) = x^2 - 2x on [0,3][0, 3] is
3
ff is differentiable on R,\R\mathclose{\text{,}} f(1)=2f(1) = 2 and f(4)=11.f(4) = 11\mathclose{\text{.}} The Mean Value Theorem guarantees a number cc in (1,4)(1, 4) with
4
f′(x)=0f'(x) = 0 for every xx in the domain (−∞,0)∪(0,∞)(-\infty, 0) \cup (0, \infty) of f.f\mathclose{\text{.}} What follows?
5
f′(2)=0f'(2) = 0 and f′′(2)=−3.f''(2) = -3\mathclose{\text{.}} Then
6
Which of these functions has an inflection point at x=0?x = 0\mathclose{\text{?}}
7
A rectangle has perimeter 20 cm. What is its largest possible area?
8
Gradient descent xk+1=xk−ηf′(xk)x_{k+1} = x_k - \eta f'(x_k) on f(x)=2x2f(x) = 2x^2 approaches the minimum 0 from every x0≠0x_0 \ne 0 exactly when
Finished this module?