Int 3 for Programmers

Functions, transformations, composition and inverses

6 / 396
Contents

Contents

Int 3 for Programmers

0 of 396 complete

9 min read

How fast it changed, on average

The slope between two points on a curve, what it measures, and what its units are.

A car goes 120 kilometres in two hours. Nobody claims it held 60 kilometres per hour the whole way; the number is the average, and it is worked out from the two ends of the journey alone. Functions get the same treatment.

Take a rule, pick two inputs, and divide the change in output by the change in input. Run it over several intervals of the same function.

Try CodePython

Change the rule to 3 * x + 5 and run it again. Every interval now reports the same number. Which number, and where is it in the rule?

For x2x^2 the four answers are 1, 3, 5 and 7. The function is getting steeper as you move right, and a single number cannot describe the whole curve. For 3x+53x + 5 every interval gives 3, because a straight line has the same steepness everywhere.

That quantity has a name and a formula. The average rate of change of ff over the interval from aa to bb is the change in output divided by the change in input.

average rate of change=f(b)−f(a)b−a\text{average rate of change} = \frac{f(b) - f(a)}{b - a}
Output change on the top, input change on the bottom, and always in that order.

Geometrically this is the slope of the straight line drawn through the two points (a,f(a))(a, f(a)) and (b,f(b))(b, f(b)). That line is called a secant line, from the Latin for cutting, because it cuts the curve at two places.

It is the same formula you already use for the slope of a line, y2−y1x2−x1\frac{y_2 - y_1}{x_2 - x_1}, with the two points taken off the curve. That is why a linear function gives the same answer over every interval: there the secant line and the function are the same line.

The order of the two endpoints does not matter, as long as you keep it consistent. Swapping aa and bb flips the sign of the top and of the bottom at once, and the two flips cancel. Swapping only one of them is an error, and it produces an answer with the wrong sign.

The secant slope on a parabola
f(b)−f(a)b−a  =  (2)2−(−1)2(2)−(−1)\frac{f(b) - f(a)}{b - a} \;=\; \frac{(2)^2 - (-1)^2}{(2) - (-1)}
-20.753.56.259-3-1.501.53
secant line
Average rate of change
1

Drag a and b together. The dashed line is the average, and the reported number is its slope. Notice the answer is always a+ba + b for this curve.

One worked example in full. Find the average rate of change of f(x)=x2−4xf(x) = x^2 - 4x from x=1x = 1 to x=5x = 5.

  1. Work out the output at each end: f(1)=1−4=−3f(1) = 1 - 4 = -3.
  2. And the other: f(5)=25−20=5f(5) = 25 - 20 = 5.
  3. Change in output: 5−(−3)=85 - (-3) = 8.
  4. Change in input: 5−1=45 - 1 = 4.
  5. Divide: 84=2\frac{8}{4} = 2.

So on average the output rose 2 units for every 1 unit of input across that stretch. Note that the function actually falls at first and rises later; the average hides that entirely, which is exactly what an average does.

Units, and what the number means

In a modelling question the answer needs units, and they come straight from the formula: the units of the output divided by the units of the input. If P(t)P(t) is a population in people and tt is in years, the average rate of change is in people per year.

Try CodePython

Change the reading at day 21 from 24 to 40 and run it again. Which week now has the fastest growth?

The three weeks give 1, about 1.43 and about 0.43 centimetres per day. A negative answer would mean the quantity fell over that stretch, and zero would mean it ended where it started, whatever it did in between.

The average rate of change of some function from x=2x = 2 to x=6x = 6 is 0. Does that mean the function is constant on that stretch?

No. It means only that f(6)=f(2)f(6) = f(2), so it ended at the same height it started. It could have climbed and come back down, which is what f(x)=−(x−4)2f(x) = -(x-4)^2 does here: f(2)=−4f(2) = -4 and f(6)=−4f(6) = -4, with a peak of 0 in the middle.

Check yourself

For f(x)=5−2xf(x) = 5 - 2x, what is the average rate of change from x=−3x = -3 to x=40x = 40?

All lessons in Int 3 for Programmers