gizmobench

Linear Interpolation Calculator

Two points, one straight line, and a plain statement of which side of the evidence the answer came from. Enter the two points and a target x, and the page returns the y on the line, the slope, the y where the line crosses x = 0, and a Position cell reading Interpolated, Extrapolated or At a known point, with the segment plotted and the carry past it drawn as a dashed reach. It runs the other way too, solving x from a target y, and it refuses the two cases that have no single answer: two points sharing an x, and a flat segment asked for an inverse. Results are shown to twelve significant figures, a whole number is shown in full, and the formula is printed underneath with your own numbers in it.

y at x = 115(0, 10) to (4, 30) · slope 5 · inside the segment
Solve for

The y on the straight line through your two points at the x you name. A target between the two points is interpolated; one outside them is still answered and labelled extrapolation.

y
15
Slope
5
y at x = 0
10
Position
Interpolated

The line through your two points is y = 5x + 10, and the answer works out as y = 10 + (1 − 0) × (30 − 10) ÷ (4 − 0) = 15.

Three cases, worked

The same two points, read three ways. Every line below is computed by the code that answers the calculator above, so the examples and the tool can never disagree.

  • (0,10) and (4,30), x = 1between the points
    y = 15
  • Same two points, x = 6past the endpoint
    y = 40, labelled extrapolated
  • Both points share an x(2,5) and (2,9)
    Both points share an x of 2, so there is no single straight line through them. Change one of the two x values.
Accuracy. Exact arithmetic on the straight line through your two points: y = y1 + (x - x1)(y2 - y1)/(x2 - x1). A target beyond the endpoints is still answered, but labelled extrapolation, because the two points are only evidence between themselves. It fits no curve and smooths nothing, and a flat segment has no unique inverse, which it says rather than picking one.

Common questions

How do you calculate linear interpolation between two points?
Multiply the distance from the first x by the rise between the two y values, divide by the run between the two x values, and add the result to the first y: y = y1 + (x - x1)(y2 - y1)/(x2 - x1). With the points (0, 10) and (4, 30), x = 1 gives y = 15, because the slope is 5 and one step in x adds 5 to y. The page prints that line of arithmetic with your own numbers in it, so a figure typed into the wrong field is easy to spot.
What is the difference between interpolation and extrapolation?
Interpolation reads a value between the two points you gave. Extrapolation carries the same straight line past them, which is arithmetic you can always do and evidence you may not have. On the same two points, x = 6 gives y = 40, and the Position cell reads Extrapolated instead of Interpolated, with the carry drawn as a dashed line on the plot. The number is not withheld; it is labelled.
Can it work backwards, from a y value to an x?
Yes. Switch to Find x from y and it solves x = x1 + (y - y1)(x2 - x1)/(y2 - y1). On the points (0, 10) and (4, 30), y = 20 gives x = 2. One case has no answer: if both points share a y, the segment is flat, every x on it returns that y, and the page says which kind of nothing it found rather than picking an x for you.
Why are two points with the same x refused?
Because they describe a vertical line, and a vertical line does not have one y at that x, it has all of them. The slope would be a division by zero. Rather than reporting an infinity, the page names the x the two points share and asks for one of the two to change.
What are the slope and the y-intercept of the line?
The slope is (y2 - y1)/(x2 - x1), and the intercept is the y where the line crosses x = 0. For (0, 10) and (4, 30) the line is y = 5x + 10, and both numbers sit in the readout beside the answer, because a question that starts with interpolation usually ends with the equation of the line.
Does it handle negative numbers and decimals?
Yes, in every field, including a target outside the two points. The points (-2, -5) and (3, 10) give the line y = 3x + 1, so a target x of 0 returns y = 1. Values can be typed with a decimal point, a minus sign, grouped thousands like 1,250 or exponent form like 1.2e5, and anything that does not read as a number is quoted back to you rather than silently treated as zero.
Is this the same as a line of best fit or a spline?
No. It uses exactly two points and the single straight line through them, so it fits nothing and smooths nothing. A best-fit line through many points is regression, and a smooth curve through many points is a spline. If you have a scatter of points rather than two, the linear regression calculator is the one to use.
How precise are the results?
The arithmetic is ordinary double precision, the same as a spreadsheet, and figures are shown to twelve significant figures, with a whole number shown in full and very large or very small values in exponent form. Nothing is rounded before the answer is worked out. In the rare case where one step of the multiplication would run past what a double can hold, the ratio is divided first and the page says that it regrouped the arithmetic.
Are my numbers stored or sent anywhere?
They stay in this browser. The last set you typed is remembered locally so the page opens where you left it, and nothing is uploaded. If storage is blocked or full the calculator still works, it simply forgets.

Exact arithmetic on the straight line through your two points: y = y1 + (x - x1)(y2 - y1)/(x2 - x1). A target beyond the endpoints is still answered, but labelled extrapolation, because the two points are only evidence between themselves. It fits no curve and smooths nothing, and a flat segment has no unique inverse, which it says rather than picking one.