Linear Interpolation: The Intuition
Imagine you're walking along a straight road between two towns. You know the distance to Town A (at the start) and the distance to Town B (at the end). If someone asks, "How far have you walked when you're one-third of the way there?" — you don't need a GPS. You just take one-third of the total distance and add it to the starting point.
That's linear interpolation in a nutshell: filling in the gaps between two known points by assuming the change happens at a constant rate.
The key assumption is linearity — the quantity changes by the same amount for each unit of the input. If the temperature at 2 PM was 30°C and at 4 PM it was 40°C, linear interpolation says at 3 PM it was exactly 35°C. The real temperature might have been 34°C or 36°C, but if you have no other data, the straight-line guess is the most natural one.
The Precise Statement
Let's formalise this. You have two known points:
- (x0,y0) — the first point
- (x1,y1) — the second point, with x1=x0
You want to estimate the value y at some x that lies between x0 and x1.
y=y0+x1−x0y1−y0⋅(x−x0)
Here's what each part means:
- x1−x0y1−y0 is the slope — the rate of change of y per unit change in x. It tells you how much y increases (or decreases) when x increases by 1.
- (x−x0) is how far you've moved from the starting point.
- Multiplying them gives the total change in y from x0 to x.
- Adding y0 gives the final estimate.
A cleaner way to remember this: the fraction of the way you are between x0 and x1 equals the fraction of the way you should be between y0 and y1.
x1−x0x−x0=y1−y0y−y0
A Worked Example
Suppose a car's speed is recorded at two times:
- At t=10 seconds, speed =20 m/s
- At t=20 seconds, speed =50 m/s
What was the speed at t=14 seconds?
Here x0=10, y0=20, x1=20, y1=50, and x=14.
Slope: 20−1050−20=1030=3 m/s per second.
Distance from start: 14−10=4 seconds.
Change in speed: 3×4=12 m/s.
Estimated speed: 20+12=32 m/s.
Linear interpolation only works between the two known points. If you try to estimate a value outside the range (say at t=25 seconds), that's called extrapolation — a much riskier business because you're assuming the same rate continues forever.
Why "Linear"?
The formula gives a straight line between the two points. If you plot (x0,y0) and (x1,y1) on a graph and draw a line through them, the interpolated value for any x is simply the y-coordinate of that line at that x. The word "linear" refers to this straight-line relationship — not to the fact that the original data might be linear. …