# Modelling with functions

> Math: Applications and Interpretation (IB Mathematics: Applications and Interpretation SL and HL) · Functions. A free chapter of Atlas, the interactive visual textbook: https://atlasclass.app/math-ai/ibmodels/. On the site each page sits beside an interactive 3D figure; here it is the words and the math (LaTeX) alone.

## Chapter 6 · Modelling with functions

*choosing, fitting and testing a model*

A cup of coffee at 90.6 °C cools in a 22 °C room, measured every 4 minutes. Which function describes it, and how well?

The shape suggests a model that falls quickly, then levels off just above room temperature: $T = 22 + 68e^{-kt}$. It has one free parameter, $k$. In the figure $k$ slides until the red curve passes as close as it can to the points: the red **residuals** (measured minus modelled) shrink, and the sum of their squares is least at $k \approx 0.05$.

That is what your calculator does when it fits a model. This chapter is the IB toolkit of models (linear, piecewise, quadratic, exponential, power, cubic and sinusoidal), how to read them with technology, the modelling cycle, and correlation. HL adds logistic models, logarithmic scales and $R^2$.

## 2.1 · IB Math AI · Lines, gradients and rates

*the gradient is a rate of change*

A taxi charges $5 for the first 2 km, then a fixed amount per kilometre. Two trips: 3 km costs $7.40 and 8 km costs $19.40.

$$m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{19.4 - 7.4}{8 - 3} = 2.4$$

In context the gradient is a **rate**, in dollars per kilometre: each extra kilometre adds $2.40. The point–gradient form $y - y_1 = m(x - x_1)$ gives $C - 7.4 = 2.4(d - 3)$, that is $C = 2.4d + 0.2$. The same line can be written $y = mx + c$ or $ax + by + d = 0$. Parallel lines share a gradient; perpendicular gradients multiply to $-1$.

The intercept, $0.20, means nothing here: the line only applies for $d \ge 2$. The whole fare is a **piecewise linear model** (2.5), and its two pieces meet at $d = 2$, where $2.4 \cdot 2 + 0.2 = 5$:

$$C(d) = \begin{cases} 5, & 0 2 \end{cases}$$

## 2.2 · IB Math AI · Functions, domain, range and inverse

*what goes in, what comes out, and back again*

A **function** gives each input exactly one output. $F = 1.8C + 32$ turns degrees Celsius into degrees Fahrenheit.

The **domain** is the set of inputs the model is used for, and context decides it. For liquid water at sea level, $0 \le C \le 100$, so the **range** is $32 \le F \le 212$: the red bars on the axes.

The **inverse** undoes the function. Swap the roles and solve: $C = \frac{F - 32}{1.8}$, written $f^{-1}(x) = \frac{x - 32}{1.8}$. So $f^{-1}(98.6) = 37$: body temperature. Every point $(a, b)$ on $f$ is a point $(b, a)$ on $f^{-1}$, so the blue graph is the red one reflected in $y = x$. The domain of $f^{-1}$ is the range of $f$, and $f^{-1}(f(x)) = x$.

The two graphs meet on the mirror, at $(-40, -40)$: −40 degrees is the same in both scales.

## 2.4 · IB Math AI · Graphs, zeros and intersections

*key features found with technology*

In this course you graph with a calculator and read the **key features** (2.3): intercepts, local maxima and minima, zeros, asymptotes and symmetry. Then you solve equations with the graph (2.4).

For $f(x) = x^3 - 6x^2 + 9x - 2$: the $y$-intercept is $-2$; there is a local maximum at $(1, 2)$ and a local minimum at $(3, -2)$; the zeros are $x \approx 0.268,\ 2,\ 3.732$.

To solve $x^3 - 6x^2 + 9x - 2 = 0.5x$, graph both sides and find where they **intersect**: $x \approx 0.293,\ 1.707,\ 4$. The same method solves equations algebra can’t, such as $2^x = x + 3$: $x \approx -2.863$ or $x \approx 2.445$.

In an exam, **sketch** means show the shape and the key features labelled; **draw** means accurately, to scale. Give answers to 3 significant figures unless told otherwise.

## 2.5 · IB Math AI · Quadratic models

*up and back down*

A ball is thrown up at 14 m/s from 1.5 m above the ground. Its height after $t$ seconds is modelled by

$$h(t) = 1.5 + 14t - 4.9t^2$$

A **quadratic model** $f(x) = ax^2 + bx + c$ has an axis of symmetry $x = -\frac{b}{2a}$. Here $a = -4.9 , so the parabola opens down and the vertex is a maximum: at $t = \frac{14}{9.8} \approx 1.43$ s the ball is 11.5 m up.

The ball lands at the positive zero, $t \approx 2.96$ s (from the calculator, or the quadratic formula). So in context the domain is $0 \le t \le 2.96$ and the range $0 \le h \le 11.5$: the other zero, below $t = 0$, means nothing.

The blue ball on the axis is the real motion, straight up and down; the graph spreads it out in time. Given data instead of a formula, quadratic regression on the calculator finds $a$, $b$ and $c$.

## 2.5 · IB Math AI · Exponential models

*growth and decay by a constant factor*

Exponential models multiply by the same factor in each equal time step: $f(x) = ka^x + c$, or with base $e$, $f(x) = ke^{rx} + c$. The line $y = c$ is a horizontal asymptote.

A bacteria colony: $N = 100e^{0.2t}$, $t$ in hours. Each hour it is multiplied by $e^{0.2} \approx 1.2214$: 22.1% growth per hour. It doubles when $e^{0.2t} = 2$, every $\frac{\ln 2}{0.2} \approx 3.47$ hours.

A drug in the blood: $D = 800e^{-0.2t}$ mg. A negative exponent is **decay**, with a **half-life** of the same 3.47 hours: 800, 400, 200, 100 mg.

The two curves cross where $100e^{0.2t} = 800e^{-0.2t}$, at $t = \frac{\ln 8}{0.4} \approx 5.2$ h. Here $c = 0$; the opener’s coffee has $c = 22$, the room it cools toward.

## 2.5 · IB Math AI · Power, variation and cubic models

*y = axⁿ, and a box to fold*

In $y = ax^n$, $y$ **varies directly** with $x^n$ when $n > 0$, and **inversely** when $n . Every such curve passes through $(1, a)$.

Inverse variation: the time for a 240 km trip is $t = \frac{240}{v} = 240v^{-1}$; double the speed and the time halves. Direct variation: a dropped stone falls $d = 4.9t^2$ metres, so in twice the time it falls four times as far. Given one data point you find $a$; given $n$ too, you have the model.

A **cubic model** $f(x) = ax^3 + bx^2 + cx + d$ comes from multiplying three lengths. Cut squares of side $x$ from the corners of a 30 cm by 20 cm card and fold up the sides:

$$V = x(30 - 2x)(20 - 2x)$$

The calculator’s maximum: $x \approx 3.92$ cm gives the largest box, $V \approx 1056$ cm³. The domain is $0 : at 10 cm the shorter side is used up.

## 2.5 · IB Math AI · Sinusoidal models

*what goes round comes round*

A Ferris wheel of radius 18 m turns once every 30 minutes, its centre 20 m up. You board at the bottom. Your height after $t$ minutes is a **sinusoidal model** (angles in degrees):

$$h(t) = -18\cos(12t) + 20$$

In $f(x) = a\sin(bx) + d$ or $a\cos(bx) + d$: the **amplitude** is $|a|$ (18 m, centre to top), the **period** is $\frac{360^\circ}{b}$ (so $b = \frac{360}{30} = 12$), and the **principal axis** is $y = d$, halfway between the maximum 38 m and the minimum 2 m. A negative $a$ starts the cosine at its lowest point.

When are you above 30 m? Graph $y = 30$ too and intersect: from $t \approx 10.31$ to $t \approx 19.69$ min, about 9.4 minutes of each turn. Tides, daylight hours and temperatures through a year are modelled the same way.

## 2.6 · IB Math AI · The modelling cycle

*choose, fit, test, reflect*

Modelling is a cycle: pose the problem, choose a model, fit it to data, test it, reflect, and improve it.

A sunflower is measured for 8 weeks. The points lie close to a line ($r \approx 0.995$), so a linear model is a reasonable first choice: $h = 24.52w - 4.02$. The gradient says it grows about 24.5 cm a week.

Test it: the model predicts $h(14) \approx 339$ cm in week 14. The real sunflower is 253.3 cm. The prediction was an **extrapolation**, beyond the data, and the context breaks it: sunflowers stop growing.

Reflect: a good model fits the data, makes sense in context (no negative heights, no endless growth), and states its limits. Here the fix is a model with a ceiling: the logistic model on the HL page. A model is judged by its use, not by being true.

## 4.4 · IB Math AI · Correlation and the regression line

*Pearson’s r, and predicting y from x*

Ten students’ hours of revision $x$ and test scores $y$. **Pearson’s product-moment correlation coefficient** $r$ measures how close the points lie to a straight line: $-1 \le r \le 1$.

Here $r \approx 0.967$: a strong positive linear correlation. Near $\pm 1$ is strong, near 0 is little linear correlation. Correlation is not causation: a third factor can drive both.

The **regression line of $y$ on $x$** minimises the squared vertical residuals:

$$\hat{y} = 38.05 + 4.98x$$

It passes through the mean point $(\bar{x}, \bar{y}) = (4.25, 59.2)$, and its gradient means about 5 more marks per extra hour. Use it only to predict $y$ from $x$.

Predicting inside the data’s range is **interpolation**: 5.5 hours gives $\hat{y} \approx 65.4$. Outside it is **extrapolation**, and unreliable: 15 hours “predicts” 112.7 out of 100.

## 4.10 · IB Math AI · Spearman’s rank correlation

*does one go up when the other does?*

Shares of a post on each of its first 8 days: 6, 4, 9, 14, 25, 46, 88, 170. They rise faster and faster, so they are far from a line: $r \approx 0.854$.

**Spearman’s rank correlation coefficient** $r_s$ replaces each value by its rank (1 for the smallest) and finds Pearson’s $r$ for the ranks. In the figure the points walk to their ranks. Only days 1 and 2 disagree: day 1 had more shares. With no tied ranks,

$$r_s = 1 - \frac{6\sum d^2}{n(n^2 - 1)} = 1 - \frac{6 \cdot 2}{8 \cdot 63} \approx 0.976$$

where $d$ is the difference in ranks. $r_s = 1$ means the order agrees perfectly: whenever one increases, so does the other.

Prefer $r_s$ when the relationship is **monotonic but not linear** (as here), when there are outliers (ranks blunt them), or when the data are ranks already, such as two judges’ placings. Use Pearson’s $r$ for straight-line relationships, and before fitting a regression line.

## 2.9 · AI HL · Logistic models

*growth with a ceiling*

The sunflower needs a model that grows like an exponential at first and then levels off. That is the **logistic model**:

$$f(x) = \frac{L}{1 + Ce^{-kx}}, \qquad L, C, k > 0$$

$L$ is the **carrying capacity**, the horizontal asymptote. For the sunflower $L = 260$, $C = 12$, $k = 0.45$: it starts at $\frac{260}{1 + 12} = 20$ cm and grows fastest at half the ceiling, 130 cm, when $t = \frac{\ln 12}{0.45} \approx 5.52$ weeks.

Early on, $Ce^{-kx}$ is large and the model is close to the exponential $20e^{0.45t}$. By week 14 they part completely: the logistic gives 254.4 cm (the sunflower: 253.3 cm); the exponential, 10,891 cm.

HL also uses **natural logarithmic** models $f(x) = a + b\ln x$, sinusoidal models with a horizontal shift, $a\sin(b(x - c)) + d$, and **piecewise** models built from any of these, joined where the context changes.

## 2.10 · AI HL · Straightening curves with logarithms

*log–log and semi-log graphs*

Planets’ distances from the Sun $a$ (in AU) and years $T$ span two orders of magnitude. On ordinary axes Mercury, Venus, Earth and Mars crowd into a corner. Logarithms spread them out.

If $y = kx^n$, take logs of both sides:

$$\ln y = n\ln x + \ln k$$

a straight line on a **log–log graph** of $\ln y$ against $\ln x$, with gradient $n$ and intercept $\ln k$. For the planets the line has gradient $n \approx 1.5$ and intercept $\ln k \approx 0.0003$, so $k \approx 1$ and $T = a^{1.5}$: Kepler’s third law, $T^2 = a^3$.

If $y = ka^x$, then $\ln y = x\ln a + \ln k$: straight on a **semi-log graph** of $\ln y$ against $x$, gradient $\ln a$. So: plot the logs, and whichever graph is straight tells you the kind of model; its gradient and intercept give the parameters.

## 4.13 · AI HL · Non-linear regression and R²

*how much of the variation a model explains*

A test car’s stopping distance at 11 speeds. Which model fits: linear, quadratic or exponential? The calculator fits each by least squares and reports the **coefficient of determination**:

$$R^2 = 1 - \frac{SS_{\text{res}}}{SS_{\text{tot}}} = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}$$

the proportion of the variation in $y$ that the model explains. For a linear model $R^2 = r^2$.

Here: linear $R^2 \approx 0.97$, quadratic 0.998, exponential 0.902. Watch the residuals in the figure: the line misses in a pattern (above, below, above), the quadratic’s are small and random.

The quadratic, $d = 0.00695v^2 + 0.173v + 0.38$, also makes sense: thinking distance grows like $v$, braking distance like $v^2$. Choose by context and residuals as well as $R^2$: adding parameters never lowers $R^2$, so the highest is not always the best model.

---

Read it with the figures, and practice it graded as you go: https://atlasclass.app/math-ai/ibmodels/
