Skip to main content
Back to module
Math for Tech & STEM · Functions and Graphs

Linear relationships and slope

Reading32mLesson 2 of 3 in this module

What you'll learn

  • Find slope and intercept from data
  • Calculate slope as rise over run from two points
  • Interpret slope and intercept in context, with units
  • Recognise a linear table by its constant differences, and extrapolate with caution

Find the slope and intercept of a line from two points or a data table, and interpret them.

Why this matters

Linear relationships are the workhorse model of science and engineering. Cost grows by a fixed amount per unit, a spring stretches a fixed amount per newton, and a sensor's output rises a fixed number of millivolts per degree. When a relationship is linear, two numbers describe it completely: the slope (how fast it changes) and the intercept (where it starts).

The core idea: y = mx + b

A linear function has the form

y = mx + b

  • m, the slope, is the change in y for each 1-unit increase in x.
  • b, the y-intercept, is the value of y when x = 0.

The graph is a straight line. A positive slope rises left to right, a negative slope falls, and a slope of 0 is flat.

Finding slope from two points

Slope is "rise over run":

m = (y₂ − y₁) / (x₂ − x₁)

For the points (1, 10) and (3, 4):

m = (4 − 10) / (3 − 1) = −6 / 2 = −3

y falls by 3 for every 1 step in x. The order of the points does not matter as long as you are consistent: (10 − 4) / (1 − 3) = 6 / −2 = −3 as well.

Finding the intercept

Once you have m, substitute either point into y = mx + b and solve for b:

b = y₁ − m × x₁ = 10 − (−3)(1) = 13

So the line is y = −3x + 13. Check the other point: −3(3) + 13 = 4. Correct.

Worked example 1: a data table

A delivery company records cost against distance:

distance (km)cost ($)
04.00
57.50
1011.00
1514.50

Each 5 km adds $3.50, a constant change, so the relationship is linear.

  • Slope: 3.50 / 5 = $0.70 per km
  • Intercept: at 0 km the cost is $4.00 (a fixed booking fee)
  • Model: cost = 0.70 × distance + 4.00

Predict a 22 km trip: 0.70 × 22 + 4.00 = $19.40.

The units of the slope are "y units per x unit", here dollars per kilometre. Stating units turns a number into an interpretation.

Worked example 2: is it linear?

x0123
y13713

The differences are 2, 4, 6. They are not constant, so this is not linear. A constant difference for equal steps in x is the quick test.

Real data is noisy

Measured data rarely sits exactly on a line. Engineers fit a line of best fit (usually by least squares, which you will meet in statistics) that passes as close as possible to all points. The slope and intercept of that line are read the same way. Python's standard library can fit one:

Python
import statistics

distance = [0, 5, 10, 15]
cost = [4.0, 7.5, 11.0, 14.5]
fit = statistics.linear_regression(distance, cost)
print(fit.slope, fit.intercept)   # 0.7 4.0 (up to rounding)

Interpolation and extrapolation

Using the line between measured points (interpolation) is usually safe. Using it far beyond your data (extrapolation) is risky: a delivery price may jump for long distances, and a spring stops being linear when it is overstretched.

Common mistakes

  • Mixing the order of points: (y₂ − y₁) / (x₁ − x₂) gives the wrong sign.
  • Putting x-change on top. Slope is change in y over change in x.
  • Reading b as the first table value when the table does not start at x = 0.
  • Dropping units on the slope, so it cannot be interpreted.
  • Extrapolating too far beyond the data.

Quick recap

  • y = mx + b: m is the rate of change, b is the value at x = 0.
  • m = (y₂ − y₁) / (x₂ − x₁); then b = y₁ − m × x₁.
  • Equal steps in x with equal changes in y means linear.
  • Give slopes units, and be cautious outside your data.

Try it

In the Do tab, write the slope formula. The intercept and prediction functions are already built on top of it.

Key terms (5)

slope
In y = mx + b, m: the change in y for each 1-unit increase in x, in y units per x unit.
y-intercept
In y = mx + b, b: the value of y when x = 0.
line of best fit
A line through noisy data that passes as close as possible to all the points.
interpolation
Using a line to estimate values between measured points, which is usually safe.
extrapolation
Using a line to predict far beyond the measured data, which is risky.

Recap

  • In y = mx + b, m is the rate of change and b is the value at x = 0
  • Slope m = (y₂ − y₁) / (x₂ − x₁); then b = y₁ − m × x₁
  • Equal steps in x with equal changes in y means the relationship is linear
  • Give slopes units, and be cautious outside your data
Also in this lesson: