Search

Search papers and lessons

Linear Interpolation

Level 1 · 10 min read

Linear interpolation estimates a value between two known points by placing it on the straight line joining them, in proportion to how far along the interval it lies.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • ReadReady to readNot yet

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, (0,0)(0, 0) and (10,50)(10, 50), and find the value at x=4x = 4.

  1. Find the rate. Going from x=0x = 0 to x=10x = 10, the output rises from 0 to 50. The rate is 50/10=550 / 10 = 5 output units per input unit. Check: 0+5×10=500 + 5 \times 10 = 50, so the rate reproduces the second point.
  2. Measure the distance from the start, then as a fraction. The point x=4x = 4 is 4 units past x=0x = 0. As a share of the whole interval, that is 4/10=0.44 / 10 = 0.4, so the point is 4 tenths of the way across. Check: 10−0=1010 - 0 = 10 and 4−0=44 - 0 = 4.
  3. Scale the rate by that distance. 5×4=205 \times 4 = 20 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.
  4. Add the rise to the start. 0+20=200 + 20 = 20. So the interpolated value at x=4x = 4 is 20. Check: the line passes through (0,0)(0, 0) and (10,50)(10, 50), and at x=4x = 4 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.

0.511.522.50204060voltage (V)temperature (C)
  • straight line through the two points
The two calibration points define a straight line. The reading at 1.35 V lies on that line, at 31.2 degrees.

The math

Definition: Linear interpolation

Given two points (x0,y0)(x_0, y_0) and (x1,y1)(x_1, y_1) with x0≠x1x_0 \neq x_1, the linear interpolant at a point xx is the value on the straight line through the two points. The fraction t=(x−x0)/(x1−x0)t = (x - x_0) / (x_1 - x_0) measures how far along the interval xx lies, where t=0t = 0 at the start and t=1t = 1 at the end.

Step 1 in symbols: the rate

The rate of change between the two points is

m=y1−y0x1−x0.m = \frac{y_1 - y_0}{x_1 - x_0}.

In the example, m=(50−0)/(10−0)=5m = (50 - 0) / (10 - 0) = 5.

Step 2 in symbols: the fraction

The distance from the start, as a share of the interval, is

t=x−x0x1−x0.t = \frac{x - x_0}{x_1 - x_0}.

In the example, t=(4−0)/(10−0)=0.4t = (4 - 0) / (10 - 0) = 0.4.

Step 3 and 4 in symbols: the value

Combining the rate and the distance gives the interpolant

y=y0+m (x−x0)=y0+t (y1−y0).y = y_0 + m\,(x - x_0) = y_0 + t\,(y_1 - y_0).

The two forms are equal. The second form is often nicer, because tt runs from 0 to 1 and the formula reads as "start plus a fraction of the change". In the example, y=0+0.4×50=20y = 0 + 0.4 \times 50 = 20.

Two checks confirm the formula. At x=x0x = x_0 we have t=0t = 0 and y=y0y = y_0. At x=x1x = x_1 we have t=1t = 1 and y=y1y = y_1. The formula reproduces both known points exactly, and the output changes steadily in between.

Worked examples

Example
Example 1: the midpoint (tiny)

Interpolate between (0,2)(0, 2) and (4,10)(4, 10) at x=2x = 2.

  1. The interval length is 4−0=44 - 0 = 4. The point x=2x = 2 is halfway, so t=(2−0)/4=0.5t = (2 - 0) / 4 = 0.5.
  2. The change in output is 10−2=810 - 2 = 8.
  3. The share of the change is 0.5×8=40.5 \times 8 = 4.
  4. Add to the start: 2+4=62 + 4 = 6.
  5. Check: the midpoint of 2 and 10 is 6, which agrees with the straight-line result.

The interpretation: when t=0.5t = 0.5, linear interpolation gives the simple average of the two outputs.

Example
Example 2: the flour table (standard)

Interpolate between (2,300)(2, 300) and (3,420)(3, 420) at x=2.5x = 2.5 cups.

  1. The interval length is 3−2=13 - 2 = 1.
  2. The fraction is t=(2.5−2)/1=0.5t = (2.5 - 2) / 1 = 0.5.
  3. The change in grams is 420−300=120420 - 300 = 120.
  4. The share of the change is 0.5×120=600.5 \times 120 = 60.
  5. Add to the start: 300+60=360300 + 60 = 360 grams.
  6. Check: the rate is 120120 grams per cup, and half a cup is 6060 grams, so 300+60=360300 + 60 = 360.

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.

Example
Example 3: a sensor reading (realistic)

A calibration gives (1.0 V,20 C)(1.0 \text{ V}, 20 \text{ C}) and (2.0 V,52 C)(2.0 \text{ V}, 52 \text{ C}). A reading of 1.35 volts must be converted to a temperature.

  1. The interval length in volts is 2.0−1.0=1.02.0 - 1.0 = 1.0.
  2. The fraction is t=(1.35−1.0)/1.0=0.35t = (1.35 - 1.0) / 1.0 = 0.35.
  3. The change in degrees is 52−20=3252 - 20 = 32.
  4. The share of the change is 0.35×32=11.20.35 \times 32 = 11.2.
  5. Add to the start: 20+11.2=31.220 + 11.2 = 31.2 degrees Celsius.
  6. Check: the line has slope 3232 degrees per volt. From 1.0 volt, moving 0.350.35 volts adds 0.35×32=11.20.35 \times 32 = 11.2, 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: t=0.8t = 0.8, the share of the change is 0.8×32=25.60.8 \times 32 = 25.6, and the temperature is 20+25.6=45.620 + 25.6 = 45.6 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 tt 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 tt 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 tt 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 t=0t = 0 mean in the formula y=y0+t (y1−y0)y = y_0 + t\,(y_1 - y_0)?Show answer

It means the point lies exactly at the start of the interval, x=x0x = x_0, so the interpolated value is the starting value y0y_0. At t=1t = 1 the point is at the end and the value is y1y_1.

QuestionInterpolate between (0, 4) and (8, 12) at x = 6. What is the value?Show answer

The fraction is t=(6−0)/8=0.75t = (6 - 0) / 8 = 0.75. The change is 12−4=812 - 4 = 8. The share of the change is 0.75×8=60.75 \times 8 = 6. Add to the start: 4+6=104 + 6 = 10. 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 tt 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