linear interpolation: what it is and when to use it
Linear interpolation is a method to estimate a value that lies between two known data points on a straight line. It’s useful when you have measurements at two boundaries and need a reasonable estimate for an intermediate position, time, temperature, price, or any other quantity that changes approximately linearly between those points.
linear interpolation formula
The basic formula for linear interpolation between two points (x0, y0) and (x1, y1) to find y at x is:
y = y0 + (y1 - y0) * (x - x0) / (x1 - x0)
This computes the proportion of the distance from x0 to x and applies the same proportion to the change in y.
when to use linear interpolation and limitations
- Use it when the variation between points is approximately linear or when you need a simple, fast estimate.
- Don't use it for sharply curved behavior, oscillations, or where higher-order trends dominate—there, polynomial or spline interpolation is better.
- Linear interpolation is only reliable inside the interval between x0 and x1. Estimating outside that range (extrapolation) can produce large errors.
step-by-step: how to interpolate by hand
Follow these steps to get the interpolated value manually.
1. identify the two bounding points
Find the known points (x0, y0) and (x1, y1) such that x0 <= x <= x1. If your target x is outside that range, note that you will be extrapolating.
2. compute the fractional distance (t)
Compute the fraction t that represents how far x is between x0 and x1:
t = (x - x0) / (x1 - x0)
t is 0 at x0, 1 at x1, and between 0 and 1 for interior points.
3. interpolate y
Apply the fraction to the y difference:
y = y0 + t * (y1 - y0)
4. verify sanity
- If x equals x0, y should equal y0; if x equals x1, y should equal y1.
- If t is negative or greater than 1, you’re extrapolating—treat results cautiously.
practical examples with numbers
example 1: interpolate temperature between hours
Known: at 8:00 the temperature is 14°C and at 12:00 it is 22°C. Estimate temperature at 10:00.
- x0 = 8, y0 = 14
- x1 = 12, y1 = 22
- x = 10
Compute t = (10 - 8) / (12 - 8) = 2/4 = 0.5.
Then y = 14 + 0.5 * (22 - 14) = 14 + 0.5 * 8 = 14 + 4 = 18°C.
Interpretation: at 10:00 the temperature is estimated as 18°C (midpoint between 14 and 22 because 10:00 is halfway in time).
example 2: interpolate price between two quantities
Known: bulk price for 100 units is $450, for 200 units is $800. Estimate unit price at 150 units (total price).
- x0 = 100, y0 = 450
- x1 = 200, y1 = 800
- x = 150
t = (150 - 100) / (200 - 100) = 50/100 = 0.5.
y = 450 + 0.5 * (800 - 450) = 450 + 0.5 * 350 = 450 + 175 = $625.
Interpretation: the interpolated total price for 150 units is $625. Unit price implied is $625/150 ≈ $4.17.
example 3: non-integer x and negative slope
Known: at altitude 0 m pressure is 101.3 kPa, at altitude 1000 m pressure is 89.9 kPa. Estimate pressure at 250 m.
- x0 = 0, y0 = 101.3
- x1 = 1000, y1 = 89.9
- x = 250
t = 250/1000 = 0.25.
y = 101.3 + 0.25 * (89.9 - 101.3) = 101.3 + 0.25 * (-11.4) = 101.3 - 2.85 = 98.45 kPa.
Interpretation: pressure decreases linearly in this approximation, giving about 98.45 kPa at 250 m.
how to use an online linear interpolation tool
An online interpolator speeds this up: enter x0, y0, x1, y1 and the target x; the tool returns y and t and often shows a graph. For a quick test, use the calculators at Calculatorr to pair interpolation with unit conversions or to chain multiple interpolations.
Steps when using a web tool:
- Enter the two known points precisely (units matter).
- Enter the target x; confirm it lies between x0 and x1 for interpolation.
- Review the computed t and result; check a plotted line if available.
interpreting results and common mistakes
- Mixing units: ensure x and y are in consistent units (hours vs minutes, meters vs kilometers).
- Swapping coordinates: keep track which value is x and which is y; swapping them reverses the operation.
- Division by zero: if x1 equals x0 the formula is invalid; points must have distinct x-values.
- Extrapolating without caution: results outside [x0, x1] can be far from true values if the relationship isn’t linear beyond the range.
- Precision: round only at the end; intermediate rounding causes small errors.
extensions and related techniques
- Weighted average: interpolation is a weighted average of y0 and y1 with weights (1 - t) and t.
- Linear interpolation in multiple dimensions: apply 1D interpolation repeatedly (bilinear interpolation for grids).
- Higher-order interpolation: when data curves significantly, use polynomial, Lagrange, or cubic spline interpolation.
quick-reference cheat sheet
| Item | Formula / note |
|---|---|
| Fraction t | t = (x - x0) / (x1 - x0) |
| Interpolated value y | y = y0 + t * (y1 - y0) |
| Edge checks | t=0 → y=y0, t=1 → y=y1 |
| Invalid case | x1 = x0 → division by zero |
final practical tips
- Whenever possible, plot the two known points and the interpolated point to visually check the result.
- Use interpolation for short intervals or when physical knowledge supports near-linear change.
- Combine interpolation with unit converters on Calculatorr when inputs/outputs use different units.
Applying linear interpolation by hand or with a calculator is fast and reliable for many everyday tasks—from estimating temperatures and prices to filling missing data in simple datasets.