Precalculus · Chapter 2

Chapter 2
Flat and curved functions

Lectures 6–11  |  the chapter calculus is built on

In this chapter
  1. Lines, slope, and the line of best fit
  2. A toolbox of curved functions — and what curvature is
  3. Average rate of change, and rolling downhill
  4. Roots you cannot factor: secant lines and Newton's method
  5. Area: rectangles under a curve
  6. Polynomial approximation: building a curve out of powers

There are two kinds of function in the world. Some change at a constant rate, and those are easy: one number describes them completely, and everything about them can be worked out with arithmetic. The rest change at a rate that itself changes, and those are hard.

This chapter is the strategy for dealing with the hard ones, and the strategy is always the same: zoom in until they look easy, do the easy thing, and control the error. Every technique here — slopes of secant lines, rectangles under curves, polynomial approximations, root-finding by iteration — is that one move in a different costume. Calculus, next year, is what happens when you take the zoom to its limit.


Lecture 6 — Lines, slope, and the line of best fit

Cartoon: fitting a line through scattered dotsA stick figure holds a straight edge across a scatter of six dots and is asked whether it is a good line. Is it a good line?
“It is the least bad one. That is a technical term.”

A function is linear when equal steps in the input always produce equal steps in the output. That single sentence is the whole content of the topic; the formulas are bookkeeping.

definition

The slope of the line through \((x_1,y_1)\) and \((x_2,y_2)\) is $$m=\frac{y_2-y_1}{x_2-x_1}=\frac{\text{change in output}}{\text{change in input}}.$$ It is the same number whichever two points on the line you pick — and that invariance is exactly what "linear" means.

Useful forms: point-slope \(y-y_1=m(x-x_1)\), which you can write down the instant you know one point and the slope; and slope-intercept \(y=mx+b\).

spot check

What is the slope of the line through \((1,4)\) and \((5,12)\)?

decimals, fractions, pi and sqrt( ) are all fine

Slope always carries units, and reading them is the difference between an answer and an understanding. If \(x\) is in hours and \(y\) is in kilometres, the slope is in kilometres per hour, and it is a speed. If \(y\) is in dollars and \(x\) is in items, the slope is the cost of one more item — what an economist calls the marginal cost, and what calculus will eventually call the derivative.

spot check
\(x\) is measured in hours and \(y\) in kilometres. The slope of a line through the data is measured in…
example 2.1 — two points, one model

A 3D print job costs \$14.50 for a part using 60 g of filament and \$21.70 for one using 108 g. Assuming the cost is linear in the mass, find the model, and say what each of its two numbers means.

Slope: \(m=\dfrac{21.70-14.50}{108-60}=\dfrac{7.20}{48}=0.15\) dollars per gram.

Point-slope from \((60,14.50)\): \(C-14.50=0.15(m-60)\), so $$C(m)=0.15m+5.50.$$

The slope is the material cost: every extra gram costs 15 cents. The intercept is the \$5.50 you pay before any plastic is used at all — machine time, setup, the operator walking over. It is the cost of a print job of zero grams, which is a thing you would never order but a number that is perfectly real.

Note also which question the model cannot answer: at 5,000 g it predicts \$755.50, and by then you would not be using this printer at all. A linear model is a claim about a range, never about all of \(\mathbb{R}\).

example 2.2 — parallel and perpendicular

A robot vacuum travels along \(y=\tfrac23x+1\). Find the line through \((6,0)\) parallel to its path, and the line through \((6,0)\) that meets the path at a right angle.

Parallel means identical slope: \(y=\tfrac23(x-6)=\tfrac23x-4\).

Perpendicular means the slopes multiply to \(-1\), so the slope is \(-\tfrac32\): \(y=-\tfrac32(x-6)=-\tfrac32x+9\).

Why \(m_1m_2=-1\)? Rotating a direction by a quarter turn swaps the run and the rise and flips one sign: a step of \((3,2)\) becomes \((-2,3)\). We will prove this properly in Chapter 7, where rotation becomes a matrix and this fact becomes a one-line computation with the dot product.

When the data does not lie on a line

Real measurements never sit exactly on a line. So we stop asking for the line through the points, which usually does not exist, and start asking for the line that misses them by as little as possible. To do that we have to decide what "as little as possible" means — and that decision is the birth of every fitting procedure in statistics and machine learning.

definition

Given data \((x_i,y_i)\) and a candidate line \(y=mx+b\), the \(i\)th residual is $$e_i=y_i-(mx_i+b),$$ the vertical gap between what actually happened and what the line predicted. The sum of squared residuals is $$\mathrm{SSE}=\sum_i e_i^{2},$$ and the least-squares line is the one line making that total as small as possible.

spot check

The data point \((3,10)\) and the line \(y=2x+3\). What is the residual at this point?

decimals, fractions, pi and sqrt( ) are all fine

Two questions are worth asking immediately. Why square the residuals rather than just adding them? Because positive and negative misses would cancel, and a line that is wildly too high here and wildly too low there would score perfectly. Why square rather than take absolute values? Partly because squaring punishes one big miss more than several small ones, and partly — honestly — because squares are smooth and absolute values have a corner, which makes the squared version far easier to minimise. That convenience has shaped the whole subject.

Beat the computer

Twelve days of cold-drink sales against that day's high temperature. Move the two sliders to fit a line by eye; the running total of squared residuals is your score, and lower is better. When you cannot improve it, reveal the least-squares line and see how close you got.

high temperature (°F) drinks sold

example 2.3 — scoring two candidate lines

Five measurements: \((1,3),(2,5),(3,4),(4,8),(5,9)\). Two lines are proposed: \(y=1.5x+1.5\) and \(y=2x+0.5\). Which fits better by the least-squares criterion?

\(x\)\(y\)line A pred.\(e_A\)line B pred.\(e_B\)
133.00.02.50.5
254.50.54.50.5
346.0−2.06.5−2.5
487.50.58.5−0.5
599.00.010.5−1.5

\(\mathrm{SSE}_A=0+0.25+4+0.25+0=4.50\).   \(\mathrm{SSE}_B=0.25+0.25+6.25+0.25+2.25=9.25\).

Line A wins. Notice that the third point contributes most of both totals: one bad miss, squared, outweighs four good fits. That sensitivity to outliers is a genuine weakness of least squares, and knowing about it is part of using it honestly.

Neither line is optimal, as it happens. The true least-squares line here is \(y=1.5x+1.3\), with \(\mathrm{SSE}=4.30\) — line A was close but not best. Finding the optimum, rather than testing candidates one at a time, is a minimisation problem. Lecture 8 shows you how to hunt for a minimum, and Lecture 9 shows you how to go straight to it.

idea

You have just met, in full, the structure of supervised machine learning. There is a model with adjustable numbers (here, \(m\) and \(b\)). There is a loss function measuring how badly it does (here, SSE). And there is the problem of choosing the numbers that make the loss smallest, which is called training.

A modern neural network differs in exactly one respect: it has billions of adjustable numbers rather than two, so the loss cannot be minimised by a formula and has to be hunted down by rolling downhill. That hunt is Lecture 8. Everything else — model, loss, training — is already on this page, and you have done it by hand with a slider.

history

On 1 January 1801 the asteroid Ceres was spotted, tracked for 41 days, and then lost behind the Sun. Predicting where it would re-emerge meant fitting an orbit to a short, noisy arc of observations. Carl Friedrich Gauss, then 24, did it with a method he had not published, and Ceres was recovered in December within half a degree of his prediction.

The method was least squares. Legendre published it first in 1805; Gauss claimed he had been using it since 1795, and the priority dispute was bitter. Either way, the technique that runs inside every spreadsheet's trendline button was invented to find a lost rock.

a standing warning

Ice cream sales and drowning deaths rise and fall together with a strong linear relationship. Ice cream does not cause drowning. Both are caused by summer.

A fitted line measures association and says nothing whatever about cause. No amount of data, and no improvement in the fit, ever upgrades one to the other — that upgrade requires an experiment, or an argument about mechanism, and it comes from outside the mathematics.

spot check
Two variables have a very strong linear fit. What does that establish?
exercises 2.1
  1. Find the equation of the line through \((-2,5)\) and \((4,-7)\), and the coordinates of both intercepts.
  2. Find the perpendicular bisector of the segment joining \((1,2)\) and \((7,10)\).
  3. A tank drains steadily; it holds 480 L at 9:00 and 300 L at 12:00. Write volume as a function of hours after 9:00, interpret the slope with units, and say when it runs dry.
  4. For the data \((0,1),(1,4),(2,4),(3,8)\), compute the SSE of \(y=2x+1\) and of \(y=2.2x+0.9\). Which is better?
  5. Show that the least-squares line always passes through the point \((\bar x,\bar y)\), the average of the inputs and the average of the outputs. Verify it on the data in exercise 4, whose least-squares line is \(y=2.1x+1.1\).
  6. Two variables are measured and the fitted line has slope \(-0.02\) with data tightly clustered around it. A colleague says the effect is negligible because the slope is so small. What do you need to know before agreeing?
  7. A linear model of a city's population, fitted to data from 1990 to 2020, predicts a population of zero in 2085. What does that tell you about the model, and about extrapolation in general?
  1. \(m=\dfrac{-7-5}{4-(-2)}=-2\), so \(y=-2x+1\). Intercepts \((0,1)\) and \((\tfrac12,0)\).
  2. Midpoint \((4,6)\); the segment has slope \(\tfrac{8}{6}=\tfrac43\), so the bisector has slope \(-\tfrac34\): \(y=-\tfrac34(x-4)+6=-\tfrac34x+9\).
  3. \(V(t)=480-60t\) litres, \(t\) in hours. The slope is \(-60\) litres per hour, a drain rate. Empty when \(480-60t=0\), at \(t=8\), which is 17:00.
  4. For \(y=2x+1\): residuals \(0,1,-1,1\), SSE \(=3\). For \(y=2.2x+0.9\): residuals \(0.1,0.9,-1.3,0.5\), SSE \(=0.01+0.81+1.69+0.25=2.76\). The second is better.
  5. If \(y=mx+b\) minimises the SSE then the residuals sum to zero, so \(\sum(y_i-mx_i-b)=0\); dividing by \(n\) gives \(\bar y-m\bar x-b=0\), which says \((\bar x,\bar y)\) is on the line. Check: \(\bar x=1.5\), \(\bar y=4.25\), and \(2.1(1.5)+1.1=4.25\). ✓
  6. The units, and the range of the input. A slope of \(-0.02\) is negligible if \(x\) varies by 3 and enormous if \(x\) varies by 50,000. Slope is a rate, and a rate means nothing until you know how far it gets applied.
  7. That the linear model is wrong outside the range it was fitted to — populations do not fall to zero on a straight line. Fitting well on \([1990,2020]\) is a statement about \([1990,2020]\) and nothing else. Every model is a local approximation, which is the theme of this entire chapter.

Lecture 7 — A toolbox of curved functions, and what curvature is

Cartoon: a drooping slice of pizzaA stick figure holds a slice of pizza by the crust. The slice droops downward and a topping is sliding off the tip. Why does that work?
a folded slice stays out straight. it is a theorem, and Gauss called it remarkable.

A line has one number in it, the slope, and that number never changes. A curved function is precisely one for which no such number exists: the rate of change is different at different places. That is not a vague description, it is the definition, and everything difficult and interesting follows from it.

Before we can approximate curves we should know a few by name.

the toolbox
spot check

For \(x>1\) the largest of \(\sqrt x\), \(x\), \(x^{3}\) is ; for \(0<x<1\) the largest is .

One family, one dial

All of the above are \(y=x^{p}\) for different \(p\). Drag the exponent continuously from \(-2\) to \(3\) and watch one curve pass through the entire toolbox. Everything happens at \((1,1)\), through which every one of them passes.

(1, 1)

example 2.4 — the inverse-square law

Signal strength from a router falls off as \(S(d)=k/d^{2}\). If the signal is 100 units at 2 m, what is it at 4 m, at 6 m, and at 1 m? At what distance has it dropped below 5 units?

From \(S(2)=k/4=100\) we get \(k=400\). Then \(S(4)=25\), \(S(6)=11.1\), \(S(1)=400\).

Below 5 units: \(400/d^{2}<5\) gives \(d^{2}>80\), so \(d>8.9\) m.

Doubling the distance quarters the signal — not halves it. That is the signature of a square in the denominator, and the same shape governs brightness, sound intensity and gravity, all for the same geometric reason: whatever is emitted spreads over a sphere, and the area of a sphere grows with the square of its radius. The physics is a consequence of the geometry.

example 2.5 — who wins in the end

Compare \(\sqrt{x}\), \(x\), \(x^{2}\) and \(x^{3}\) at \(x=0.01\), \(x=1\) and \(x=100\). Which is largest in each case, and what is the general rule?

\(\sqrt x\)\(x\)\(x^{2}\)\(x^{3}\)
\(x=0.01\)0.10.010.0001\(10^{-6}\)
\(x=1\)1111
\(x=100\)10100\(10^{4}\)\(10^{6}\)

Below 1 the order is reversed; above 1 the higher power always wins; at \(x=1\) everything ties. That crossing point is why every one of these curves passes through \((1,1)\).

The practical version: for a polynomial, the highest-degree term decides the behaviour far from the origin, and the lowest-degree term decides it near zero. \(x^{3}+500x\) looks like a line near the origin and like a cubic beyond \(x\approx22\).

for your toolbox

These are the first graphs to commit to memory. From here on, every new function in the course gets added to this list, and every one of them is reshaped by the same five transformations of Lecture 4.

functiondomainrangefeatures
\(y=x\)all realsall realsa line; the only member with no bend
\(y=x^{2}\)all reals\([0,\infty)\)even; a single lowest point
\(y=x^{3}\)all realsall realsodd; flattens at the origin then climbs
\(y=\sqrt{x}\)\([0,\infty)\)\([0,\infty)\)the right half of a sideways parabola
\(y=\dfrac{1}{x}\)all reals except 0all reals except 0two branches; asymptotes \(x=0\) and \(y=0\)
\(y=|x|\)all reals\([0,\infty)\)even; a corner at the origin

Get into the habit of writing the domain and range down every time you sketch. They are the two questions a grader always asks, and for the reciprocal they are the two places the graph does something dramatic.

spot check

Signal strength falls off as \(k/d^{2}\). If you move three times as far away, the signal is multiplied by what fraction?

decimals, fractions, pi and sqrt( ) are all fine

Concave up, concave down

Slope tells you which way a curve is going. The next question — the one that separates a curve from a line — is how the slope itself is changing.

definition

A function is concave up on an interval if its slope is increasing there, so the curve bends upward and lies above its own tangent lines. It is concave down if the slope is decreasing. A point where the concavity changes is an inflection point.

spot check
Weekly sales are \(50, 70, 85, 95\). Is the pattern concave up or concave down?

Language is a trap here, so it is worth being slow. A concave-down curve can still be rising: think of a rocket that is still gaining altitude but more slowly every second. "Increasing" is about the function; "concave" is about its slope. A quantity can grow while its growth decelerates, and confusing those two statements is how a great deal of bad news gets reported as good.

example 2.6 — reading concavity out of a table

A country's total cases are recorded weekly: 100, 260, 500, 790, 1090, 1370. Are cases rising? Is the situation improving?

Weekly increases: \(160,\ 240,\ 290,\ 300,\ 280\).

Cases are rising every week, so the function is increasing throughout. But the increases grew, then peaked around week 4, and have started to fall. The curve is concave up at first and concave down at the end, with an inflection around week 4.

And that inflection is the good news, arriving well before any total starts to fall. It is the moment the growth stopped accelerating. Reporters call it "the curve flattening"; mathematically, it is the second difference changing sign, and it is visible in the table long before it is visible in the headline number.

Notice what we just did: we took differences of the data to learn about the slope, and then differences of those to learn about the bending. Do that twice with calculus and you have the first and second derivative. The idea is already here, in arithmetic.

Curvature as a number

"Bends a lot" ought to be measurable, and it is. Take three nearby points on a curve. Unless they happen to be collinear, exactly one circle passes through all three. Slide the points together and that circle settles down to a definite limiting circle, the one that hugs the curve best at that spot.

definition

The radius of curvature \(R\) at a point is the radius of that best-fitting circle. The curvature is \(\kappa=1/R\).

A tight bend is a small circle, so a large curvature. A straight line is the extreme case: the best circle has infinite radius, and curvature zero.

spot check

A tighter bend has a radius of curvature and a curvature.

The circle that best fits a parabola at its vertex The parabola y equals x squared with a circle of radius one half centred at the point zero, one half, touching the parabola at the origin and matching its bend. R = 1/2 y = x² curvature here is κ = 2
At its vertex, \(y=x^{2}\) bends exactly as hard as a circle of radius \(\tfrac12\). Further along the same parabola the bend is gentler: at \(x=1\) the best circle has radius \(5.59\), so the curvature there is only \(0.179\).
example 2.7 — measuring a bend with three points

Find the circle through the three points \((-0.1,\,0.01)\), \((0,\,0)\) and \((0.1,\,0.01)\) on the parabola \(y=x^{2}\), and compare its radius with the one for the closer points \((\pm0.01,\,0.0001)\).

By symmetry the centre is on the \(y\)-axis, at \((0,c)\). Equal distances to \((0,0)\) and \((0.1,0.01)\) give $$c^{2}=0.1^{2}+(c-0.01)^{2}=0.01+c^{2}-0.02c+0.0001,$$ so \(0.02c=0.0101\) and \(c=0.505\). The radius is \(0.505\).

Repeating with \(x=\pm0.01\): \(0.0002c=0.0001+10^{-8}\), giving \(c=0.50005\) and radius \(0.50005\).

The radii are heading to \(0.5\). This is a limit — the third one in this course, after \(e\) and the difference quotient — and it is completely computable by hand. Calculus will later give the shortcut \(\kappa=|y''|/(1+(y')^{2})^{3/2}\), which at the vertex of \(y=x^{2}\) reads \(\kappa=2\). You already have the answer; the formula is a convenience.

Why folding a slice of pizza works

Hold a slice flat by the crust and the tip droops. Fold the crust into a gentle U and the slice goes rigid and stays level. Everyone knows the trick. Almost nobody knows that it is a theorem.

Fold the slice

You are holding the crust. Fold the slice across its width with the first slider and watch the tip. The other two turn the slice and raise your viewpoint, so you can look along it, down on it, or edge-on. Green lines run along the slice, from crust to tip; pink lines run across it.

level

The two directions of curvature on a pizza slice, seen from above A slice seen from above, with green lines running from the crust to the tip along its length and pink lines running across its width. A note says that the product of the bending in the two directions must stay zero. along the slice across the slice bend one of these and the other is forbidden to bend
The two families of lines on a flat slice. Gauss's theorem says the bend along and the bend across cannot both be non-zero, because that product is fixed at the value a flat sheet started with: zero. Fold across — the pink direction — and the green lines are stuck being straight, which is exactly what keeps the tip up.
idea — Gauss's remarkable theorem

A surface has a curvature that can be measured entirely from inside it, without ever stepping off — by comparing the circumference of a small circle drawn on the surface with the \(2\pi r\) you would expect, or by checking whether the angles of a small triangle add to \(180^{\circ}\). Gauss proved in 1827 that this intrinsic curvature is unchanged by bending, as long as you do not stretch or tear. He called it the theorema egregium, the remarkable theorem, and he was not usually given to superlatives.

A flat pizza slice has intrinsic curvature zero. Folding it does not stretch it, so the curvature stays zero. But a surface curving downward along its length and curving across its width would have non-zero curvature at that point — and it is not allowed to. Curve it one way and it is forbidden from curving the other. The slice stays out straight because geometry will not let it do otherwise.

The same theorem says no flat map of the Earth can get both areas and shapes right, that an orange peel will never lie flat, and that a cylinder — surprisingly — is intrinsically flat, which is why you can roll a sheet of paper into one and unroll it undamaged. And it is the doorway to the study of curved spaces in their own right: manifolds, the objects general relativity is written on, where "straight line" is replaced by "the straightest available path" and the shortest route between two cities bends across the map. You will meet the first honest example in Chapter 5, on a sphere, where triangles have too many degrees.

spot check
Which of these can be made from a flat sheet of paper without stretching or tearing?
exercises 2.2
  1. Without plotting, describe the end behaviour of \(f(x)=-3x^{4}+2x^{2}-7\) and of \(g(x)=x^{5}-x\), and give all zeros of \(g\).
  2. Sketch \(y=1/x^{2}\) and \(y=1/x\) on the same axes. Where do they cross? Which is larger for \(0<x<1\), and which for \(x>1\)?
  3. The intensity of light from a lamp is 60 lux at 3 m. Find the intensity at 1.5 m and at 9 m, and the distance at which it falls to 10 lux.
  4. A quantity is measured each hour: 20, 34, 46, 55, 61, 64. Is it increasing? Is it concave up or down? Estimate when the concavity first became apparent, and predict the next reading with a one-sentence justification.
  5. By the three-point method, find the radius of curvature of \(y=2x^{2}\) at its vertex, using \(x=\pm0.05\). Compare with the parabola \(y=x^{2}\) and say which bends harder.
  6. A cylinder can be made from a flat sheet without stretching; a sphere cannot. Which one, therefore, has zero intrinsic curvature? Explain what this predicts about drawing an accurate world map on a cylinder of paper.
  7. A rolled-up poster is stiff along its length. Explain the connection to the pizza fold in two sentences, using the word curvature.
  1. \(f\) has even degree with a negative leading coefficient, so both arms fall: \(f\to-\infty\) at both ends. \(g\) has odd degree with a positive leading coefficient, so it falls to the left and rises to the right. Its zeros come from \(x(x^{4}-1)=x(x^{2}-1)(x^{2}+1)\): \(x=0,1,-1\).
  2. They cross where \(1/x^{2}=1/x\), that is \(x=1\) (and nowhere else for \(x>0\)). For \(0<x<1\), \(1/x^{2}\) is larger; for \(x>1\), \(1/x\) is larger.
  3. \(I(d)=540/d^{2}\). At 1.5 m, 240 lux; at 9 m, 6.67 lux. It reaches 10 lux at \(d=\sqrt{54}=7.35\) m.
  4. Increasing throughout. The differences are \(14,12,9,6,3\) — shrinking, so it is concave down from the start. The next difference should be near \(0\) or slightly negative, so predict about 64–65; the quantity looks like it is levelling off at a ceiling.
  5. Centre at \((0,c)\) with \(c^{2}=0.0025+(c-0.005)^{2}\), so \(0.01c=0.002525\) and \(c=0.2525\). The radius tends to \(0.25\), so \(\kappa=4\). It bends twice as hard as \(y=x^{2}\), whose vertex curvature is 2.
  6. The cylinder. Rolling does not stretch, so a cylinder inherits the plane's zero curvature — which means a map printed on a flat sheet and rolled into a tube is undistorted, while a sphere's surface can never be flattened without tearing or stretching, so every flat world map lies about something.
  7. Rolling the poster spends its available bending across its width, and since the intrinsic curvature must stay zero, it can no longer bend along its length. Same theorem, same lunch.

Lecture 8 — Average rate of change, and rolling downhill

Cartoon: zooming in until a curve looks straightTwo stick figures look through a magnifier at a gently bending curve. One declares it straight. It’s straight!
“It is not. Zoom out.” “I refuse.”

A curved function has no single slope. But it has a slope between any two of its points, and that is something we can compute with nothing but arithmetic.

definition

The average rate of change of \(f\) from \(a\) to \(b\) is $$\frac{f(b)-f(a)}{b-a},$$ the slope of the straight line joining \((a,f(a))\) to \((b,f(b))\). That line is called a secant line.

Writing \(b=a+h\) gives the same quantity as the difference quotient $$\frac{f(a+h)-f(a)}{h}.$$

spot check

What is the average rate of change of \(f(x)=x^{2}\) from \(x=1\) to \(x=3\)?

decimals, fractions, pi and sqrt( ) are all fine

example 2.8 — the same trip, two questions

A drone's height is \(h(t)=40t-5t^{2}\) metres, \(t\) in seconds. Find its average velocity over \([0,4]\), over \([0,8]\), and over \([3,5]\). Interpret each.

\(h(0)=0\), \(h(3)=75\), \(h(4)=80\), \(h(5)=75\), \(h(8)=0\).

Over \([0,4]\): \(\dfrac{80-0}{4}=20\) m/s upward.

Over \([0,8]\): \(\dfrac{0-0}{8}=0\) m/s. The drone went up 80 m and came back; the average velocity over the whole flight is zero, even though it was moving the entire time.

Over \([3,5]\): \(\dfrac{75-75}{2}=0\) as well — a window straddling the peak.

So "average rate of change is zero" does not mean "nothing happened". It means the endpoints agree. Average speed (total distance over total time) is a different quantity entirely: 160 m in 8 s, so 20 m/s. Which one you want depends on the question, and conflating them is a standard way to get an exam problem wrong.

example 2.9 — simplifying the quotient

For \(f(x)=3x^{2}-x\), simplify \(\dfrac{f(a+h)-f(a)}{h}\), then evaluate it at \(a=2\) for \(h=0.1\) and for \(h=0.001\).

\(f(a+h)=3(a+h)^{2}-(a+h)=3a^{2}+6ah+3h^{2}-a-h\), and subtracting \(f(a)=3a^{2}-a\) leaves \(6ah+3h^{2}-h\). Dividing by \(h\): $$\frac{f(a+h)-f(a)}{h}=6a+3h-1.$$

At \(a=2\): with \(h=0.1\) it is \(11.3\); with \(h=0.001\) it is \(11.003\).

Look at what the algebra did. Before dividing, every term had an \(h\) in it, so the quotient was \(\tfrac00\) at \(h=0\) — meaningless. After cancelling, the expression \(6a+3h-1\) is perfectly happy at \(h=0\), where it equals \(6a-1\). That cancellation is the entire trick of differential calculus, performed here with Chapter 0 algebra and nothing else. The number \(6a-1\) is the derivative of \(3x^{2}-x\), and you have just computed it.

Shrinking the interval

Fix a point and let the second point slide towards it. The secant line pivots, and its slope settles down.

\(h\)secant slope of \(y=x^{2}\) from \(1\) to \(1+h\)
13
0.52.5
0.252.25
0.12.1
0.012.01
0.0012.001

The pattern is not subtle: the slopes are \(2+h\), heading for \(2\). We cannot reach \(h=0\) — the quotient has no meaning there — but the destination is unmistakable.

Watch a secant become a tangent

The curve is \(y=x^{2}\), anchored at \(x=1\). Shrink \(h\) and watch the secant line stop moving.

idea — local linearity

Zoom far enough into a smooth curve at a point and it becomes indistinguishable from a straight line. Try it on any graphing tool: pick a point on a parabola, zoom in ten times, and the parabola disappears — what is left is a line, and its slope is the number the secant slopes were heading for.

This is the single most important fact in calculus, and it is a geometric fact, not an algebraic one. Curved things are locally flat. It is why a small enough patch of the Earth can be surveyed with plane geometry, why the tangent line predicts well nearby and badly far away, and why the whole strategy of this chapter — replace the hard curved thing with the easy flat thing, locally — is legitimate rather than lazy.

It is also exactly the property that defines a manifold: a space that looks flat if you stand close enough, however wildly it curves overall. The surface of the Earth is one. So is the space-time of general relativity. A curve that is locally a line is the one-dimensional case, and you are looking at it.

spot check

For \(y=x^{2}\), the secant slopes from \(2\) to \(2+h\) are \(4.1\) when \(h=0.1\) and \(4.01\) when \(h=0.01\). What number are they heading for?

decimals, fractions, pi and sqrt( ) are all fine

example 2.10 — using flatness to compute a root

Estimate \(\sqrt{9.2}\) using only the value \(\sqrt9=3\) and one secant slope.

Take a nearby point: \(\sqrt{9.1}=3.016621\), so the secant slope from 9 to 9.1 is $$\frac{3.016621-3}{0.1}=0.16621.$$ Treat the curve as a line through \((9,3)\) with that slope: $$\sqrt{9.2}\approx 3+0.2(0.16621)=3.03324.$$

The true value is \(3.03315\). We are off by \(9\times10^{-5}\), from one subtraction and one multiplication.

This is a preview of Lecture 11 in miniature. There, instead of replacing the curve with a line, we will replace it with a parabola or a cubic and do far better. And the error is not mysterious: it is the amount by which the curve pulled away from its tangent over that distance — which is to say, it is caused by curvature.

Rolling downhill

Now the payoff. Suppose you want the lowest point of a curve and cannot solve for it. The slope tells you which way is downhill: where the slope is positive the curve rises to the right, so you should move left; where it is negative, move right. Either way, step against the slope.

gradient descent

Choose a starting point \(x_0\) and a step size \(\alpha>0\). Repeat: $$x_{\text{new}}=x_{\text{old}}-\alpha\cdot(\text{slope at }x_{\text{old}}),$$ estimating the slope with a difference quotient using a small \(h\). Stop when the slope is close enough to zero.

spot check

You are at \(x=2\), the estimated slope there is \(3\), and the step size is \(\alpha=0.1\). Where does one step of gradient descent take you?

decimals, fractions, pi and sqrt( ) are all fine

lab — six steps by hand

A delivery route's total cost, in hundreds of dollars, as a function of the departure hour \(x\) measured from midday, is modelled by $$C(x)=0.05x^{4}-0.5x^{2}+0.2x+3.$$ Start at \(x_0=3\) with step size \(\alpha=0.4\), estimating each slope with \(h=0.01\). Run six steps.

step\(x\)\(C(x)\)estimated slope
03.00003.15002.6001
11.96002.2091−0.2541
22.06162.1904−0.1091
32.10532.1872−0.0391
42.12092.1868−0.0128
52.12602.1867−0.0041
62.12762.1867−0.0013

The first step overshoots past the bottom and lands on the far side — the slope was steep and \(\alpha\) was generous. After that the steps shrink automatically, because the slope shrinks as the bottom approaches. The method brakes on its own.

Now run it again from \(x_0=-3\). It converges to \(x=-2.3300\) with \(C=1.2932\) — a lower value than the one we just found. The first run landed in the wrong valley and had no way of knowing.

Two valleys, one rule

Tap anywhere on the curve to drop a marble there, then press step. From the keyboard: focus the figure, move with the arrow keys, and press Enter to take a step. The same rule, from two different starting points, finds two different answers.

C(x)

A stream finding its way down a hillside A hillside in cross-section with a stream running down it, taking the steepest available route and pooling in a hollow that is not the lowest point on the whole landscape. it stops here the real bottom is over here a raindrop starts
Every raindrop that lands on a mountainside solves this problem, by taking the steepest way down at each moment. That is what a river is. It is also why rivers pool in hollows rather than always reaching the sea — a local minimum is a perfectly good place to get stuck, and neither water nor an algorithm can see over the ridge.
idea

This is how neural networks are trained, with no embellishment. The loss is a function of billions of adjustable numbers instead of one; the slope in each of those directions is estimated (by a bookkeeping method called backpropagation rather than by difference quotients, but the quantity is the same); and the whole vector of numbers takes a small step against it. Then again, millions of times.

The local-minimum problem in the picture above is entirely real, and the honest answer from the field is that in very high dimensions it matters less than you would expect — with a billion directions to choose from, it is rare for all of them to point uphill at once. But the warning stands, the step size is still chosen by hand, and it still goes wrong in the ways this one-dimensional picture suggests. You now know the whole algorithm.

exercises 2.3
  1. Find the average rate of change of \(f(x)=x^{3}\) over \([1,3]\), \([1,2]\), \([1,1.5]\) and \([1,1.1]\). What number are these heading for?
  2. Simplify the difference quotient for (a) \(f(x)=5x-2\); (b) \(f(x)=x^{2}+x\); (c) \(f(x)=1/x\). For (c) the algebra needs a common denominator; the answer should contain no \(h\) in any denominator standing alone.
  3. In (a) above the answer does not involve \(a\) or \(h\) at all. Explain why, in one sentence about lines.
  4. A population is 4,000 in 2015 and 6,760 in 2020. Find the average rate of change with units, and explain why this number alone cannot tell you whether growth was linear or exponential.
  5. Estimate \(\sqrt[3]{8.3}\) by the method of the worked example, starting from \(\sqrt[3]{8}=2\) and using \(\sqrt[3]{8.1}=2.00830\). Compare with the true value 2.02469.
  6. Run gradient descent by hand on \(g(x)=x^{2}-4x+7\) from \(x_0=0\) with \(\alpha=0.3\), for four steps, computing slopes exactly from the difference quotient \(2a+h-4\) with \(h\) taken as 0. Where does it converge, and why is there no second valley to worry about?
  7. Repeat the previous exercise with \(\alpha=1.2\). Describe what happens and explain it in terms of overshoot.
  8. A student says gradient descent must fail on a function with a flat stretch. Sketch such a function, and say precisely what goes wrong.
  1. \(\dfrac{27-1}{2}=13\); \(\dfrac{8-1}{1}=7\); \(\dfrac{3.375-1}{0.5}=4.75\); \(\dfrac{1.331-1}{0.1}=3.31\). They are heading for 3.
  2. (a) \(\dfrac{5(a+h)-2-(5a-2)}{h}=5\). (b) \(\dfrac{(a+h)^{2}+(a+h)-a^{2}-a}{h}=2a+h+1\). (c) \(\dfrac{1}{h}\left(\dfrac{1}{a+h}-\dfrac1a\right)=\dfrac{1}{h}\cdot\dfrac{a-(a+h)}{a(a+h)}=\dfrac{-1}{a(a+h)}\).
  3. A line has the same slope everywhere, so the average rate of change cannot depend on where you measure it or how wide the window is.
  4. \(\dfrac{6760-4000}{5}=552\) people per year. That number is the slope of the secant and is compatible with any number of histories between the endpoints — steady growth, a boom and a crash, or a constant 11% per year, which also lands on 6,760.
  5. Secant slope \(=\dfrac{2.00830-2}{0.1}=0.0830\), so \(\sqrt[3]{8.3}\approx 2+0.3(0.0830)=2.0249\). The true value is 2.02469; the error is about \(2\times10^{-4}\), larger than in the square-root case because the window was three times wider.
  6. The slope at \(a\) is \(2a-4\). From \(x_0=0\): slope \(-4\), so \(x_1=1.2\); slope \(-1.6\), \(x_2=1.68\); slope \(-0.64\), \(x_3=1.872\); slope \(-0.256\), \(x_4=1.9488\). It converges to \(x=2\), where \(g=3\). A parabola opening upward has exactly one valley, so no starting point can strand you.
  7. From \(x_0=0\): \(x_1=4.8\), \(x_2=-1.92\), \(x_3=7.488\), \(x_4=-4.4928\). It oscillates across the minimum and the swings get wider every step — the method diverges. With \(\alpha\) this large each step is more than twice the distance to the bottom, so the marble lands further from the minimum than it started. Too small an \(\alpha\) crawls, too large diverges, and choosing it is the practical art of the method.
  8. Any function with a long flat plateau, such as one that levels off before descending again. On the plateau the estimated slope is nearly zero, so the steps become microscopic and the method stalls — it has no way to tell a flat stretch from the bottom. This is the vanishing-gradient problem, and it has cost the field years of work.

Lecture 9 — Roots you cannot factor: secant lines and Newton's method

Cartoon: throwing darts that land closer each timeA stick figure points at a dartboard where three darts have landed progressively closer to the centre. Two more throwsand I’m inside the atom.
each guess is about twice as good as the last one

Chapter 0 taught you to solve equations by factoring. It is worth being honest about how narrow that skill is. \(x^{2}-5x+6=0\) factors. \(x^{5}+x-1=0\) does not, and never will: it has a perfectly ordinary real root near \(0.75\), and it can be proved that no formula built from \(+,-,\times,\div\) and roots can ever express it.

That is not an exotic failure. Almost every equation that arises from a real problem is in this second class. So the practical question is not how to solve equations exactly — usually impossible — but how to compute a root to as many decimal places as you need.

The graph of x to the fifth plus x minus one A curve rising from minus one at x equals zero to just above zero at x equals one, crossing the horizontal axis once at about x equals 0.755. root ≈ 0.7549 00.51 −1 y = x⁵ + x − 1
The function is negative at \(0\) and positive at \(1\), so somewhere in between it must be zero. Finding where is the business of this lecture.

Bisection: slow, and certain

If \(f\) is continuous, \(f(a)<0\) and \(f(b)>0\), then a root lies between. Check the midpoint, keep whichever half still has a sign change, repeat. Each step halves the uncertainty.

spot check
\(f(2)=-1\) and \(f(3)=4\). You check the midpoint and find \(f(2.5)=1.2\). Which half do you keep?
example 2.11 — six bisections

Apply bisection to \(f(x)=x^{5}+x-1\) on \([0,1]\) and report six steps.

stepmidpointsign of \(f\)interval kept
10.500000−[0.5, 1]
20.750000−[0.75, 1]
30.875000+[0.75, 0.875]
40.812500+[0.75, 0.8125]
50.781250+[0.75, 0.78125]
60.765625+[0.75, 0.765625]

After six steps we know the root to within \(1/2^{6}=0.0156\). To get ten decimal places would take about 34 steps. It always works, it never surprises you, and it is slow — each step buys exactly one binary digit, no matter how nicely the function behaves.

Bisection ignores everything except the sign of \(f\). It never asks how negative the function was. That discarded information is what the next method exploits.

The secant method: use the slope you already have

Take two points on the curve, draw the secant line through them — the same line as Lecture 8 — and ask where that line crosses zero. A line's root is trivial to find. Since the line hugs the curve nearby, its root should be close to the curve's root, and we can iterate.

the secant method

Given two estimates \(x_{n-1},x_n\), the secant line through \((x_{n-1},f(x_{n-1}))\) and \((x_n,f(x_n))\) crosses zero at $$x_{n+1}=x_n-f(x_n)\cdot\frac{x_n-x_{n-1}}{f(x_n)-f(x_{n-1})}.$$ The fraction is the reciprocal of the average rate of change. Nothing beyond Lecture 8 is needed.

spot check

\(f(1)=-2\) and \(f(3)=2\). Where does the secant line through these two points cross zero?

decimals, fractions, pi and sqrt( ) are all fine

lab — the race

Run the secant method on \(x^{5}+x-1\) from \(x_0=0\), \(x_1=1\), and compare with the bisection table above, step for step.

stepbisectionsecant
10.5000000.500000
20.7500000.659574
30.8750000.795474
40.8125000.748472
50.7812500.754456
60.7656250.754882

The true root is \(0.7548777\). After six steps bisection has two correct digits and the secant method has five. The gap widens from there: bisection gains a fixed amount per step, the secant method gains an increasing amount, because the closer it gets the better a line approximates the curve.

Note that the secant estimates are not trapped in a shrinking interval — step 3 overshoots past the root, step 4 comes back. Speed was bought by giving up the guarantee.

Newton's method: slide the two points together

In the secant method the two points can be anywhere. Put them very close together and the secant line becomes the tangent line, whose slope is the number the difference quotients were converging to in Lecture 8. That is Newton's method:

$$x_{n+1}=x_n-\frac{f(x_n)}{m(x_n)},\qquad m(x_n)\approx\frac{f(x_n+h)-f(x_n-h)}{2h}\ \text{for small } h.$$

In words: stand on the curve, slide down the tangent line to the axis, and start again from there. Calculus will give you \(m\) exactly and call it \(f'\); until then a small \(h\) gives it to you accurately enough.

spot check

For \(f(x)=x^{2}-2\), your guess is \(x=1.5\) and the slope there is \(3\). What is the next Newton guess?

decimals, fractions, pi and sqrt( ) are all fine

Step it yourself

Tap the curve to choose a starting guess, then step. From the keyboard: focus the figure, move with the arrow keys, and press Enter to step. The tangent line is drawn each time, and where it hits the axis becomes the next guess.

f(x) = x⁵ + x − 1

example 2.12 — counting correct digits

Newton's method on \(x^{5}+x-1\) from \(x_0=1\) gives \(0.8333333333\), \(0.7643821157\), \(0.7550248672\), \(0.7548777018\), \(0.7548776662\). The true root is \(0.7548776662\). How many correct digits does each step produce?

stepestimatecorrect digits
10.83333333331
20.76438211572
30.75502486724
40.75487770187
50.754877666210+

The count roughly doubles each step: 1, 2, 4, 7, 10. This is called quadratic convergence, and it is why Newton's method is inside almost every piece of numerical software ever written. Four steps from a mediocre guess gives more precision than most measurements deserve.

Compare the cost honestly, though: bisection needed one function evaluation per step and could not fail. Newton needs a slope estimate as well, and it can fail.

when it goes wrong

Three failure modes, all worth seeing once:

None of these makes the method bad. They make it a method that needs a decent starting guess — often supplied by a few bisection steps first, which is exactly what good software does.

Optimisation is root-finding in disguise

Lecture 8 hunted for a minimum by rolling downhill. Here is a sharper way to think about it. At the bottom of a valley the slope is zero. So finding a minimum of \(C\) means solving the equation \(m(x)=0\), where \(m\) is the slope function — and solving equations is what this lecture is about.

spot check
At the very bottom of a smooth valley, the slope of the curve is…
example 2.13 — finding the valley by root-finding

For the delivery cost \(C(x)=0.05x^{4}-0.5x^{2}+0.2x+3\) of Lecture 8, estimate the slope function with \(h=0.01\) and run the secant method on it from \(x_0=1.5\), \(x_1=3\).

step\(x\)slope there
11.790681−0.442
21.966482−0.246
32.185914+0.103
42.121031−0.0126
52.128089−0.00053

Five steps land on \(x=2.1281\), against the true minimum at \(2.1285\). Gradient descent in Lecture 8 needed six steps to reach \(2.1276\) — and that was with a step size chosen by hand, where this needed no such choice.

But notice what has not changed: it found the same valley, the one nearer the starting points, and the deeper minimum at \(x=-2.33\) is still invisible to it. Solving \(m(x)=0\) finds a place where the ground is level. Level ground can be the bottom of a valley, the top of a hill, or a flat shoulder, and the equation cannot tell them apart. Checking which is which is a job for curvature — concave up means a minimum — and that is Lecture 7 coming back to be useful.

history

The method is older than Newton and was not his alone. Sharaf al-Din al-Tusi, in twelfth-century Persia, gave a numerically identical procedure for cubics; Chinese root-extraction algorithms of comparable power are older still. Newton's version, written around 1669, contained no derivatives and no tangent lines — it was a purely algebraic scheme for improving an approximation, and he applied it to a cubic.

Joseph Raphson published a simplified iterative form in 1690, and Thomas Simpson in 1740 gave the version with derivatives that everyone now recognises, and extended it to systems of equations. The name "Newton–Raphson" records half the story at best, which is normal.

idea

Look at what these two lectures have in common. Gradient descent uses the slope and takes a cautious step. Newton's method uses the slope and takes the exact step that a straight line would require. The first is robust and slow; the second is fast and brittle.

That trade-off has not gone away. Training a large model is done with gradient descent, in variants with names like Adam and SGD, precisely because the honest Newton step is unaffordable when there are a billion directions. Methods that do use curvature information are called second-order, and building affordable ones is an active research problem. When you meet that phrase, you will know exactly what it means: somebody is trying to use the bend, not just the slope.

exercises 2.4
  1. Show that \(f(x)=x^{3}-x-3\) has a root between 1 and 2, and locate it to within \(0.1\) by bisection.
  2. Continue the previous exercise with three secant steps from \(x_0=1\), \(x_1=2\). Compare the accuracy after the same number of steps.
  3. Use Newton's method on \(f(x)=x^{2}-7\) from \(x_0=3\), estimating slopes with the exact formula \(2x\). Do three steps and compare with \(\sqrt7=2.6457513\).
  4. Show that Newton's method applied to \(f(x)=x^{2}-N\) simplifies to \(x_{n+1}=\tfrac12\left(x_n+\dfrac{N}{x_n}\right)\). This rule for square roots was in use in Babylon around 1700 BCE. What does it tell you about how old the idea is?
  5. Explain, with a sketch, why Newton's method sends you far away when the tangent at your guess is nearly horizontal.
  6. A box of volume 1000 cm³ is made from a square base of side \(x\) with an open top. Its surface area is \(A(x)=x^{2}+4000/x\). Estimate the slope function at \(x=10,12,14\) with \(h=0.1\), and use two secant steps to find the \(x\) minimising the material used.
  7. A company's profit is modelled by a function with two local maxima. Explain why solving "slope = 0" is necessary but not sufficient for finding the best price, and say what extra check is needed.
  8. Bisection halves the interval each step. How many steps are needed to go from an interval of length 1 to an accuracy of \(10^{-6}\)? Compare with the four Newton steps in the worked example.
  1. \(f(1)=-3\) and \(f(2)=3\), so a sign change traps a root. Midpoints: \(1.5\) gives \(-1.125\), so keep \([1.5,2]\); \(1.75\) gives \(+0.61\), keep \([1.5,1.75]\); \(1.625\) gives \(-0.33\), keep \([1.625,1.75]\); \(1.6875\) gives \(+0.12\). The root is near \(1.67\).
  2. Secant from \(1,2\): \(x_2=1.5\), then \(x_3=1.636364\), then \(x_4=1.676271\). The true root is \(1.671700\), so after three steps the secant method is accurate to about \(0.005\) while four bisections had only pinned the root inside an interval of width \(0.0625\).
  3. \(x_1=3-\dfrac{2}{6}=2.6\overline{6}\); \(x_2=2.645833\); \(x_3=2.6457513\) — correct to all seven displayed digits after three steps.
  4. \(x_{n+1}=x_n-\dfrac{x_n^{2}-N}{2x_n}=\dfrac{2x_n^{2}-x_n^{2}+N}{2x_n}=\dfrac12\left(x_n+\dfrac{N}{x_n}\right)\). The Babylonians were running Newton's method on clay tablets three and a half thousand years before Newton, without the theory that explains why it works. Good algorithms are often discovered long before they are understood.
  5. The next guess is where the tangent meets the axis. A nearly horizontal line travels an enormous horizontal distance before reaching the axis, so a nearly flat tangent throws you far from where you started — possibly outside the region where the function behaves at all.
A nearly horizontal tangent overshooting badlyA curve crossing the axis near x equals 1.85. At x equals 1 the curve has a very flat shoulder, and the tangent line drawn there is almost horizontal, travelling far to the right before it meets the axis at about x equals 5.2. your guessthe true rootthe tangent sends you here0123451−1
Newton’s next guess is wherever the tangent meets the axis. A nearly flat tangent has to travel an enormous horizontal distance to get there, so a guess sitting on a flat shoulder is flung far past the answer: the root is at \(x\approx1.85\) and the method proposes \(x\approx5.2\).
  1. Slopes: at \(x=10\), about \(-20.0\); at \(x=12\), about \(-3.8\); at \(x=14\), about \(+7.6\). Secant on those from \(10\) and \(12\): \(x\approx12.47\); next step \(x\approx12.60\). The true minimiser is \(x=\sqrt[3]{2000}=12.599\).
  2. Every local maximum has slope zero, but so does every local minimum and every flat shoulder — so the equation produces candidates, not answers. Evaluate the profit at each candidate and at the ends of the allowed price range, and take the largest; or check concavity, since a maximum must be concave down.
  3. Need \(2^{-n}<10^{-6}\), so \(n>6/\log_{10}2=19.9\): twenty steps. Newton got ten digits in five. The comparison is not quite fair — Newton needs a good start and can fail — but it explains why the two are used together.

Lecture 10 — Area: rectangles under a curve

Cartoon: filling the area under a curve with rectanglesA stick figure shrugs beside a rising curve that has been filled in with five rectangles of increasing height. How many rectangles?
“Yes.”

Rates have occupied us for three lectures. This one asks the opposite question, and it turns out to be the deeper of the two.

idea — why anyone wants an area

If you drive at a steady 60 km/h for 2 hours you cover 120 km, and you got that by multiplying. On a graph of speed against time, that product is literally the area of a rectangle: 60 tall, 2 wide.

Now let the speed vary. The multiplication no longer works — which speed would you use? But the area still does. Area under a speed curve is distance. Area under a flow-rate curve is volume. Area under a power curve is energy; under a rate-of-infection curve, total infections. Whenever you have a rate and want a total, you want an area, and this is not an analogy. It is the same arithmetic, cut finer.

When the rate is constant, it is just geometry

Under a linear function the region is a trapezoid, and you already know its area: average height times width. A tank filling at a rate rising steadily from 2 to 8 litres per minute over 5 minutes receives \(\tfrac{2+8}{2}\times 5=25\) litres. Nothing new is needed, precisely because the rate changes at a constant rate.

spot check

Water flows into a tank at a rate rising steadily from 2 L/min to 6 L/min over 4 minutes. How many litres arrive?

decimals, fractions, pi and sqrt( ) are all fine

example 2.14 — an area you can find with a ruler

A car accelerates from rest at a constant rate, reaching 30 m/s after 12 s, then holds that speed for 8 s. Sketch the speed graph and find the total distance.

The graph is a straight climb from \((0,0)\) to \((12,30)\), then a horizontal line to \((20,30)\).

Triangle: \(\tfrac12(12)(30)=180\) m. Rectangle: \(8\times30=240\) m. Total \(420\) m.

The whole calculation is primary-school geometry, and it is exact. Everything hard about integration comes from the moment the top edge stops being straight.

When it curves, chop it up

Under a curve there is no formula. So we do the only thing available: cover the region with rectangles whose areas we can compute, and accept an approximation. Divide \([a,b]\) into \(n\) strips of width \(h=(b-a)/n\), and on each strip build a rectangle whose height is the function's value at the left edge, the right edge, or the middle.

spot check
\(f\) is increasing on \([a,b]\). The left-endpoint rectangles…
Rectangles approximating the area under a parabola The curve y equals x squared from zero to two, with four rectangles using left endpoints, which sit below the curve and underestimate the area. 00.511.52 each rectangle is too short: the curve rises above it across every strip
Four left-endpoint rectangles under \(y=x^{2}\) on \([0,2]\). Each one is too short, because the curve rises across every strip. Narrower strips leave smaller slivers.

More rectangles, less error

The region under \(y=x^{2}\) from 0 to 2. Slide the number of strips and choose where each rectangle takes its height. The true area is \(8/3=2.6\overline{6}\).

example 2.15 — squeezing the true area

Estimate the area under \(y=x^{2}\) on \([0,2]\) with 4 strips, using left endpoints and then right endpoints. What can you conclude about the true area?

Here \(h=0.5\) and the sample points are \(0,0.5,1,1.5\) on the left and \(0.5,1,1.5,2\) on the right.

Left: \(0.5(0+0.25+1+2.25)=1.75\).   Right: \(0.5(0.25+1+2.25+4)=3.75\).

Because the function is increasing on this interval, every left rectangle is too short and every right one too tall. So the true area is trapped: $$1.75 < A < 3.75.$$ That is a poor bracket, but it is a guarantee, and it costs eight multiplications. With \(n=50\) the bracket is \(2.587<A<2.747\), and with \(n=200\) it is \(2.647<A<2.687\).

Left and right rectangles trapping the true areaFour blue rectangles whose heights are taken at the left edge of each strip, all sitting below the rising curve, and four gold rectangles taken at the right edge, all sticking out above it. 0.511.521234left rectangles (blue) sit under the curve; right rectangles (gold) stick out above it
Because \(x^{2}\) is increasing here, every left rectangle is too short and every right one too tall — so the true area is caught between the two sums, \(1.75\) and \(3.75\). The bracket is wide, but it is a guarantee rather than a guess.

Notice the gap: left and right differ by exactly \(h\left(f(b)-f(a)\right)=h\cdot 4\), which shrinks in proportion to \(h\). Halving the strip width halves the uncertainty — the same slow, dependable behaviour as bisection.

example 2.16 — the midpoint is much better

Redo the estimate with midpoints, \(n=4\), and compare the error with the left and right rules.

Midpoints \(0.25,0.75,1.25,1.75\): \(0.5(0.0625+0.5625+1.5625+3.0625)=2.625\).

The true area is \(2.6667\). Errors: left \(-0.917\), right \(+1.083\), midpoint \(-0.042\) — about twenty times better than either endpoint rule, from the same four evaluations.

The reason is visible in a sketch: a midpoint rectangle cuts the curve, losing a sliver on one side and gaining one on the other, and the two very nearly cancel. Averaging the left and right rules instead gives the trapezoid rule, \(2.75\), which is also good but not as good here. Choosing where to sample is free, and it buys accuracy that more strips would cost you dearly.

Why the midpoint rule is so accurateA single rectangle whose height is taken at the middle of the strip. The curve cuts through the top of the rectangle, leaving a small region above the rectangle on the right and an almost equal region below it on the left. lostgainedmidpoint height0.51 (the midpoint)1.512
The midpoint rectangle cuts the curve instead of sitting under or over it. The little piece it loses on the left is very nearly the same size as the piece it gains on the right, so the two errors cancel — which is why four midpoint rectangles beat four endpoint ones by a factor of about twenty.
example 2.17 — an area with no formula at all

A car's speedometer is read every 10 seconds: 0, 8, 17, 23, 26, 27, 25 m/s. Estimate the distance travelled in the first minute, and give an honest bracket.

Six strips of width 10 s. Left sum: \(10(0+8+17+23+26+27)=1010\) m. Right sum: \(10(8+17+23+26+27+25)=1260\) m.

The speed is not increasing throughout — it drops in the last interval — so the left and right sums do not strictly bracket the answer. The trapezoid rule, which averages them, gives \(1135\) m and is the sensible estimate.

And here is the point of the example: there is no formula here at all. There is a table of numbers from an instrument. No amount of calculus will give an exact answer, because the exact answer depends on what the car did between readings, and nobody recorded it. Real measurement looks like this far more often than it looks like a tidy formula, and the rectangle method is not a teaching device — it is the tool people actually use.

history

Archimedes found the area of a parabolic segment around 240 BCE, by filling it with infinitely many triangles and summing the series — getting \(4/3\) of the inscribed triangle, exactly right. He worked from a method of Eudoxus called exhaustion: to prove an area equals \(A\), show it cannot be more and cannot be less.

So area was being computed nineteen centuries before anyone worked out slopes. The hard problem was solved first, one shape at a time, by geniuses. What Newton and Leibniz added was not the idea of area but a shocking discovery about the connection between the two halves of this chapter: finding an area and finding a rate of change are opposite operations, so that solving either one solves the other. That is the Fundamental Theorem of Calculus, and it is the reason calculus is a subject rather than a collection of tricks.

idea — where this is going

Watch the pattern across this chapter. Slope was a quotient that got better as \(h\) shrank. Area is a sum that gets better as \(h\) shrinks. In both cases we can compute any particular approximation exactly, and in both cases the answer we actually want is the thing those approximations approach.

Calculus supplies the missing word: limit, the value a sequence of ever-better approximations is heading towards. It also supplies two symbols for the two destinations, and both are worth recognising on sight: \(\dfrac{dy}{dx}\) for where the slope quotients are heading, and \(\int\) for where the rectangle sums are heading — a stretched letter S, chosen because it is a sum. You are not being prepared for those symbols. You are already computing the things they stand for.

exercises 2.5
  1. A cyclist's speed increases linearly from 0 to 12 m/s over 30 s. Find the distance covered, and check it with the average-speed formula.
  2. Estimate the area under \(y=x^{3}\) on \([0,2]\) with \(n=4\), using left, right and midpoint rules. The true area is 4. Rank the three errors.
  3. Estimate the area under \(y=1/x\) from 1 to 2 with \(n=5\) midpoints. (The true value is \(\ln 2=0.6931\); how close did you get?)
  4. For a decreasing function, which of the left and right rules overestimates? Justify in one sentence.
  5. Rainfall intensity in mm/h is measured hourly during a storm: 0, 3, 9, 14, 11, 5, 1. Estimate the total rainfall by the trapezoid rule, and state one reason the true total could differ.
  6. Show that for any function, the trapezoid estimate is exactly the average of the left and right estimates.
  7. The left and right sums for an increasing \(f\) differ by \(h(f(b)-f(a))\). Use this to find how many strips guarantee an error below \(0.01\) for \(y=x^{2}\) on \([0,2]\).
  8. A student says that since the midpoint rule was better here, it is always better. Construct a function on an interval for which the midpoint rule is exact and the trapezoid rule is not, and one where both are exact.
  1. Triangle of base 30 and height 12: \(180\) m. Average speed \(6\) m/s for 30 s gives the same.
  2. \(h=0.5\). Left: \(0.5(0+0.125+1+3.375)=2.25\). Right: \(0.5(0.125+1+3.375+8)=6.25\). Midpoint: \(0.5(0.0156+0.4219+1.9531+5.3594)=3.875\). Errors: \(-1.75\), \(+2.25\), \(-0.125\). The midpoint rule wins by a factor of fourteen.
  3. \(h=0.2\), midpoints \(1.1,1.3,1.5,1.7,1.9\): \(0.2(0.9091+0.7692+0.6667+0.5882+0.5263)=0.6919\). That is within \(0.0012\) of \(\ln 2\).
  4. The left rule overestimates: on each strip the function starts high and falls, so the left-hand height is the tallest value in the strip.
  5. Trapezoid with \(h=1\): \(\tfrac12(0)+3+9+14+11+5+\tfrac12(1)=42.5\) mm. The true total could differ because the intensity between readings is unknown — a five-minute cloudburst between two hourly readings would be invisible.
  6. Left \(=h\sum_{i=0}^{n-1}f(x_i)\) and right \(=h\sum_{i=1}^{n}f(x_i)\). Their average is \(h\left(\tfrac{f(x_0)}{2}+f(x_1)+\cdots+f(x_{n-1})+\tfrac{f(x_n)}{2}\right)\), which is precisely the sum of the trapezoid areas \(h\cdot\tfrac{f(x_i)+f(x_{i+1})}{2}\).
  7. The gap is \(h(4-0)=4h\), and \(h=2/n\), so the gap is \(8/n\). For the two sums to agree within \(0.01\) we need \(n>800\). That is a lot of arithmetic for two decimal places, and it is why better rules exist.
  8. The midpoint rule is exact for any linear function, and so is the trapezoid rule — so both are exact on, say, \(y=3x+1\). For a case where they differ, take any strictly concave or convex function: on \(y=x^{2}\) over \([0,1]\) with one strip, midpoint gives \(0.25\) and trapezoid gives \(0.5\), against the true \(0.3\overline{3}\); neither is exact, and here the midpoint is closer. Neither rule is universally better, but the midpoint rule's errors are typically about half the trapezoid's and of the opposite sign — which is the observation Simpson's rule is built on.

Lecture 11 — Polynomial approximation: building a curve out of powers

Cartoon: a calculator admits how it worksA stick figure stands beside a calculator showing only the four arithmetic operations, which explains that it fakes square roots. I do not know whata square root is.I just add and multiplyvery convincingly.+ − × ÷
every calculator you have ever used, being honest for once

Here is a question with an uncomfortable answer. Your calculator computes \(\sqrt{2}\), \(\sin 37^{\circ}\) and \(e^{1.4}\) in microseconds. The processor inside it can do four things: add, subtract, multiply and divide. There is no square-root circuit and no sine circuit. So how?

The answer is that it does not compute those functions at all. It computes a polynomial that agrees with them closely enough, because polynomials are made of exactly the four operations available. This lecture builds one by hand.

Matching a curve at a point

Suppose we want a polynomial that behaves like \(f\) near \(x=0\). We have three things we can ask it to match, and each costs one coefficient:

A polynomial that gets all three right cannot help hugging the curve nearby: it starts in the same place, sets off in the same direction, and bends the same way. And every one of those three quantities can be measured from sampled values with the arithmetic of Lecture 8.

coefficients from finite differences

Sample \(f\) at \(-h\), \(0\) and \(h\). Then

$$c_0=f(0),\qquad c_1\approx\frac{f(h)-f(-h)}{2h},\qquad c_2\approx\frac{f(h)-2f(0)+f(-h)}{2h^{2}},$$

and \(p(x)=c_0+c_1x+c_2x^{2}\) is the quadratic that matches \(f\) at that point. The middle expression is the symmetric difference quotient; the last is a difference of differences, which is why it detects bending.

spot check

\(f(-0.1)=0.9\), \(f(0)=1\) and \(f(0.1)=1.2\). Estimate the slope coefficient \(c_1\).

decimals, fractions, pi and sqrt( ) are all fine

lab — identify the mystery function

A function is sampled at three points and you are told nothing else: $$f(-0.2)=0.980067,\qquad f(0)=1,\qquad f(0.2)=0.980067.$$ Build the quadratic approximation, then use it to predict \(f(0.1)\) and \(f(0.5)\).

\(c_0=1\).

\(c_1=\dfrac{0.980067-0.980067}{0.4}=0\). The function is flat at the origin — a peak or a trough.

\(c_2=\dfrac{0.980067-2+0.980067}{2(0.04)}=\dfrac{-0.039866}{0.08}=-0.49833\).

So \(p(x)=1-0.49833x^{2}\), which is suspiciously close to \(1-\tfrac12x^{2}\).

Predictions: \(p(0.1)=0.995017\) and \(p(0.5)=0.875418\).

The mystery function was \(\cos x\). The true values are \(\cos(0.1)=0.995004\) and \(\cos(0.5)=0.877583\). Near the sample points the approximation is good to five decimal places; two-tenths further out it has already lost two of them.

You have just derived the first two terms of the cosine series from three numbers and some division. Madhava of Sangamagrama and the Kerala school had the full series — and \(\pi\) to eleven places — by about 1400, some 250 years before Newton, Gregory and Taylor, working in a tradition that reached Europe by a route historians still argue about.

Going further: square roots from arithmetic

The same idea, carried to three terms, gives one of the most useful approximations in practice:

the binomial approximation $$\sqrt{1+x}\;\approx\;1+\frac{x}{2}-\frac{x^{2}}{8}+\frac{x^{3}}{16}$$

valid for \(x\) near zero, with each extra term shrinking the error.

spot check

Use the first two terms, \(1+\tfrac{x}{2}\), to estimate \(\sqrt{1.06}\).

decimals, fractions, pi and sqrt( ) are all fine

example 2.18 — how good is it?

Approximate \(\sqrt{1.1}\), \(\sqrt{1.5}\) and \(\sqrt{0.7}\) with one, two and three terms, and compare with the true values.

true1 term2 terms3 terms
\(x=0.1\)1.0488091.0500001.0487501.048813
\(x=0.5\)1.2247451.2500001.2187501.226562
\(x=-0.3\)0.8366600.8500000.8387500.837063

At \(x=0.1\) three terms give six correct digits — better than most measurements deserve, from two multiplications and two additions. At \(x=0.5\) the same three terms give only two. The approximation is local: it is built at zero and it degrades as you walk away.

That is not a defect to be apologised for, it is the deal. And it is worth noticing which of the three terms did what: the first term is a flat guess, the second adds the slope, and the third adds the bend — the correction that curvature makes to a straight-line estimate.

Adding terms one at a time

The curve is \(y=\sqrt{1+x}\). Raise the degree and watch the polynomial peel away later and later. Notice that no polynomial can follow it past \(x=-1\), where the true function simply stops.

anchored here y = √(1+x)

example 2.19 — a percentage shortcut worth keeping

Show that a 6% increase followed by a 6% decrease leaves you slightly worse off, and quantify it with the approximation \((1+x)(1-x)=1-x^{2}\).

\(1.06\times0.94=0.9964\), a loss of \(0.36\%\). The identity says the result is \(1-0.06^{2}=1-0.0036\), which is exactly it.

The general lesson: small percentage changes almost cancel, and what survives is a second-order term — a term in \(x^{2}\). Ignore it and you have the useful rule that percentages add; keep it and you know the size of the error you are making.

This is the whole philosophy of approximation in one line. First-order thinking gets you the trend. Second-order thinking — curvature again — tells you how wrong the trend is.

idea — what calculus will add

Everything in this lecture was done with sampled values and division. Our estimate of the slope came from two nearby values; our estimate of the bend came from three. Calculus replaces those estimates with exact ones, and once it does, a clean pattern appears in the coefficients: the \(x\) term is built from the exact slope, the \(x^{2}\) term from the exact bend divided by 2, the \(x^{3}\) term from the next quantity divided by 6, and so on down the line. The result is called a Taylor series, and those divisors are doing exactly the job our \(2h^{2}\) denominator was doing.

Then it goes further than we can. It proves how large the error is, rather than letting you observe it. It says which functions are equal to their infinite series and which merely resemble them. And it explains the wall at \(x=-1\) in the picture above — the radius of convergence, a boundary you cannot cross no matter how many terms you take, and which turns out to be governed by behaviour in the complex plane that has nothing visibly to do with the real graph at all.

That is the shape of the whole subject. You arrive already able to compute the objects. Calculus tells you why they work, how well, and where they stop.

exercises 2.6
  1. Use \(\sqrt{1+x}\approx1+\tfrac{x}{2}-\tfrac{x^{2}}{8}\) to estimate \(\sqrt{1.02}\) and \(\sqrt{0.96}\), and find the error in each.
  2. Estimate \(\sqrt{26}\) by writing it as \(5\sqrt{1+0.04}\). Why is rewriting it this way necessary?
  3. A function is sampled: \(g(-0.1)=0.904837\), \(g(0)=1\), \(g(0.1)=1.105171\). Find the quadratic approximation at 0 and guess the function.
  4. Using the coefficients from the previous exercise, predict \(g(0.3)\) and compare with the true value \(1.349859\). Comment on the accuracy.
  5. Show that the quadratic through the three points \((-h,f(-h))\), \((0,f(0))\), \((h,f(h))\) has leading coefficient \(\dfrac{f(h)-2f(0)+f(-h)}{2h^{2}}\), by substituting the three points into \(c_0+c_1x+c_2x^{2}\) and solving.
  6. The approximation \(\sin x\approx x\) is used constantly in physics for small angles. Using \(\sin(0.2)=0.198669\), find the largest angle in degrees for which this is accurate to within 1%.
  7. Explain why no polynomial can be a good approximation to \(1/x\) near \(x=0\), no matter how high its degree.
  8. Take \(f(x)=1/(1-x)\) and check that \(1+x+x^{2}+x^{3}\) approximates it at \(x=0.1\), \(x=0.5\) and \(x=0.9\). What happens as \(x\) approaches 1, and what does that suggest about the limits of approximation?
  1. \(\sqrt{1.02}\approx1+0.01-0.00005=1.00995\); true \(1.009950\), error under \(10^{-6}\). \(\sqrt{0.96}\approx1-0.02-0.0002=0.9798\); true \(0.979796\), error about \(4\times10^{-6}\).
  2. \(\sqrt{26}=\sqrt{25}\sqrt{1.04}=5(1+0.02-0.0002)=5(1.0198)=5.0990\); true \(5.09902\). Rewriting is necessary because the approximation is built at \(x=0\) and is worthless at \(x=25\) — you must first extract a factor you know exactly, leaving a small correction.
  3. \(c_0=1\); \(c_1=\dfrac{1.105171-0.904837}{0.2}=1.00167\); \(c_2=\dfrac{1.105171-2+0.904837}{0.02}=0.50040\). So \(p(x)\approx1+x+\tfrac12x^{2}\), which is \(e^{x}\).
  4. \(p(0.3)=1+0.3+0.045=1.345\), against \(1.349859\): an error of \(0.005\), about \(0.36\%\). Three times further from the anchor than the samples were, and the error has grown roughly with the cube of the distance — which is the size of the first term we left out.
  5. Substituting \(x=0\) gives \(c_0=f(0)\). Substituting \(\pm h\) gives \(f(\pm h)=c_0\pm c_1h+c_2h^{2}\). Adding those two kills \(c_1\): \(f(h)+f(-h)=2c_0+2c_2h^{2}\), so \(c_2=\dfrac{f(h)+f(-h)-2f(0)}{2h^{2}}\).
  6. At \(0.2\) rad the error is \(0.2-0.198669=0.001331\), which is \(0.67\%\) of \(0.198669\). Trying larger angles, 1% error is reached near \(0.245\) rad, about \(14^{\circ}\). (The error grows like \(x^{3}/6\), so it climbs quickly after that.)
  7. Every polynomial is finite at \(x=0\), while \(1/x\) blows up there. No finite value can approximate an unbounded one, so the failure is not about degree — it is structural. Near \(x=0\) one needs a different tool, which is what a Laurent series provides, or a change of variable.
  8. At \(x=0.1\): \(1.111\) against \(1.1111\). At \(0.5\): \(1.875\) against \(2\). At \(0.9\): \(3.439\) against \(10\). As \(x\to1\) the true function runs to infinity and no finite sum can follow. Approximations built at a point have a range of validity, and the boundary is set by where the function misbehaves, not by how hard you try.

Where this chapter leaves you

One idea, six ways. A curve is hard, so replace it locally with something flat and easy, and control the error: a secant line to measure a rate, a step against that slope to find a valley, a tangent line to chase a root, rectangles to accumulate a total, and a polynomial to stand in for a function a processor cannot compute. Every one of those is exact arithmetic producing an approximate answer, and every one of them gets better as a step size shrinks.

You have also met curvature twice: as the number that measures how hard a curve bends, and as the quantity Gauss proved cannot be changed by bending a surface — the reason a folded slice of pizza holds itself up and a flat map of the world cannot be honest.

Chapter 3 leaves polynomials behind for functions that grow in proportion to themselves, where a limit appears again and produces a number nobody chose.

Next: Chapter 3 — Growth: exponentials and logarithms.