A shop sold 200 cups of tea on Monday and 260 on Thursday. Sales went up by 60 cups over 3 days: on average, 20 more cups per day. That "per day" number is a rate of change: how much one thing changes for each unit of another. Kilometres per hour, rupees per month, marks per hour of study, and errors per training step are all rates of change.
Rates of change are the starting point of calculus. For straight lines the rate is the slope, and it's the same everywhere. For curves it depends on where you measure and over how long, and that turns out to be the key to the derivative. This lesson explains the average rate of change, how to read its units, how it appears on a graph as the slope of a secant line, and what happens when you measure it over smaller and smaller intervals.
What you need first: what is calculus?, slope and intercept and ratios, proportions and rates.
Key terms
- Rate of change: change in output ÷ change in input, such as kilometres per hour.
- Average rate of change: the rate of change between two points, ignoring what happens in between.
- Interval: the stretch of input you measure over, such as "from 2 to 4 hours".
- Secant line: a straight line through two points on a curve. Its slope is the average rate of change between them.
- Δ (delta): "change in". Δx means the change in x.
The formula, from the tea example
Monday is day 1 with 200 cups; Thursday is day 4 with 260:
average rate of change = (change in output) ÷ (change in input) = Δy ÷ Δx
= (260 − 200) ÷ (4 − 1) = 60 ÷ 3 = 20 cups per day
For a function f between inputs a and b:
average rate of change = (f(b) − f(a)) ÷ (b − a)
Read it as "the output at b minus the output at a, divided by b minus a". It's exactly the slope formula, rise over run, from slope and intercept.
The units tell you what it means: output units "per" input unit. Cups per day, km per hour, ₹ per kg. If you can't say the units, you don't know what the number means yet.
The sign matters too:
| Rate | Means |
|---|---|
| Positive | The output is rising |
| Zero | No overall change between the two points |
| Negative | The output is falling |
For a straight line, the rate never changes
A taxi charges ₹50 to start plus ₹15 per km: fare(d) = 15d + 50. Measure the average rate over different intervals:
import numpy as np
import matplotlib.pyplot as plt
def fare(km):
return 15 * km + 50
def average_rate(f, a, b):
return (f(b) - f(a)) / (b - a)
for a, b in [(0, 1), (2, 10), (7, 7.5)]:
print(f"from {a} to {b} km: {average_rate(fare, a, b):.1f} rupees per km")
from 0 to 1 km: 15.0 rupees per km
from 2 to 10 km: 15.0 rupees per km
from 7 to 7.5 km: 15.0 rupees per km
Always ₹15 per km, wherever and however long you measure. That's what makes a straight line straight.
For a curve, it depends on where you look
A car pulls away from traffic lights, speeding up steadily. Its distance in metres after t seconds is d(t) = 2t². Measure the average speed over a few different intervals:
def distance(t):
return 2 * t ** 2 # metres after t seconds
for a, b in [(0, 2), (2, 4), (4, 6)]:
print(f"seconds {a} to {b}: travelled {distance(b) - distance(a):.0f} m, "
f"average speed {average_rate(distance, a, b):.0f} m/s")
seconds 0 to 2: travelled 8 m, average speed 4 m/s
seconds 2 to 4: travelled 24 m, average speed 12 m/s
seconds 4 to 6: travelled 40 m, average speed 20 m/s
The same 2-second interval gives three different average speeds: 4, 12 and 20 m/s. The car covers more ground in each 2-second stretch than the last, because it's speeding up. For a curve, the average rate of change depends on where you measure.
On a graph, each average rate is the slope of a secant line: the straight line through the two points on the curve.
t = np.linspace(0, 6, 200)
fig, ax = plt.subplots(figsize=(7.5, 5))
ax.plot(t, distance(t), color="black", linewidth=2.5, label="d(t) = 2t²")
for (a, b), colour in zip([(0, 2), (2, 4), (4, 6)], ["#1f5fbf", "#16a34a", "#c2410c"]):
rate = average_rate(distance, a, b)
ts = np.array([a - 0.5, b + 0.5])
ax.plot(ts, distance(a) + rate * (ts - a), color=colour, linestyle="--", label=f"secant {a}–{b} s: slope {rate:.0f} m/s")
ax.plot([a, b], [distance(a), distance(b)], "o", color=colour)
ax.set_xlim(0, 6.5)
ax.set_ylim(-5, 80)
ax.set_xlabel("Time (seconds)")
ax.set_ylabel("Distance (metres)")
ax.set_title("Each average speed is the slope of a secant line")
ax.legend(loc="upper left")
plt.show()
Shrinking the interval
The average speed from 2 to 4 seconds is 12 m/s, but the car is speeding up the whole time: slower than 12 at the start, faster at the end. So what's the speed at exactly 2 seconds? Measure over shorter and shorter intervals starting at 2:
print("interval average speed")
for width in [2, 1, 0.5, 0.1, 0.01, 0.001]:
print(f"2 to {2 + width:<7} {average_rate(distance, 2, 2 + width):.4f} m/s")
interval average speed
2 to 4 12.0000 m/s
2 to 3 10.0000 m/s
2 to 2.5 9.0000 m/s
2 to 2.1 8.2000 m/s
2 to 2.01 8.0200 m/s
2 to 2.001 8.0020 m/s
As the interval shrinks, the average speed settles on 8 m/s: 12, 10, 9, 8.2, 8.02, 8.002. The extra after the 8 is exactly twice the interval width, so it disappears as the width heads to zero. In limit notation: the speed at t = 2 is lim (h → 0) (d(2 + h) − d(2)) ÷ h = 8 m/s.
fig, ax = plt.subplots(figsize=(7.5, 5))
t = np.linspace(0, 4.5, 200)
ax.plot(t, distance(t), color="black", linewidth=2.5, label="d(t) = 2t²")
for width, colour in zip([2, 1, 0.5], ["#fca5a5", "#f87171", "#dc2626"]):
rate = average_rate(distance, 2, 2 + width)
ts = np.array([0.5, 4.5])
ax.plot(ts, distance(2) + rate * (ts - 2), color=colour, linestyle="--", label=f"2 to {2 + width} s: slope {rate:.1f}")
ts = np.array([0.5, 4.5])
ax.plot(ts, distance(2) + 8 * (ts - 2), color="#1f5fbf", linewidth=2, label="the limit: slope 8 (the tangent)")
ax.plot(2, distance(2), "o", color="black", markersize=8)
ax.set_xlim(0, 4.5)
ax.set_ylim(-5, 40)
ax.set_xlabel("Time (seconds)")
ax.set_ylabel("Distance (metres)")
ax.set_title("As the interval shrinks, the secant turns into the tangent")
ax.legend(loc="upper left")
plt.show()
As the second point slides towards the first, the secant line pivots and settles on a line that just touches the curve at t = 2: the tangent line. Its slope, 8 m/s, is the instantaneous rate of change: the car's speed at that exact moment. That's the derivative, the subject of the next lesson.
Where machine learning uses rates of change
- Training progress: the change in validation error per epoch tells you whether training is still improving or has levelled off; early stopping stops when that rate is about zero.
- Growth metrics: users gained per day, revenue per month and percentage change are all average rates of change; see percentage change.
- Numerical gradients: (f(x + h) − f(x)) ÷ h with a small h is an average rate of change over a tiny interval. It's used to check that hand-written gradients are correct; see numerical derivatives with Python.
Common mistakes
- Subtracting in different orders. (f(b) − f(a)) ÷ (b − a) and (f(a) − f(b)) ÷ (a − b) agree; (f(b) − f(a)) ÷ (a − b) gives the wrong sign.
- Forgetting the units. "12" means nothing; "12 metres per second" does.
- Treating an average rate as the rate everywhere. Over 2 to 4 seconds the average is 12 m/s, but the car was never steadily doing 12: it went from 8 to 16.
- Dividing by the wrong change. It's change in output divided by change in input, not the other way round.
Practice
- A plant was 12 cm tall on day 5 and 30 cm tall on day 11. What's its average growth rate, with units?
Show the answer
(30 − 12) ÷ (11 − 5) = 18 ÷ 6 = 3 cm per day.
- A model's validation error was 0.42 after epoch 10 and 0.39 after epoch 40. What's the average rate of change per epoch? Is it improving quickly?
Show the answer
(0.39 − 0.42) ÷ (40 − 10) = −0.03 ÷ 30 = −0.001 per epoch. Negative means the error is falling, so it's improving, but slowly: 0.001 per epoch.
- For f(x) = x³, find the average rate of change from 1 to 2, then from 1 to 1.001. What do you think the instantaneous rate at x = 1 is?
Show the answer
cube = lambda x: x ** 3
print(average_rate(cube, 1, 2), round(average_rate(cube, 1, 1.001), 4))
7.0 3.003
From 1 to 2 the average rate is 7. From 1 to 1.001 it's 3.003, heading towards 3. The instantaneous rate of change of x³ at x = 1 is 3.
- Why does a straight line have the same average rate of change over every interval, while a curve doesn't?
Show the answer
A straight line rises by the same amount for every unit of input, so every secant line through two of its points is the line itself, with the same slope. A curve bends, so secants through different pairs of points tilt by different amounts.
Key takeaways
- Average rate of change = (f(b) − f(a)) ÷ (b − a): change in output per unit change in input.
- Its units are "output units per input unit", and its sign says rising or falling.
- On a graph, it's the slope of the secant line through two points.
- For a straight line it's the same everywhere; for a curve it depends on the interval.
- Shrinking the interval turns the secant into the tangent, and the average rate into the instantaneous rate: the derivative.
Frequently asked questions
Is rate of change the same as slope?
For a straight line, yes. For a curve, the average rate of change between two points is the slope of the secant line, and the instantaneous rate of change at a point is the slope of the tangent line there.
What is the difference between average and instantaneous rate of change?
Average rate of change is measured over an interval, like the average speed for a trip. Instantaneous rate of change is at a single point, like a speedometer reading. The instantaneous rate is the limit of the average rate as the interval shrinks to zero.
How is rate of change used in data science?
Everywhere data changes over time or with another variable: growth per month, change in error per epoch, the effect of one more unit of a feature in a regression model. A linear regression coefficient is a rate of change: the change in the prediction for each one-unit increase in a feature.
What to learn next
- Turn the tangent into a tool in what is a derivative? Explained visually, the next lesson.
- Revisit straight lines in slope and intercept.
- See why shrinking intervals work in limits and continuity explained.