TL;DR
Often you know a quantity at two points and need its value somewhere between them. Linear interpolation assumes the quantity changes at a steady rate between the two points, so the answer lies on the straight line joining them. It turns a gap in a table or a set of measurements into a single, simple calculation.
Builds on: Linear Function · Leads to: Bilinear Interpolation, Super-Resolution
Where it's used
Recipe and unit conversion tables. A cookbook lists that 2 cups of flour weigh 300 grams and 3 cups weigh 420 grams. A baker with 2.5 cups needs an amount that the table does not list. Assuming flour weight grows steadily with volume, the answer lies halfway between the two entries, at 360 grams.
Sensor calibration. A temperature sensor outputs a voltage. A lab calibrates it so that 1.0 volt means 20 degrees Celsius and 2.0 volts means 52 degrees. The sensor is a function from voltage to temperature, but the calibration only tests a few voltages. A reading of 1.35 volts falls between two calibration points, and linear interpolation gives its temperature without re-running the calibration at every voltage.
Animation and graphics. A designer sets a box's position at frame 0 and frame 30. The software places the box for every frame in between by interpolating linearly, which is why a motion path from one point to another moves at a constant speed unless an easing curve is applied. Image resizing fills in the new pixels using the same idea in two directions; see Bilinear Interpolation.
How it works
Take two known points, and , and find the value at .
- Find the rate. Going from to , the output rises from 0 to 50. The rate is output units per input unit. Check: , so the rate reproduces the second point.
- Measure the distance from the start, then as a fraction. The point is 4 units past . As a share of the whole interval, that is , so the point is 4 tenths of the way across. Check: and .
- Scale the rate by that distance. units of rise from the starting value. Check: this is 40 percent of the total rise of 50, which matches the 4 tenths of the way across.
- Add the rise to the start. . So the interpolated value at is 20. Check: the line passes through and , and at it is at height 20.
The same steps work with any two points. Only the start, the end and the position in between change. The figure shows the sensor example from the list above, with the two calibration points and the interpolated reading.
- straight line through the two points
The math
Given two points and with , the linear interpolant at a point is the value on the straight line through the two points. The fraction measures how far along the interval lies, where at the start and at the end.
Step 1 in symbols: the rate
The rate of change between the two points is
In the example, .
Step 2 in symbols: the fraction
The distance from the start, as a share of the interval, is
In the example, .
Step 3 and 4 in symbols: the value
Combining the rate and the distance gives the interpolant
The two forms are equal. The second form is often nicer, because runs from 0 to 1 and the formula reads as "start plus a fraction of the change". In the example, .
Two checks confirm the formula. At we have and . At we have and . The formula reproduces both known points exactly, and the output changes steadily in between.
Worked examples
Interpolate between and at .
- The interval length is . The point is halfway, so .
- The change in output is .
- The share of the change is .
- Add to the start: .
- Check: the midpoint of 2 and 10 is 6, which agrees with the straight-line result.
The interpretation: when , linear interpolation gives the simple average of the two outputs.
Interpolate between and at cups.
- The interval length is .
- The fraction is .
- The change in grams is .
- The share of the change is .
- Add to the start: grams.
- Check: the rate is grams per cup, and half a cup is grams, so .
The interpretation: the answer is 360 grams, assuming flour weight grows steadily with volume. Real measurements may differ slightly, but the table only had two entries, so this is the best straight-line estimate.
A calibration gives and . A reading of 1.35 volts must be converted to a temperature.
- The interval length in volts is .
- The fraction is .
- The change in degrees is .
- The share of the change is .
- Add to the start: degrees Celsius.
- Check: the line has slope degrees per volt. From 1.0 volt, moving volts adds , which agrees with step 4.
The interpretation: the sensor reading corresponds to about 31.2 degrees. The calibration is only trustworthy between its two points; outside them the straight-line guess can be far off, as the common mistakes below explain.
Try it: the same sensor, now reading 1.8 volts. Find the temperature using the same six steps. Answer: , the share of the change is , and the temperature is degrees Celsius.
Common mistakes and tradeoffs
It is tempting to think that any two points can be joined to predict anything. In fact linear interpolation is reliable only between the points, where the data are known. Outside them it is extrapolation, and the true curve may bend away from the line. The sensor's behaviour at 3 volts is not known from two calibration points.
It is tempting to think that the straight line is always the right shape. In fact it is only right when the quantity really changes at a steady rate. Population growth and radioactive decay follow exponential curves, and a bending cable follows a curve too; a straight line between two samples can be badly wrong in the middle. The Derivative measures how fast a curve is changing at each point, and it is not constant. More points, or a curved model such as a Polynomial fit, fix this.
It is tempting to think that interpolation and regression are the same. In fact interpolation passes exactly through every given point, which is right when the data are exact, such as a published table. Linear regression fits a line through noisy data and does not pass through each point, which is right when the measurements contain error.
Linear interpolation is cheap, easy to check and exact at the known points. Use it for short gaps between dense data and for quick estimates. Do not use it for sparse data over a long range, or for data that curves strongly. Alternatives include higher-order polynomial interpolation, spline curves, a local approximation by a Taylor series near one point, and a finer table that makes the gaps small enough for a line to be accurate.
History
Table-making is much older than algebra. Babylonian astronomers kept numerical tables at regular intervals, and they filled in values between entries by taking a steady share of the difference between neighbours. That is linear interpolation in practice, long before anyone wrote the formula down.
Later mathematicians developed the method into general formulas. In the late seventeenth century Isaac Newton and James Gregory wrote down interpolation formulas for equally spaced data, which made the process systematic. The formula with the fraction became standard in numerical work as calculators and then computers needed fast ways to fill tables. It caught on because it is simple, reproduces the known data exactly, and is a good answer whenever the gap is small.
Recap
- Linear interpolation estimates a value between two known points by assuming a steady rate of change, as a Linear Function does, between them.
- The fraction says how far along the interval the point lies, from 0 at the start to 1 at the end.
- The value is the start plus times the total change; at the known points it returns the known values exactly.
- It is accurate for small gaps and steady change, and unreliable outside the known range or for strongly curved data.
Read next: Bilinear Interpolation, which applies the same idea in two directions to estimate pixel values, and Super-Resolution, which asks how to fill in detail that simple interpolation cannot recover.
Check yourself
QuestionWhat does the fraction mean in the formula ?Show answer
It means the point lies exactly at the start of the interval, , so the interpolated value is the starting value . At the point is at the end and the value is .
QuestionInterpolate between (0, 4) and (8, 12) at x = 6. What is the value?Show answer
The fraction is . The change is . The share of the change is . Add to the start: . Answer: 10.
QuestionWhy does linear interpolation give an exact answer at the two known points, but may be wrong between them?Show answer
At each known point the formula reduces to that point's value, because is 0 or 1 there. Between the points it assumes a straight-line change, and if the real quantity curves, the true value lies off the line. The known points are exact, the middle is an estimate.
QuestionA table lists a bridge's load limit at 10 tonnes and 14 tonnes. A truck of 12 tonnes is considered. A colleague says linear interpolation proves the bridge can carry it. What is the flaw?Show answer
Linear interpolation gives an estimate, not a proof, and the load limit is a safety value. The straight-line estimate assumes the limit changes steadily between the two entries, which an engineer cannot assume without a model of the bridge. The right response is to consult the rated limit or a structural analysis, not to rely on the interpolated figure.
Sources
- Linear interpolation, Wikipedia: https://en.wikipedia.org/wiki/Linear_interpolation
- Interpolation, Wikipedia: https://en.wikipedia.org/wiki/Interpolation