The derivative of a function tells you how fast it is changing at one exact point. A car's speedometer shows the derivative of its position.
Slope from two points
Between x and x + h, the function rises f(x + h) − f(x) over a run of h. The slope of that line is the difference quotient:
slope ≈ (f(x + h) − f(x)) ÷ h
Make h smaller and the two points close in on one: the line becomes the tangent to the curve. The limit of the difference quotient as h approaches 0 is the derivative, written f′(x) or dy/dx.
def f(x):
return x * x
x = 3
for h in [1, 0.1, 0.01, 0.001]:
slope = (f(x + h) - f(x)) / h
print("h =", h, " slope ≈", round(slope, 4))
print("exact: f'(3) = 2 × 3 =", 2 * x)For f(x) = x² at x = 3 the slopes approach 6. Algebra shows why: (x + h)² − x² = 2xh + h², so the quotient is 2x + h, which approaches 2x.
What the sign tells you
- f′(x) above 0: the function is going up there.
- f′(x) below 0: it is going down.
- f′(x) = 0: it is flat for an instant, often at a peak or a valley (the lesson after next).
Common mistakes
- Choosing h far too small on a computer. With h = 10⁻¹⁵, f(x + h) and f(x) agree in almost every digit, and their difference is mostly rounding error. A middle value such as 10⁻⁵ works best.
Quick check
My notes
Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.