Calculus I for Programmers

Limits, via floating point

2 / 184
Contents

Contents

Calculus I for Programmers

0 of 184 complete

9 min read

Watching h shrink

Put the difference quotient in a loop, divide the step by ten each pass, and read down the column.

The last lesson used four values of h, chosen by hand. Choosing them by hand is the part worth automating. Start h at 1 and divide it by ten on every pass, and the answers arrange themselves into a column that can be read straight down.

The code below writes the step as 10−k10^{-k} and lets k count up. That is the same sequence 1, 0.1, 0.01 and so on, written in a way that makes the size of the step easy to say out loud.

Try CodePython

Change range(8) to range(4) and read those four lines slowly first. Then put it back, and change a to 10.

Step hQuotientGap the algebra predicts, h
17.0000000000001
0.16.1000000000000.1
0.016.0100000000000.01
0.0016.0009999999990.001
0.00016.0001000000120.0001
0.000016.0000099999510.00001
The first six rows, beside the gap the algebra says there should be.

The algebra from the last lesson said this quotient equals 2a+h2a + h, which at a=3a = 3 is 6+h6 + h. So it predicts a gap from 6 of exactly hh, and that is the third column. For the first three rows the printed quotient really is 6 plus it. From the fourth row it is not: the loop prints 6.000999999999 where the algebra says 6.001, and 6.000009999951 where it says 6.00001. Hold on to that. It is the whole subject of the next lesson.

What the column is doing, and what it is not

The numbers are not reaching 6. No row is 6. Every row sits a little above it, and no row can ever be the row where h is zero, because that row would ask the program to divide by zero. Whatever is going on, arriving is not it.

What the column does is get as close to 6 as you care to demand, and then stay there. That last clause is the important half. It is not enough that some step landed near 6; the claim is that from a certain step onward, every smaller step is near 6 too.

Say it as a bargain. You name a distance, as small as you like. One thousandth, say. I must then produce a step size such that every step smaller than mine keeps the quotient within one thousandth of 6. Here I can: any h below 0.001 does it, because the gap is exactly h. Name one millionth instead and I answer with 0.000001. You have no distance I cannot answer.

The notation

That bargain is what the word limit means, and it has a symbol. Writing lim⁡\lim under a condition like h→0h \to 0 says: this is the number the expression stays arbitrarily close to as h gets small.

lim⁡h→0(3+h)2−32h=6\lim_{h \to 0} \frac{(3+h)^2 - 3^2}{h} = 6
Read: the limit, as h tends to zero, of that quotient, is 6.

The arrow is not an instruction to substitute. There is no point in this statement at which h takes the value 0, and the expression has no value there to take. The whole statement is about the neighbourhood of zero, with zero itself removed.

Reading the limit off the column
(a+h)2−a2hwitha=3,  h=10−3\frac{(a+h)^2 - a^2}{h} \quad\text{with}\quad a = 3,\; h = 10^{-3}
-1.2-0.600.61.20.51.883.254.636
Step hh
0.001
Difference quotient
6.001
What the algebra predicts, 2a2a
6
Gap between them
0.000999999999

The curve is the gap itself, computed at every starting point rather than only at yours, and the dot on it is your aa. Drag k from 0 to 8 and watch the curve settle onto the zero line: every step of k divides the gap by ten. Then keep dragging past 12. The curve breaks up into noise, and by k = 16 it has dived clean off the bottom of the frame. That reversal is not mathematics, and it is the next lesson.

Both sides of the point

So far h has been positive, which means measuring forward: from 3 seconds to slightly after 3 seconds. Nothing stops it being negative. The interval from 2.9 to 3 is just as good an interval, and the same formula handles it, because both the rise and the run change sign and the two changes cancel.

The algebra predicts this too. 2a+h2a + h at a=3a = 3 with h=−0.1h = -0.1 is 5.9, which is a little below 6 rather than a little above it. Both sides close in on the same number, from opposite directions.

Try CodePython

Change f to return abs(x) and a to 0.0. The two directions now settle on different numbers, and the last lesson of this section is about what that means.

One more function, so that none of this looks like a peculiarity of squaring. Take f(x)=1/xf(x) = 1/x at a=2a = 2. The quotients run -0.1667, then -0.2381, then -0.2488, then -0.2499. They are closing in on −1/4-1/4, and the sign says something real: the function is falling as xx increases, so the slope of every secant is negative.

Try CodePython

Change a to 1.0 and run it again, then to 4.0. Line the three answers up against −1/a2-1/a^2 and see whether that guess survives.

By hand, simplify 12+h−12h\frac{\frac{1}{2+h} - \frac{1}{2}}{h} until no hh is left in the denominator, and say what is left when hh goes to zero.

Put the top over a common denominator: 12+h−12=2−(2+h)2(2+h)=−h2(2+h)\frac{1}{2+h} - \frac{1}{2} = \frac{2 - (2+h)}{2(2+h)} = \frac{-h}{2(2+h)}. Dividing that by hh cancels the hh and leaves −12(2+h)\frac{-1}{2(2+h)}. As hh goes to zero this heads for −14\frac{-1}{4}, which is the number the loop was closing in on.

All lessons in Calculus I for Programmers