The derivative is a velocity¶
Level: 101 → 201 · for anyone who can multiply out (3 + h)², and who has watched a car's speedometer
One line: The velocity of a moving point at one instant is the number its average velocities settle on as the time interval shrinks; that number is the derivative, and knowing it is knowing how to take the next small step.
Two arrows on a number line¶
The talk behind Euler's identity draws e^t as an arrow on a number line labelled Position, and its derivative d/dt e^t as a second arrow starting at the tip of the first, labelled Velocity. Before e appears at all, there is the question of what the second arrow is. This page answers it with motions simple enough to compute exactly.
A point moves along a number line, and x(t) is where it is at time t. Between the times t and t + h it covers the distance x(t + h) − x(t), so its average velocity over that stretch is
A speedometer does not show an average, though. It shows the velocity at an instant, and an instant has no length: put h = 0 in the formula and it reads 0/0. The way out is to take shorter and shorter stretches and watch where the averages go.
What the program prints¶
Verified output of derivative_as_velocity.py — regenerated by tools/run_examples.py, never hand-typed.
1. A STEADY MOTION: x(t) = 5 + 3t
The average velocity over any stretch of time, long or short:
from t to t + h distance time average velocity
0 1 3 1 3
2 5/2 3/2 1/2 3
7 7001/1000 3/1000 1/1000 3
Always 3. A steady motion has one velocity, and every average finds it.
2. A MOTION THAT SPEEDS UP: x(t) = t^2
The averages over [3, 3 + h] depend on h:
h = 1 average velocity = 7 = 6 + 1
h = 1/10 average velocity = 61/10 = 6 + 1/10
h = 1/100 average velocity = 601/100 = 6 + 1/100
h = 1/1000 average velocity = 6001/1000 = 6 + 1/1000
h = 1/1000000 average velocity = 6000001/1000000 = 6 + 1/1000000
Algebra says why: ((3 + h)^2 - 9) / h = (6h + h^2) / h = 6 + h,
exactly. The averages settle on 6, and no single h gives 6 itself:
the velocity at the instant t = 3 is 6. At other instants:
t = 0 average over [t, t + 1/1000] = 1/1000 settles on 0 = 2t
t = 1 average over [t, t + 1/1000] = 2001/1000 settles on 2 = 2t
t = 2 average over [t, t + 1/1000] = 4001/1000 settles on 4 = 2t
t = 3 average over [t, t + 1/1000] = 6001/1000 settles on 6 = 2t
t = 4 average over [t, t + 1/1000] = 8001/1000 settles on 8 = 2t
The velocity of t^2 at time t is 2t: the derivative of t^2 is 2t.
3. THE NOTATION
d/dt x, x'(t) and dx/dt all name the velocity of x at time t, the
number the averages (x(t + h) - x(t)) / h settle on as h shrinks:
d/dt (5 + 3t) = 3 d/dt t^2 = 2t
'd' is for difference: dx is a small change in position, dt a small
change in time, and dx/dt their ratio when both are very small.
4. STEPPING WITH A VELOCITY
Knowing the velocity lets you step forward: over a short time dt the
position moves by about velocity . dt. Start x = t^2 at x = 0 and
step to t = 3 using only the velocity 2t:
3 steps of dt = 1 x reaches 6 = 6.0000
30 steps of dt = 1/10 x reaches 87/10 = 8.7000
300 steps of dt = 1/100 x reaches 897/100 = 8.9700
3000 steps of dt = 1/1000 x reaches 8997/1000 = 8.9970
The true position is 3^2 = 9. Each step uses the velocity at its
start, which is a little too low for a motion that speeds up, and
the shortfall is exactly 9/n: smaller steps, smaller error.
5. IN FLOATS, THE STEP CANNOT SHRINK FOREVER
The same average for t^2 at t = 3, in floating point:
h average velocity off 6 by
1e-1 6.100000000000012 1.0e-01
1e-2 6.009999999999849 1.0e-02
1e-3 6.000999999999479 1.0e-03
1e-4 6.000100000012054 1.0e-04
1e-5 6.000009999951316 1.0e-05
1e-6 6.000001000927568 1.0e-06
1e-7 6.000000087880153 8.8e-08
1e-8 5.999999963535174 3.6e-08
1e-9 6.000000496442226 5.0e-07
1e-10 6.000000496442226 5.0e-07
1e-11 6.000000496442226 5.0e-07
1e-12 6.000533403494046 5.3e-04
1e-13 5.986322548778844 1.4e-02
1e-14 6.217248937900877 2.2e-01
1e-15 5.329070518200751 6.7e-01
The error falls with h, then rises again. (3 + h)^2 and 9 agree in
more and more leading digits, and subtracting them leaves only the
rounding: catastrophic cancellation. Exactly, the error is h; in
floats the best h is near 1e-8, and no h gives more than about half
the digits of a double.
A steady motion¶
Section 1 moves a point by x(t) = 5 + 3t: it starts at 5 and gains 3 every unit of time. Every average velocity is 3, over a whole unit of time or over a thousandth of one. A steady motion has one velocity, and there is nothing to settle.
A motion that speeds up¶
Section 2 moves the point by x(t) = t². Now the averages over [3, 3 + h] depend on h: 7 over a whole unit, 6.1 over a tenth, 6.01 over a hundredth. The program computes them as exact fractions, so the pattern is not approximate, and algebra says why:
The average is 6 + h exactly. As h shrinks the averages settle on 6, and no stretch of time gives 6 itself, because every stretch has some length. The number the averages settle on is the velocity at the instant, and it is called the derivative. At the instant t = 3 the velocity of t² is 6; the same algebra at any t gives 2t + h, which settles on 2t, and section 2 prints it for t = 0 to 4. The derivative of t² is 2t.
"Settle on" is what a calculus course calls a limit, and it makes the phrase precise. For following the talk the picture is enough: the velocity is what the average velocities over shorter and shorter times are heading for.
The notation¶
Section 3 names it. d/dt x, x′(t) and dx/dt are three spellings of the same thing, the velocity of x at time t. The d is for difference: dx is a small change in position, dt a small change in time, and dx/dt their ratio when both are very small. So d/dt (5 + 3t) = 3 and d/dt t² = 2t. On the talk's slides, d/dt e^t sits in a box labelled Velocity, and this is all the box means.
Stepping with a velocity¶
The reason to know a velocity is that it says where the point goes next. Over a short time dt the position moves by about velocity · dt:
That is the talk's picture exactly: the velocity arrow starts at the tip of the position arrow, and a short time later the position has moved a little way along it. Section 4 uses the rule to rebuild x = t² from its velocity 2t alone, starting at 0 and stepping to t = 3. Three steps reach 6, thirty reach 8.7, three thousand reach 8.997, and the true position is 9. Each step uses the velocity at its start, which is a little too low for a motion that is speeding up, and the shortfall is exactly 9/n, so smaller steps give smaller errors.
The same stepping is how the next lesson finds e, and how Euler's identity walks a point round a circle. It has a name, Euler's method, after the same Euler.
In floats, the step cannot shrink forever¶
Exactly, the average for t² at t = 3 is off by h, so a smaller h is always better. Section 5 does the same computation in floating point and finds the opposite past a certain point: the error falls to about 4 × 10⁻⁸ at h = 10⁻⁸ and then climbs, until at h = 10⁻¹⁵ the answer is 5.33. (3 + h)² and 9 agree in more and more leading digits, and subtracting them leaves only rounding. That is catastrophic cancellation, and it means a program cannot find a derivative by making h tiny; the best it can do this way is about half the digits of a double. The lessons in this chapter measure velocities with h = 10⁻⁶, near the sweet spot, and print six decimals.
Run it yourself¶
From the root of your clone of this repository:
Po polsku, w skrócie¶
Punkt porusza się po osi liczbowej, a x(t) to jego położenie w chwili t. Średnia prędkość między t a t + h to przebyta droga przez czas: (x(t + h) − x(t)) / h. Prędkość w jednej chwili, tę ze szybkościomierza, dostaje się, skracając odcinek czasu i patrząc, do czego dążą średnie. Dla x = t² w chwili 3 średnia to dokładnie 6 + h, więc dąży do 6, choć żaden odcinek czasu nie daje samego 6. Ta liczba to pochodna, zapisywana d/dt x, x′(t) albo dx/dt; pochodna t² to 2t.
Prędkość mówi, gdzie punkt będzie za chwilę: nowe położenie ≈ położenie + prędkość · dt. To dokładnie obrazek z wykładu, strzałka prędkości zaczepiona na końcu strzałki położenia, i to z niego następna lekcja buduje e^t. Pułapka jest w komputerze: w liczbach zmiennoprzecinkowych h nie może maleć bez końca, bo odejmowanie prawie równych liczb zjada cyfry, i najlepsze h to około 10⁻⁸.
Auf Deutsch: Stichwörter¶
Die Geschwindigkeit in einem Augenblick ist der Wert, auf den sich Durchschnittsgeschwindigkeiten einpendeln, wenn das Zeitintervall schrumpft: die Ableitung.
Stichwörter: Ableitung, Momentangeschwindigkeit, Durchschnittsgeschwindigkeit, Differenzenquotient, Grenzwert, Differentialquotient, numerische Ableitung, Schrittweite.
See also¶
- Velocity equals position — the next lesson: the motion whose velocity is its own position, which is e^t
- Euler's identity — where the talk's position and velocity arrows are going: round a circle
- Euler's formula: a lesson plan — this page is step 7 of it
- Catastrophic cancellation — why section 5's error climbs back up
- Linear equations and their solutions — x = 5 + 3t is a line, and a line is the motion with one velocity
- The essence of calculus, 3Blue1Brown ↗ — chapters 1 and 2, the derivative as a rate of change and the paradox of a velocity at an instant
- Derivative ↗ — Wikipedia
- Where this is taught — books and free courses