---
# System prepended metadata

title: Linear interpolation

---

# Linear interpolation

## Linear interpolation derivation
> (wiki) linear interpolation is a method of curve fitting using linear polynomials to construct new data points within the range of a discrete set of known data points.

![image](https://hackmd.io/_uploads/r1T3ujYw1x.png)
For example, in the image above, the red dots are the the measurements we know, the blue dots are the data we need to interpolate.

![image](https://hackmd.io/_uploads/SJWEFoYvJe.png)

So, where does the fomulation at end of slide come from?

Let's reformulate the problem here. Given two known value $y_0, y_1$ are evaluated at $x_0, x_1$, respectively, and a value of $x \in [x_0, x_1]$, we want to estimate the value of $y$ (see graph below).
![image](https://hackmd.io/_uploads/BkkEoiYwye.png)

Start with slope equation:
$$\frac{y-y_0}{x-x_0} = \frac{y_1 - y_0}{x_1 - x_0}$$

Solving for $y$, we have:

\begin{align*}
  y &= y_0 + (x-x_0)\frac{y_1 - y_0}{x_1 - x_0} \\
   &= \frac{y_0 (x_1- x_0) + (x-x_0)(y_1-y_0)}{x_1 - x_0} \\
   &= \frac{(y_0 x_1 - y_0 x_0) + (xy_1 - xy_0 - x_0 y_1 + x_0y_0)}{x_1 - x_0} \\
   &= \frac{y_0 (x_1 - x) + y_1 (x-x_0)}{x_1 - x_0} \\
   &= y_0 \frac{x_1 - x}{x_1 - x_0} + y_1 \frac{x-x_0}{x_1 - x_0}
\end{align*} 

Now, if we set $t := \frac{x-x_0}{x_1 - x_0}$, then $1-t = \frac{x_1 - x}{x_1 - x_0}$. Thus the above equation becomes:

\begin{align*}
  y &= y_0 \times (1-t) + y_1 \times t \\
   &=(y_1 - y_0) \times t + y_0
\end{align*} 

which matches with the equation in the slide, where $y_0 = a, y_1 = b$.


## Reference
https://en.wikipedia.org/wiki/Linear_interpolation