Lesson 2 of 16 · Change
Slopes and Derivatives
Learn what a derivative is: the slope of a curve at a single point. Go from the slope of a line to secant and tangent lines, the limit definition, notation like dy/dx, and why derivatives tell a model which way to move.
- 10 min read
- Intermediate
- Reviewed
- How to measure the slope of a straight line
- What an average rate of change and a secant line are
- How the derivative is defined as a limit
- How to read derivative notation such as f'(x) and dy/dx
- What the sign and size of a derivative tell you
The slope of a line
A straight line has the same steepness everywhere. Its slope is how much it goes up for each step to the right:
slope = rise / run = (change in y) / (change in x)The line y = 2x + 1 goes up 2 for every 1 step to the right, so its slope is 2. A slope of 0 is flat, and a negative slope goes downhill.
The slope of a curve
A curve like y = x² is gentle near 0 and steep further out. Its steepness changes from point to point, so "the slope" only makes sense at a particular point.
To measure it, start with two points on the curve and draw the straight line through them, a secant line. Its slope is the average rate of change between the two points:
average rate of change = (f(x + h) - f(x)) / hwhere h is the gap between the two x values.
Now shrink the gap h. The second point slides towards the first, and the secant line turns until it just touches the curve. That final line is the tangent line, and its slope is the slope of the curve at that point.
Move the sliders. Make h small and watch the dashed secant (orange) become the tangent (pink):
The derivative
The slope of the tangent is the limit of the secant slopes as h approaches 0. That limit has a name:
f'(x) = lim (f(x + h) - f(x)) / h
h → 0Let us watch the limit happen for f(x) = x² at x = 3:
def f(x):
return x**2
x = 3
for h in [1, 0.1, 0.01, 0.001, 0.0001]:
slope = (f(x + h) - f(x)) / h
print(f"h = {h:<7} secant slope = {slope:.4f}")The secant slopes approach 6. So the derivative of x² at x = 3 is 6.
The derivative is a function
Notice that the answer, 2x, is itself a function: plug in any x to get the slope there. The derivative turns one function into another.
Notation
You will see several ways to write the same derivative:
| Notation | Read as | Who uses it |
|---|---|---|
f'(x) | "f prime of x" | most textbooks |
dy/dx | "d y by d x" | physics, ML papers |
d/dx f(x) | "the derivative with respect to x of f(x)" | when f is a formula |
∂L/∂w | "partial L by partial w" | ML, for functions of many variables (a later lesson) |
dy/dx is a reminder of where the derivative comes from: a tiny change in y divided by a tiny change in x.
What a derivative tells you
| Derivative at a point | The function there is... |
|---|---|
| positive | going up (increasing) |
| negative | going down (decreasing) |
| zero | flat: possibly a lowest or highest point |
| large (positive or negative) | changing quickly, steep |
| small | changing slowly, gentle |
Explore it on a wavy curve. Find the points where the tangent is flat:
Common mistakes
Estimate the slope of x³ at three points. (In the next lesson you will learn that the exact derivative is 3x², which gives 3, 12 and 27.)
def f(x):
return x**3
h = 0.001
# For x = 1, 2 and 3, estimate the slope of f with (f(x + h) - f(x)) / h
# and print it rounded to 2 decimal places.
# Output must be exactly:
# x = 1: slope ≈ 3.0
# x = 2: slope ≈ 12.01
# x = 3: slope ≈ 27.01
At a point where the derivative of a function is negative, the function is...
Summary
- The slope of a line is rise over run.
- A secant line through two points gives an average rate of change.
- The derivative is the limit of that average as the gap h approaches 0: the slope of the tangent line.
- The derivative of x² is 2x. The derivative is itself a function.
- Its sign says up or down, its size says how steeply, and 0 means flat.
Next: rules that give derivatives instantly, without limits.
Finished reading? Tick it off to track your progress.