Unit 10, lesson 122

Graphing Software and Numerical Reliability

How a computer graph is made from finitely many rounded samples, how it can hide or invent features, and how the derivative theorems turn what a graph suggests into a proof.

  • Theory part 243
  • Practice part 244
  • Reliable Computation

A graphing tool draws a smooth looking curve in a fraction of a second, and it is tempting to read answers straight off the screen. But the screen only shows a few hundred computed points, each one rounded, joined by straight segments inside a rectangle someone chose. That picture is a superb guide and a poor judge. This lesson pairs the theorems that describe a graph’s shape with the ways a computed graph can mislead you.

Key terms

Extrema and how a graph shows them

Definition Let ff be defined on a set DD and let c∈Dc \in D. The value f(c)f(c) is the absolute maximum of ff on DD if f(c)≥f(x)f(c) \ge f(x) for every x∈Dx \in D, and the absolute minimum if f(c)≤f(x)f(c) \le f(x) for every x∈Dx \in D. It is a local maximum if there is an open interval JJ containing cc such that f(c)≥f(x)f(c) \ge f(x) for every x∈D∩Jx \in D \cap J, and a local minimum if the same holds with ≤\le in place of ≥\ge. By Fermat’s theorem, if ff has a local extremum at a point cc in the interior of DD and f′(c)f'(c) exists, then

f′(c)=0.f'(c) = 0.

So the absolute extrema of a continuous function on a closed interval [a,b][a, b] occur at the endpoints or at critical numbers in (a,b)(a, b), the points where f′=0f' = 0 or f′f' does not exist.

In plain words Peaks and valleys on a graph tell you roughly where to look. The derivative and the endpoint values tell you exactly where they are and how high or low they go.

Example Take f(x)=x3−3xf(x) = x^3 - 3x on [−2,3][-2, 3]. A plot shows a hump near x=−1x = -1 and a dip near x=1x = 1. Since f′(x)=3x2−3f'(x) = 3x^2 - 3, the critical numbers are exactly ±1\pm 1. Compare the candidates.

xx−2-2−1-11133
f(x)f(x)−2-222−2-21818

At the critical numbers there is a local maximum 22 at x=−1x = -1 and a local minimum −2-2 at x=1x = 1. On [−2,3][-2, 3] the absolute maximum is 1818 at x=3x = 3, and the absolute minimum −2-2 is reached twice, at x=−2x = -2 and at x=1x = 1.

Extreme value theorem

Definition If ff is continuous on a closed, bounded interval [a,b][a, b], then there are numbers cc and dd in [a,b][a, b] with

f(c)≤f(x)≤f(d)for every x∈[a,b].f(c) \le f(x) \le f(d) \quad \text{for every } x \in [a, b].

That is, ff attains an absolute minimum f(c)f(c) and an absolute maximum f(d)f(d) on [a,b][a, b]. Both hypotheses matter. On the half-open interval (0,1](0, 1] the continuous function f(x)=1xf(x) = \frac{1}{x} has no maximum, and a function with a jump can miss its highest value.

In plain words A continuous curve drawn over a closed interval has a highest point and a lowest point. The theorem guarantees they exist, and the candidate list above finds them.

Example Consider f(x)=x2−4xf(x) = x^2 - 4x on [0,5][0, 5]. Its only critical number is x=2x = 2, with f(2)=−4f(2) = -4. The endpoints give f(0)=0f(0) = 0 and f(5)=5f(5) = 5. So the absolute minimum is −4-4 and the absolute maximum is 55, exactly as the theorem promises.

Rolle’s theorem

Definition Suppose ff is continuous on [a,b][a, b], differentiable on (a,b)(a, b), and f(a)=f(b)f(a) = f(b). Then there is at least one number cc in (a,b)(a, b) with

f′(c)=0.f'(c) = 0.

In plain words If a smooth curve starts and ends at the same height, somewhere in between it has a flat tangent.

Example For f(x)=x2−4xf(x) = x^2 - 4x on [0,4][0, 4] we have f(0)=f(4)=0f(0) = f(4) = 0, and ff is a polynomial, so the hypotheses hold. Solving f′(c)=2c−4=0f'(c) = 2c - 4 = 0 gives c=2c = 2, which lies in (0,4)(0, 4).

Mean value theorem

Definition Suppose ff is continuous on [a,b][a, b] and differentiable on (a,b)(a, b). Then there is at least one 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}.

In plain words Somewhere along the way the tangent line is parallel to the secant line joining the endpoints. If your average speed on a trip was 80, at some instant the speedometer read exactly 80.

Example For f(x)=x3f(x) = x^3 on [0,2][0, 2] the secant slope is

f(2)−f(0)2−0=8−02=4.\frac{f(2) - f(0)}{2 - 0} = \frac{8 - 0}{2} = 4.

Solving 3c2=43c^2 = 4 gives c=23≈1.155c = \frac{2}{\sqrt{3}} \approx 1.155, which lies in (0,2)(0, 2).

Monotonicity

Definition 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 are points of II, and decreasing on II if f(x1)>f(x2)f(x_1) > f(x_2) whenever x1<x2x_1 < x_2 are points of II. The increasing and decreasing test says that if ff is continuous on II and f′(x)>0f'(x) > 0 at every interior point xx of II, then ff is increasing on II. If instead f′(x)<0f'(x) < 0 at every interior point, then ff is decreasing on II. The test follows from the mean value theorem.

In plain words The sign of the derivative tells you whether the graph rises or falls, and it does so for every point of the interval, not just the ones that were plotted.

Example For f(x)=x3−3xf(x) = x^3 - 3x the derivative factors as f′(x)=3(x−1)(x+1)f'(x) = 3(x - 1)(x + 1). It is positive for x<−1x < -1 and x>1x > 1 and negative for −1<x<1-1 < x < 1. So ff is increasing on (−∞,−1](-\infty, -1] and on [1,∞)[1, \infty), and decreasing on [−1,1][-1, 1].

Concavity

Definition Let ff be differentiable on an open interval II. The graph of ff is concave up on II if f′f' is increasing on II, and concave down on II if f′f' is decreasing on II. The concavity test says that if f′′(x)>0f''(x) > 0 for all xx in II, the graph is concave up on II, and if f′′(x)<0f''(x) < 0 for all xx in II, it is concave down on II. A point (c,f(c))(c, f(c)) of the graph is an inflection point if ff is continuous at cc and the graph changes from concave up to concave down, or from concave down to concave up, at cc.

In plain words Concave up bends like a cup, concave down bends like a cap. The second derivative says which one you have.

Example For f(x)=x3−3xf(x) = x^3 - 3x the second derivative is f′′(x)=6xf''(x) = 6x. The graph is concave down on (−∞,0)(-\infty, 0) and concave up on (0,∞)(0, \infty), so (0,0)(0, 0) is an inflection point.

Window selection

Definition The viewing window of a plot is the rectangle [xmin⁡,xmax⁡]×[ymin⁡,ymax⁡][x_{\min}, x_{\max}] \times [y_{\min}, y_{\max}] of the plane that is drawn on the screen. Features smaller than about one pixel in either direction, or outside the rectangle, cannot be seen.

In plain words The window is a choice, and a bad choice can hide the most interesting part of the graph. Zoom in and out before you believe a shape.

Example The cubic f(x)=x3−0.03xf(x) = x^3 - 0.03x looks like a plain increasing curve in the window [−10,10]×[−10,10][-10, 10] \times [-10, 10]. Yet f′(x)=3x2−0.03f'(x) = 3x^2 - 0.03 vanishes at x=±0.1x = \pm 0.1, and

f(−0.1)=0.002,f(0.1)=−0.002f(-0.1) = 0.002, \qquad f(0.1) = -0.002

are a local maximum and a local minimum. The bumps rise and fall by 0.0020.002 in a window 2020 units tall, about ten thousand times smaller, so only a window like [−0.2,0.2]×[−0.005,0.005][-0.2, 0.2] \times [-0.005, 0.005] shows them.

Sampling

Definition A plotter evaluates ff at finitely many sample points x0<x1<⋯<xNx_0 < x_1 < \dots < x_N in the window and joins consecutive points (xk,f(xk))(x_k, f(x_k)) with line segments. The drawn curve agrees with ff only at the samples. What ff does strictly between two samples is not computed at all.

In plain words The computer connects the dots. If the function wiggles faster than the dots are spaced, the picture can be completely wrong.

Example Plot f(x)=sin⁡(100πx)f(x) = \sin(100\pi x) on [0,1][0, 1] with the 51 equally spaced samples xk=k50x_k = \frac{k}{50}. Every sample gives

f(xk)=sin⁡(2πk)=0,f(x_k) = \sin(2\pi k) = 0,

so the screen shows a flat line on the xx axis. The true graph oscillates between −1-1 and 11 fifty times on that interval.

Roundoff

Definition A computer stores real numbers in floating point form with a fixed number of binary digits. In standard double precision with rounding to nearest, each real number xx in the normal range is stored as

fl⁡(x)=x(1+δ),∣δ∣≤u=2−53≈1.1×10−16,\operatorname{fl}(x) = x(1 + \delta), \qquad \lvert \delta \rvert \le u = 2^{-53} \approx 1.1 \times 10^{-16},

and each arithmetic operation returns the exact result rounded the same way. Roundoff error is the difference between a computed value and the exact value that comes from these roundings.

In plain words The machine keeps about 16 significant decimal digits. Usually that is plenty, but when two nearly equal numbers are subtracted, most of those digits cancel and what remains can be mostly noise.

Example The function

g(x)=1−cos⁡xx2g(x) = \frac{1 - \cos x}{x^2}

tends to 12\frac{1}{2} as x→0x \to 0. In double precision g(10−3)≈0.49999996g(10^{-3}) \approx 0.49999996, which is fine. But cos⁡(10−8)=1−5×10−17\cos(10^{-8}) = 1 - 5 \times 10^{-17} to many digits. The floating point number just below 11 is 1−2−53≈1−1.1×10−161 - 2^{-53} \approx 1 - 1.1 \times 10^{-16}, and cos⁡(10−8)\cos(10^{-8}) lies less than halfway from 11 to it, so it rounds to exactly 11. The numerator becomes 1−1=01 - 1 = 0 and the computer returns g(10−8)=0g(10^{-8}) = 0, although the true value is about 0.50.5. A plot of gg very close to 00 shows ragged noise and drops to zero, though the true graph is smooth.

Truncation

Definition Truncation error is the error made when an exact infinite or limiting process is replaced by a finite one, such as stopping a series after finitely many terms, using a difference quotient with a fixed hh instead of a limit, or replacing an integral by a finite sum. It is present even if every arithmetic step is done exactly.

In plain words Roundoff comes from storing numbers. Truncation comes from stopping early. Both affect every computed graph and table.

Example Start from the series

e=∑k=0∞1k!e = \sum_{k=0}^{\infty} \frac{1}{k!}

and stop after the term with k=4k = 4. That gives

1+1+12+16+124≈2.70833,1 + 1 + \frac{1}{2} + \frac{1}{6} + \frac{1}{24} \approx 2.70833,

while e≈2.71828e \approx 2.71828. The truncation error is about 0.009950.00995, and no amount of extra precision in the arithmetic would remove it.

Graph evidence versus proof

Definition A computed graph is the picture of finitely many rounded values of ff in one window. It is evidence and can suggest a conjecture, but it is not a proof of any statement about all xx in an interval. A proof uses exact reasoning that covers every point, for example the intermediate value theorem, the extreme value theorem, the mean value theorem or the derivative tests above.

In plain words Use the graph to guess, then use calculus to be sure. A statement such as “these curves meet only twice” needs an argument, not a screenshot.

Example In the window [0,5]×[0,30][0, 5] \times [0, 30] the curves y=2xy = 2^x and y=x2y = x^2 appear to meet only at x=2x = 2 and x=4x = 4. They meet a third time. Let g(x)=2x−x2g(x) = 2^x - x^2, which is continuous. Since

g(−1)=0.5−1=−0.5<0andg(0)=1>0,g(-1) = 0.5 - 1 = -0.5 < 0 \quad \text{and} \quad g(0) = 1 > 0,

the intermediate value theorem gives a root in (−1,0)(-1, 0). Bisection places it near x≈−0.767x \approx -0.767.

Check yourself

  1. Verify that f(x)=x2−6x+5f(x) = x^2 - 6x + 5 satisfies the hypotheses of Rolle’s theorem on [1,5][1, 5] and find the number cc it promises.
Show the answer

The function is a polynomial, so it is continuous on [1,5][1, 5] and differentiable on (1,5)(1, 5), and f(1)=0=f(5)f(1) = 0 = f(5). Solving f′(c)=2c−6=0f'(c) = 2c - 6 = 0 gives c=3c = 3, which lies in (1,5)(1, 5).

  1. A plot of h(x)=cos⁡(20πx)h(x) = \cos(20\pi x) on [0,1][0, 1] uses the 11 samples xk=k10x_k = \frac{k}{10}. What does the screen show, and why?
Show the answer

Every sample gives h(xk)=cos⁡(2πk)=1h(x_k) = \cos(2\pi k) = 1, so the screen shows the horizontal line y=1y = 1. The true graph oscillates between −1-1 and 11 ten times, and all of that happens between samples.

  1. A plot suggests that f(x)=x3+xf(x) = x^3 + x is increasing everywhere. Prove it.
Show the answer

The derivative satisfies f′(x)=3x2+1≥1>0f'(x) = 3x^2 + 1 \ge 1 > 0 for every real xx, and ff is continuous, so by the increasing and decreasing test ff is increasing on (−∞,∞)(-\infty, \infty).

How this lesson connects

It also uses Functions and numerical tables and calculus definitions.