Back to the blog

Linear functions · 8 min read

Linear functions: the straight line y = ax + b

What a and b do in y = ax + b, and how to find the line through two points.

Say a taxi charges 20 SRD to get in. After that you pay 5 SRD per kilometre. A ride of 7 km then costs 20 + 5 × 7 = 55 SRD. Every extra kilometre costs exactly 5 SRD more. Plot the price against the distance and you get a straight line.

A formula that gives a straight line is called a linear function. In this article you see what the numbers in such a formula do. Then you set up a formula like that yourself.

Two numbers: a and b

You can write every linear function like this:

y = ax + b

  • b is the y-intercept. Fill in x = 0: then y = a × 0 + b = b. So the line goes through (0, b).
  • a is the slope. It tells you how steep the line is. Take 1 step to the right and you go a steps up.

Slide a and b below. The graph starts at y = 2x − 1. The dashed step starts at (0, b): 1 step across, then a steps up.

Slide a and b

y = 2x − 1

  • Graph
  • 1 across, a up
  • y-intercept
−6−4−20246−6−4−20246xy1a = 2
Slope
a = 2
y-intercept
(0, −1)
The line
rises
Tap or move over the graph to read off a point.
Show the numbers
xy
−3−7
−2−5
−1−3
0−1
11
23
35

This is what you see:

  • If a is positive, the line rises from left to right.
  • If a is negative, the line falls. One step to the right then takes you down.
  • If a = 0, the line is flat. The formula is then y = b.
  • The further a is from 0, the steeper the line.
  • b does not change the slope. b moves the whole line up or down.

From a table to a line

For y = 2x − 1 you make a table. Pick a few values for x and work out y:

x = 0: y = 2 × 0 − 1 = −1
x = 1: y = 2 × 1 − 1 = 1
x = 2: y = 2 × 2 − 1 = 3

Plot the points (0, −1), (1, 1) and (2, 3) and draw a line through them. Two points are enough for a straight line. The third point is a check. If it is not on the line, there is a mistake somewhere.

Now look at the y-values: −1, 1 and 3. Each time 2 is added. That is no accident. When x goes up by 1, y goes up by exactly a. On a straight line that step is always the same size.

It works the other way round too. This is how you find the formula for a table:

  • The step in y, when x goes up by 1 each time, is a.
  • The y at x = 0 is b.

Pick a table below and look at the row of steps.

Equal steps give a straight line
  • Line
  • Points from the table
012345−20246810xy
x
y−11357
step+2+2+2+2

The same step every time, so a straight line: y = 2x − 1

Tap an x to find its point.

Table A has step +2 every time, and x = 0 goes with y = −1. That gives y = 2x − 1. Table B has step −0.5 every time and starts at 3. That gives y = −0.5x + 3. Table C has the steps −1, +1, +3 and +5. Those steps are not equal. The points lie on a curve, not on a line.

The line through two points

A test often asks this: give the formula of the line through A(1, 4) and B(3, 10). That takes two steps.

Step 1: work out a. See how far you go across and how far up. Across is called Δx and up is called Δy. You say delta x and delta y.

Δx = 3 − 1 = 2
Δy = 10 − 4 = 6
a = Δy ÷ Δx = 6 ÷ 2 = 3

Step 2: work out b. Fill in a and one point in y = ax + b. Take A(1, 4):

4 = 3 × 1 + b
4 = 3 + b
b = 1

The formula is y = 3x + 1. Check with the other point: 3 × 3 + 1 = 10. That is right.

Drag A and B below to other places. The formula follows.

Drag the two points

y = 3x + 1

  • Line through A and B
  • Δx across, Δy up
−4−20246−404812xyΔx = 2Δy = 6AB
A
(1, 4)
B
(3, 10)
Δx
3 − 1 = 2
Δy
10 − 4 = 6
Slope
a = 6 ÷ 2 = 3
y-intercept
b = 4 − 3 × 1 = 1
Drag A or B. Or pick a point with Tab and use the arrow keys.

A falling line works the same way. Take A(−1, 5) and B(2, −1):

Δx = 2 − (−1) = 3
Δy = −1 − 5 = −6
a = −6 ÷ 3 = −2

Fill in A: 5 = −2 × (−1) + b. Then 5 = 2 + b, so b = 3. The formula is y = −2x + 3. The line falls, so a is negative.

A formula from a story

Back to the taxi. You pay 20 SRD to get in and 5 SRD per km. Call the distance x, in km. Call the price y, in SRD:

y = 5x + 20

The fixed amount at the start is b = 20. The amount per kilometre is a = 5. This works for every story with a fixed start and a fixed step. The starting amount is b. What is added per step is a.

The price of a taxi ride
  • Price of the ride
  • Getting in: 20 SRD
024681012020406080100Distance (km)Price (SRD)Getting in: 20 SRD
Price
20 + 5 × 7 = 55 SRD
Slide the distance. The dotted lines read off the price.
Show the numbers
DistancePrice
0 km20 SRD
2 km30 SRD
4 km40 SRD
6 km50 SRD
8 km60 SRD
10 km70 SRD
12 km80 SRD

It works the other way round too. Say you have 60 SRD. Then you solve this equation:

5x + 20 = 60
5x = 40
x = 8

You get 8 km. Set the slider to 8 km to check.

Where two lines cross

Taxi B charges 8 SRD to get in and 7 SRD per km. That gives y = 7x + 8. Taxi B is cheaper to get in, but more expensive per kilometre. At one distance they cost the same. That is where the two lines cross.

Set the two formulas equal to each other:

5x + 20 = 7x + 8
20 − 8 = 7x − 5x
12 = 2x
x = 6

At 6 km both cost 5 × 6 + 20 = 50 SRD. The point where they cross is (6, 50). For shorter rides taxi B is cheaper. For longer rides taxi A is cheaper.

Change the prices of taxi B below.

Taxi A against taxi B
  • Taxi A: y = 5x + 20
  • Taxi B: y = 7x + 8
  • Crossing point
024681012020406080100120Distance (km)Price (SRD)AB
Equation
5x + 20 = 7x + 8
Crossing point
(6, 50)

Up to 6 km, Taxi B is cheaper. After that, Taxi A is cheaper.

Tap or move over the graph to see both prices.
Show the numbers
Distance (km)Taxi ATaxi B
020 SRD8 SRD
230 SRD22 SRD
440 SRD36 SRD
650 SRD50 SRD
860 SRD64 SRD
1070 SRD78 SRD
1280 SRD92 SRD

Set taxi B to 5 SRD per km. Then both lines have the same a. They are parallel and never cross. You can see that in the equation too. Take a starting price of 8 SRD:

5x + 20 = 5x + 8
20 = 8

That is impossible. There is no solution, so there is no crossing point either.

Lines that are perpendicular to each other follow a fixed rule too. Multiply the two slopes and you get −1. Take y = 2x + 1 and y = −0.5x + 4. Then 2 × (−0.5) = −1. These two lines are perpendicular.

Try it yourself

Give the formula of the line through (2, 1) and (6, 3).

See the answer

Δx = 6 − 2 = 4 and Δy = 3 − 1 = 2. Then a = 2 ÷ 4 = 0.5. Fill in (2, 1): 1 = 0.5 × 2 + b, so b = 0. The formula is y = 0.5x.

A table: x = 0, 1, 2 and 3 go with y = 7, 4, 1 and −2. Give the formula.

See the answer

The step in y is −3 every time, so a = −3. At x = 0, y = 7, so b = 7. The formula is y = −3x + 7.

Where do y = 2x + 1 and y = −x + 7 cross?

See the answer

2x + 1 = −x + 7, so 3x = 6 and x = 2. Then y = 2 × 2 + 1 = 5. They cross at (2, 5). Check with the second line: −2 + 7 = 5.

Read next

  • Powers and roots

    Powers and roots: the rules

    What a power is, the four rules, negative exponents and how to simplify √72. With figures you can slide and count.

  • Solving equations

    Solving equations: balance and graph

    Solve equations with the balance method, through brackets and fractions, with two crossing lines and with x², from factorising to the quadratic formula.

  • Pythagoras' theorem

    Pythagoras in the plane and in space

    Why a² + b² = c² is true, how to work out a side, how to check for a right angle, and how to find distances and space diagonals.