Objective
Learning objectives
- Distinguish average rate of change (secant slope) from instantaneous rate of change (tangent slope)
- Explain instantaneous rate of change as what a secant slope converges to as the gap shrinks toward zero
- Compute secant slopes for progressively smaller gaps and observe numeric convergence
- Estimate a tangent slope using two very close secant points
Hook
Phase 01's slope() always needed two points — rise over run, between here and there. But a curve doesn't have one steepness; it has a different steepness at every single point. So: exactly how fast is a curve changing right at one specific point, not averaged between two? That question sounds like it needs a genuinely new tool. It mostly just needs Phase 01's oldest one, pushed to its limit.
See it
Point A stays fixed on the curve; point B starts far away and slides toward it. The line through both — the secant line — is exactly Phase 01's slope calculation, just drawn on a curve instead of a straight line. Watch the live slope value in the title as B slides in: it doesn't jump around randomly, it converges, settling closer and closer to one specific number — the slope of the curve at point A alone, no second point required once you've found it.
The secant slope was never wrong — it was just answering a different question
slope(A, B) always correctly reports the average rate of change between A and B. That's a real, useful, correctly-computed number. It just isn't the same question as "how steep is the curve exactly at A" — and the whole trick of this lesson is realizing that shrinking the gap between A and B all the way to zero turns one question into the other.
Name it
Average rate of change between two points is exactly Phase 01's slope: rise over run, computed between two distinct points on a curve — geometrically, the secant line's slope. Instantaneous rate of change is the rate of change at one single point, with no second point at all — geometrically, the tangent line's slope, the line that just grazes the curve at exactly that spot.
The connection between them: instantaneous rate of change is what the average rate of change converges to as the second point slides infinitely close to the first. This limiting idea has a name — the derivative — named here only as vocabulary. Its full treatment, including how to compute it without ever needing to shrink a gap by hand, is Math for AI & ML's Calculus & Optimization material. What matters here is that the idea itself — a limit of a shrinking secant — is no longer unfamiliar when you get there.
Code it
def f(x):
return x * x
def secant_slope(x0, h):
return (f(x0 + h) - f(x0)) / h
x0 = 1
for h in [1, 0.1, 0.01, 0.001, 0.0001]:
print(h, secant_slope(x0, h))
1 3.0
0.1 2.100000000000002
0.01 2.0100000000000007
0.001 2.0009999999996975
0.0001 2.000099999999172
Each row shrinks the gap h by a factor of 10, and the slope creeps steadily toward 2.0 — never quite reaching it in this table, but leaving no doubt about where it's headed. That number, 2, is exactly the tangent slope the figure's secant line was visually converging onto at x0 = 1. Numeric convergence and visual convergence are reporting the same fact two different ways.
def g(x):
return x ** 3
def secant_slope_g(x0, h):
return (g(x0 + h) - g(x0)) / h
for h in [1, 0.1, 0.01]:
print(h, secant_slope_g(2, h))
Different function (x³ instead of x²), different point (x0 = 2), same convergence pattern: each smaller h pulls the slope closer to a single number, here 12. Nothing about the method changed — only which function and point it's being applied to.