What is linear interpolation?
Linear interpolation estimates an unknown value that lies between two known data points by assuming the relationship between them is a straight line. It is one of the most common techniques in engineering, statistics, finance, and science whenever you have a table of values and need a reading that falls between the listed entries.
How to use this calculator
Enter the coordinates of your two known points: \((x_1, y_1)\) and \((x_2, y_2)\). Then enter the x value you want to evaluate. The calculator returns the interpolated y value along with the slope of the connecting line. The x value may also fall outside the two points, in which case the result is a linear extrapolation.
The formula explained
The interpolation formula is $$y = y_1 + \left(x - x_1\right) \cdot \frac{y_2 - y_1}{x_2 - x_1}$$ The fraction \(\frac{y_2 - y_1}{x_2 - x_1}\) is the slope of the line through the two points. Multiplying by \((x - x_1)\) scales that slope by how far x has moved from \(x_1\), and adding \(y_1\) shifts the result to the correct starting height.
Worked example
Suppose you know the point \((1, 2)\) and \((4, 8)\), and want y at \(x = 3\). The slope is $$\frac{8 - 2}{4 - 1} = \frac{6}{3} = 2$$ Then $$y = 2 + (3 - 1) \times 2 = 2 + 4 = 6$$ So the interpolated value is 6.
More Linear Interpolation Examples
Both examples use the formula \(y = y_1 + (x - x_1)\cdot\frac{y_2 - y_1}{x_2 - x_1}\).
Example 1: Reading a lookup table with decimals
A table lists a sensor value of 1.50 at x = 20 and 2.10 at x = 30. Estimate the value at x = 25.
- Known points: \((x_1, y_1) = (20, 1.50)\) and \((x_2, y_2) = (30, 2.10)\); target \(x = 25\).
- Slope: \(\frac{2.10 - 1.50}{30 - 20} = \frac{0.60}{10} = 0.06\) per unit of x.
- Substitute: \(y = 1.50 + (25 - 20)\cdot 0.06 = 1.50 + 0.30\).
- Result: \(y =\) 1.80.
Here \(t = (25-20)/(30-20) = 0.5\), so x is exactly halfway and y is the midpoint of 1.50 and 2.10.
Example 2: Negative slope and a short extrapolation
A line passes through (2, 10) and (6, 4). Find y at x = 8, which lies outside the two points.
- Known points: \((x_1, y_1) = (2, 10)\) and \((x_2, y_2) = (6, 4)\); target \(x = 8\).
- Slope: \(\frac{4 - 10}{6 - 2} = \frac{-6}{4} = -1.5\). The negative sign means y decreases as x increases.
- Substitute: \(y = 10 + (8 - 2)\cdot(-1.5) = 10 - 9\).
- Result: \(y =\) 1.
Because \(t = (8-2)/(6-2) = 1.5\) is greater than 1, this is extrapolation. For comparison, an interpolated point at x = 4 gives \(y = 10 + (4-2)\cdot(-1.5) = 7\), with \(t = 0.5\).
Interpreting Your Result and Accuracy Limits
- Exact only if the relationship is linear. The calculator draws a straight line through your two points. If the true relationship is a straight line, the answer is exact. If it curves (for example exponential, logarithmic or quadratic data), the answer is only an approximation.
- Error grows with curvature and spacing. The more the real curve bends, and the farther apart x1 and x2 are, the larger the gap between the straight line and the true curve. Using two points that are close together on either side of your target gives a better estimate.
- Extrapolation is less reliable. Estimating outside the range of x1 to x2 assumes the trend continues unchanged, which is often untrue. Treat extrapolated values with caution, especially far from the known points.
- Endpoints return the known values. If x = x1 the result is y1, and if x = x2 the result is y2, because the correction term is 0 or the full rise.
- Fractional position t. The parameter \(t = \frac{x - x_1}{x_2 - x_1}\) shows where x lies. A value of t from 0 to 1 means interpolation (t = 0.5 is the midpoint). A t below 0 or above 1 means extrapolation.
- Sign of the slope. A positive slope \(\frac{y_2 - y_1}{x_2 - x_1}\) means y increases as x increases. A negative slope means y decreases as x increases. A slope of zero means y stays constant.
- Requirement. x1 and x2 must be different, otherwise the slope is undefined (division by zero).
Key Terms in Linear Interpolation
- Interpolation
- Estimating an unknown value that lies between two known data points.
- Extrapolation
- Estimating a value outside the range of the known points by extending the trend. It is generally less reliable than interpolation.
- Known points (x1, y1) and (x2, y2)
- The two data points you already have, which define the straight line used for the estimate.
- Target x
- The input value for which you want to estimate y.
- Slope (rise over run)
- The change in y divided by the change in x, \(\frac{y_2 - y_1}{x_2 - x_1}\). It shows how much y changes for each one-unit increase in x.
- Linear relationship
- A relationship in which y changes by a constant amount for every unit change in x, so the graph is a straight line.
- Interpolation fraction (t)
- The value \(t = \frac{x - x_1}{x_2 - x_1}\), giving the relative position of x between x1 and x2. Then \(y = y_1 + t\,(y_2 - y_1)\). Values from 0 to 1 are interpolation; others are extrapolation.
FAQ
Can x be outside the two points? Yes. If x is below \(x_1\) or above \(x_2\) the formula extrapolates linearly, which assumes the trend continues straight.
What if x₁ equals x₂? The two points share the same x, so the slope is undefined (division by zero). The calculator guards against this and returns \(y_1\).
Is this the same as a trendline? It is a two-point straight line. A regression trendline uses many points; interpolation uses exactly the two you supply.