Velamuvi AIAcademy

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
In this lesson you will learn
  • 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)) / h

where 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):

-4-3-2-101234-20246810
f(x) = x²
at x = 1: f(x) = 1slope of tangent = 2slope of secant = 3.5
As h shrinks, the slope of the secant gets closer and closer to the slope of the tangent. For x² at x = 1, that slope is 2.

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 → 0

Let us watch the limit happen for f(x) = x² at x = 3:

Try it yourselfPython
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.

-4-3-2-101234-6-4-20246810
f(x) = x²f'(x) = 2x (the slope)
Where x² goes downhill (x < 0), its derivative is negative. Where it is flat (x = 0), the derivative is 0. Where it climbs, the derivative is positive.

Notation

You will see several ways to write the same derivative:

NotationRead asWho 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 pointThe function there is...
positivegoing up (increasing)
negativegoing down (decreasing)
zeroflat: possibly a lowest or highest point
large (positive or negative)changing quickly, steep
smallchanging slowly, gentle

Explore it on a wavy curve. Find the points where the tangent is flat:

-4-3-2-101234-2-10123456
f(x)
at x = 1.5: f(x) = 1.503slope of tangent = -0.725
The slope is 0 at the bottom of each valley and at the top of the hill. Those flat points are exactly what training searches for.

Common mistakes

Practice exercise

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.)

Your solutionPython
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
Knowledge check

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.