Linear interpolation
Linear interpolation estimates an unknown value between two known points by assuming they are joined by a straight line. If you know the points (x₁, y₁) and (x₂, y₂), the value of y at any x between them is y = y₁ + (x − x₁)(y₂ − y₁) ÷ (x₂ − x₁). For example, if a tank holds 5 litres after 2 minutes and 13 litres after 6 minutes, linear interpolation estimates 8 litres after 3.5 minutes. In A-level statistics, it is how you estimate the median and percentiles from grouped data.
The linear interpolation formula
| Symbol | Meaning |
|---|---|
| (x₁, y₁) | The known point just below the value you want |
| (x₂, y₂) | The known point just above it |
| x | The value you know, between x₁ and x₂ |
| y | The estimate you want |
The fraction (y₂ − y₁) ÷ (x₂ − x₁) is the gradient of the straight line between the two points. So the formula says: start at y₁, then go up by the gradient for every unit you move along from x₁. That is just the equation of a straight line through two points.
The same formula as a fraction of the way
Another way to see it: work out how far along the gap you are, as a fraction, then go the same fraction of the way up.
If x is a quarter of the way from x₁ to x₂, then y is a quarter of the way from y₁ to y₂. This is the form programmers call lerp, short for linear interpolation: lerp(a, b, t) = a + t(b − a), where t runs from 0 at a to 1 at b. With a = 40, b = 100 and t = 0.25, lerp gives 40 + 0.25 × 60 = 55.
How to do linear interpolation
- Find the two known values either side of the one you want: (x₁, y₁) below and (x₂, y₂) above.
- Work out the fraction of the way along: (x − x₁) ÷ (x₂ − x₁).
- Multiply that fraction by the gap in y, y₂ − y₁.
- Add the result to y₁.
- Check the answer lies between y₁ and y₂. If it does not, something has gone wrong.
Linear interpolation examples
Example 1: between two points
Estimate y at x = 3.5, given the points (2, 5) and (6, 13).
The gradient is 2, and x is 1.5 along from 2, so y rises by 3 from 5 to 8. This is the point P in the diagram.
Example 2: reading between values in a table
A weather station records 12 °C at 10:00 and 18 °C at 13:00. Estimate the temperature at 11:30.
11:30 is 1.5 hours into a 3-hour gap, which is halfway, so the temperature is halfway from 12 to 18:
Example 3: working backwards
Using the same readings, estimate when the temperature reached 16 °C.
This time you know y and want x, so swap the roles. 16 °C is 4 of the 6 degrees from 12 to 18, which is ⅔ of the way:
So the temperature reached 16 °C at about 12:00. This is sometimes called inverse interpolation.
Linear interpolation for grouped data
In A-level Maths, the most common use is estimating the median, quartiles and percentiles from a grouped frequency table. You cannot find the exact median when the data is grouped, because you do not know the individual values. So you assume the values in each class are spread evenly across it, and interpolate. Pearson Edexcel's A-level Maths specification says that use of linear interpolation to calculate percentiles from grouped data is expected.
Here are the times, in minutes, that 60 people took to finish a puzzle.
| Time, t (minutes) | Frequency | Cumulative frequency |
|---|---|---|
| 0 ≤ t < 10 | 6 | 6 |
| 10 ≤ t < 20 | 16 | 22 |
| 20 ≤ t < 30 | 16 | 38 |
| 30 ≤ t < 40 | 14 | 52 |
| 40 ≤ t < 60 | 8 | 60 |
Example 4: the median
With n = 60, the median is the n ÷ 2 = 30th value. The cumulative frequency passes 30 in the class 20 ≤ t < 30: 22 values come before it, so the median is the 30 − 22 = 8th of the 16 values in that class.
In words: lower class boundary + (how far into the class ÷ class frequency) × class width. It is the interpolation formula again, with cumulative frequency playing the part of x.
Example 5: quartiles and a percentile
The lower quartile is the 60 ÷ 4 = 15th value, in the class 10 ≤ t < 20, with 6 values before it:
The upper quartile is the 45th value, in 30 ≤ t < 40, with 38 before it: Q₃ = 30 + (7 ÷ 14) × 10 = 35 minutes. So the interquartile range is about 35 − 15.6 = 19.4 minutes.
The 90th percentile is the 0.9 × 60 = 54th value, in the class 40 ≤ t < 60. That class is 20 minutes wide, so: P₉₀ = 40 + (2 ÷ 8) × 20 = 45 minutes. Watch the class width when classes are unequal.
The Mean, Median and Mode Calculator takes grouped data, interpolates the median and quartiles inside their classes, and shows each step, so you can check tables like this one.
Mean, Median and Mode Calculator
Find averages, range and quartiles from raw or grouped data
Here is a quick check.
How accurate is linear interpolation?
It is exact when the data really does follow a straight line, and only an estimate when it does not. The graph shows y = x², with x on the horizontal axis.
The straight line through (1, 1) and (3, 9) gives y = 1 + 1 × 4 = 5 at x = 2, but the true value on the curve is 4. Because the curve bends upwards, the straight line sits above it and interpolation overestimates. The closer together the two known points, the smaller this error, which is why tables with small steps give better interpolated values.
Interpolation and extrapolation
Interpolation estimates a value inside the range of your data. Extrapolation estimates one outside it, by extending the line beyond the last point. Interpolation is usually reliable, because you are between values you have measured. Extrapolation is risky, because there is no evidence the trend carries on. A child who grew 6 cm a year from age 4 to 10 will not keep growing 6 cm a year until age 40.
AQA's GCSE Maths specification asks students to make predictions from scatter graphs and to interpolate and extrapolate apparent trends whilst knowing the dangers of so doing. Pearson Edexcel's A-level specification lists the use of interpolation and the dangers of extrapolation alongside regression lines.
Common mistakes
- Using the wrong pair of points. Use the known values immediately either side of the one you want.
- Mixing up x and y. When working backwards, the fraction comes from the y values and is applied to the x gap.
- Using the class midpoint for the median. Interpolate from the lower class boundary, not the midpoint.
- Forgetting unequal class widths. Multiply by the width of the class the value is in.
- Using (n + 1) ÷ 2 for grouped data. For grouped data, use n ÷ 2 for the median and n ÷ 4 for the lower quartile.
- Trusting an extrapolated value as if it were interpolated.
Linear interpolation questions with answers
1. Estimate y at x = 7, given the points (4, 10) and (10, 22).
y = 10 + (7 − 4) × 2 = 16
2. A plant is 14 cm tall on day 5 and 26 cm tall on day 9. Estimate its height on day 6.
14 + ¼ × 12 = 17 cm
3. Using the same plant, estimate the day it reached 23 cm.
5 + ¾ × 4 = day 8
4. A class 15 ≤ x < 25 has frequency 12, and 30 values come before it. Estimate the 33rd value.
5. Why is an estimated median from grouped data only an estimate?
Practise statistics in a short timed paper
A-level Maths: Statistics and GCSE Maths Higher each give you a short timed paper every day, with 8 questions worth 25 to 35 marks across the course, so grouped data and interpolation turn up regularly but not in every paper.
A-level Maths: Statistics
Start today's paperGCSE Maths Higher
Start today's paperPapers reset in
Common questions
What is linear interpolation in simple terms?
What is the formula for linear interpolation?
What is the difference between interpolation and extrapolation?
How do you find the median of grouped data using linear interpolation?
Is linear interpolation accurate?
What is lerp?
Revision cards
Say the answer first, then flip the card to check it.
Where to go next
- Solve it
Mean, Median and Mode Calculator
Find averages, range and quartiles from raw or grouped data
Open the tool - Test it
A-level Maths: Statistics
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper - Test it
GCSE Maths Higher
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper