Skip to main content

How to Calculate Linear Interpolation: Data Analysis Guide

Dr. Michael Chen · 2024-04-28 · 11 min read · Mathematics

Linear interpolation estimates values between known data points. This guide derives the formula three equivalent ways, works through steam-table and engineering examples, explains why extrapolation is far riskier, and shows when a straight line is the wrong model.

How to Calculate Linear Interpolation

You have a table. The value you need falls between two rows. Linear interpolation is how you estimate it.

The assumption is simple and usually reasonable: between two nearby known points, the quantity changes at a constant rate. Draw a straight line between them and read off the value you want.

The formula

Given two known points (x_1, y_1) and (x_2, y_2), the value at some x between them is:

y = y_1 + (x - x_1)(y_2 - y_1)/(x_2 - x_1)

Read it as: start at the first known value, then add the fraction of the way you have travelled multiplied by the total change.

Three ways to see the same thing

As a slope. The middle term (y_2-y_1)/(x_2-x_1) is just the gradient. Multiply by how far you have moved in x and add to the starting y. It is the equation of a line.

As a fraction. Define t = (x - x_1)/(x_2 - x_1), the fraction of the way from the first point to the second. Then:

y = y_1 + t(y_2 - y_1)

When t = 0 you get y_1; when t = 1 you get y_2; at t = 0.5 you get the midpoint.

As a weighted average. Rearranging again:

y = (1-t)y_1 + t\,y_2

This form makes the intuition clearest: the answer is a blend of the two known values, weighted by proximity. Sit 30% of the way along and you get 70% of the first value plus 30% of the second.

All three are identical. Use whichever you find easiest to remember.

A worked example

A steam table gives the specific volume of saturated water vapour:

What is it at 104 °C?

Fraction of the way:

t = (104 - 100)/(110 - 100) = (4)/(10) = 0.4

Interpolate:

y = 1.6720 + 0.4(1.2094 - 1.6720) = 1.6720 + 0.4(-0.4626) = 1.6720 - 0.1850 = 1.4870

So approximately 1.4870 m³/kg.

Note the negative difference handled naturally — the formula does not care whether the quantity rises or falls.

A second example: pump sizing

A pump curve is tabulated at whole flow rates:

Head at 13.5 L/s:

t = (13.5 - 12)/(15 - 12) = (1.5)/(3) = 0.5

y = 28.5 + 0.5(24.2 - 28.5) = 28.5 - 2.15 = 26.35 \text m

Exactly halfway between the two flows gives exactly the midpoint head, as it should.

Interpolation vs extrapolation

Interpolation estimates between known points. Extrapolation estimates outside them, using the same formula.

They are mathematically identical and practically very different.

Interpolation is bounded: your answer must lie between two measured values, so the error is limited by how curved the underlying relationship is over a short interval. Usually small.

Extrapolation has no such safety net. You are asserting that a trend observed over a measured range continues into a range you have not measured. The further you go, the worse it gets, and nothing in the arithmetic warns you.

A concrete failure. Water's density rises as it cools from 20 °C to 10 °C. Extrapolate that trend to −10 °C and you would predict water continues getting denser. It does not — density peaks at 4 °C and then falls, which is why ice floats and why lakes freeze from the top. The linear trend was real and the extrapolation was still wrong.

Treat extrapolation as a hypothesis, not a result, and only ever a short distance beyond your data.

When a straight line is the wrong model

Linear interpolation assumes constant rate of change between points. That assumption fails when:

The relationship is strongly curved and the points are far apart. Interpolating \sin(x) between 0° and 180° gives zero everywhere — the true curve peaks at 1. The fix is closer table intervals, which is precisely why engineering tables are tabulated finely where quantities change fast.

There is a discontinuity between the points. Interpolating water properties across 100 °C at atmospheric pressure is meaningless — there is a phase change in between, and no smooth curve connects liquid to vapour.

The data is noisy. Interpolation passes exactly through both points, including their measurement error. With scattered experimental data, regression through many points is more honest than interpolation between two.

The quantity is inherently non-linear over the interval. Compound growth, radioactive decay and pH are logarithmic. Interpolating them linearly over a wide range introduces real error. Interpolating the logarithm linearly is often the right move.

Estimating the error

For a smooth function, the maximum error of linear interpolation over an interval h is bounded by:

|E| ≤ (h^2)/(8)\max|f''(x)|

The practical reading: error grows with the square of the interval. Halve the spacing between table entries and the interpolation error drops to a quarter.

It also scales with the second derivative — the curvature. A nearly straight relationship interpolates almost perfectly however wide the gap; a sharply curving one needs fine intervals.

This is why steam tables are dense near the critical point and sparse in regions where properties vary slowly.

Bilinear interpolation

When a value depends on two variables — a property tabulated against both temperature and pressure — interpolate twice.

Interpolate along the first variable at each of the two bracketing values of the second, then interpolate between those two results.

Example. A property tabulated at 100 °C and 110 °C, and at 1 bar and 2 bar. To find the value at 104 °C and 1.4 bar: interpolate to 104 °C at 1 bar, interpolate to 104 °C at 2 bar, then interpolate between those two answers at 1.4 bar.

The order does not matter — temperature first or pressure first gives the same result.

Beyond straight lines

Polynomial interpolation fits a curve through three or more points. More accurate for smooth data, but prone to wild oscillation between points when the degree is high — Runge's phenomenon.

Spline interpolation fits piecewise cubics with matched slopes at the joins. Smooth, well-behaved, and the standard choice in graphics and CAD.

Logarithmic interpolation applies the linear method to \log y rather than y. Correct for exponential relationships such as decay, compound growth and many pressure-temperature curves.

For most engineering table lookups, linear interpolation with a fine enough table beats anything more sophisticated, because the tables were designed for it.

Common mistakes

Extrapolating without acknowledging it. The formula gives an answer outside the range without complaint. Check that your x actually lies between x_1 and x_2.

Interpolating across a discontinuity such as a phase change.

Mixing up which point is which. (x_1,y_1) and (x_2,y_2) can be in either order — the formula is symmetric — but the x and y of a single point must stay paired.

Interpolating linearly on logarithmic data. Check whether the relationship is exponential first.

Ignoring the interval width. A wide interval over a curved region can carry substantial error. The h^2 bound tells you how much.

Frequently asked questions

How accurate is linear interpolation? It depends on curvature and spacing. Error is bounded by (h^2)/(8)\max|f''|. For finely tabulated engineering data it is typically well under 1% — usually smaller than the uncertainty in the tabulated values themselves.

Can I interpolate between more than two points? Not with this formula — it uses exactly two. For more points, use polynomial or spline interpolation, or simply pick the two points that bracket your target most closely, which is usually best anyway.

What if my value equals one of the known points? The formula returns that point's value exactly. At x = x_1, t = 0 and y = y_1.

Is interpolation the same as regression? No. Interpolation passes exactly through the known points, assuming they are correct. Regression fits a trend through scattered points and generally passes through none of them. Use interpolation for reliable tabulated data, regression for noisy measurements.

Why do engineering tables use uneven intervals? Because interpolation error scales with curvature. Tables are tabulated finely where properties change rapidly and coarsely where they change slowly, keeping interpolation error roughly constant throughout.

Can I interpolate dates or times? Yes — convert to a numeric representation such as days since an epoch, interpolate, then convert back. The arithmetic is the same.

Summary

Linear interpolation is y = y_1 + t(y_2 - y_1) where t is the fraction of the way between the two known points. It is a weighted average of the values on either side, and reading it that way makes it hard to get wrong.

Use it freely between closely spaced points. Treat extrapolation beyond your data with real suspicion, and check for curvature or discontinuities before trusting a straight line across a wide gap.

Interpolate any pair of points with our Linear Interpolation Calculator.

Topics: linear interpolation, data analysis, mathematics, estimation, extrapolation