# Interpolation

Interpolation is a process of defining a function to find new point(s) within the range of a discrete set of known data points. Using interpolation, we can describe or at least approximate the function at every point in space.

# Linear interpolation

Linear interpolation is obtained by passing a straight line between 2 data points. Fig. c.1 illustrates the linear interpolation between the data points $x_0$ and $x_1$ of a function $f(x)$ and $g(x)$ is the linearly interpolated approximation to $f(x)$.

Fig. c.1: Linear interpolation.

If $g(x)$ is a linear function, then:
$$g(x) = Ax + B;$$ where $A$ and $B$ are unknown coefficients. To pass through points $(x_0, f(x_0))$ and $(x_1, f(x_1))$ we should have:
\begin{aligned} & Ax_0 + B = f(x_0); \\ & Ax_1 + B = f(x_1). \end{aligned} Solving this system of equations leads to the following results:
\begin{aligned} & A = \frac{f(x_1) - f(x_0)}{x_1 - x_0}; \\ & B = \frac{f(x_0)x_1 - f(x_1)x_0}{x_1 - x_0}. \end{aligned} Substituting for $A$ and $B$ into the Eq. (1), we have:
$$g(x) = f(x_0)\frac{x_1 - x}{x_1 - x_0} + f(x_1)\frac{x - x_0}{x_1 - x_0}.$$ This is the formula for linear interpolation.

Other types of interpolations can be found as follows:

(1) Lagrange interpolation;
(2) Spline interpolation;
(3) Least squares method.