Cubic Splines for Interpolating Functions

# Cubic Splines for Interpolating Functions

Recall from the Natural Cubic Spline Function Interpolation page that if $(x_1, y_1)$, $(x_2, y_2)$, …, $(x_n, y_n)$ are points in $\mathbb{R}^2$ such that $x_1 < x_2 < ... < x_n$, then we can construct a natural cubic spline for this data set on the interval $[x_1, x_n]$ of piecewise smooth cubic polynomials [$s(x)$. For each subinterval $[x_{j-1}, x_j]$ for $j = 2, 3, ..., n$ we define:

(1)
\begin{align} \quad s(x) = \frac{(x_j - x)^3 M_{j-1} + (x - x_{j-1})^3 M_j}{6(x_j - x_{j-1})} + \frac{(x_j - x)y_{j-1} + (x - x_{j-1})y_j}{x_j - x_{j-1}} - \frac{1}{6} (x_j - x_{j-1})\left ( (x_j - x)M_{j-1} + (x - x_{j-1})M_j \right ) \end{align}

The values of the $M$'s are obtained by solving the following system of equations:

(2)
\begin{align} \quad \left\{\begin{matrix} M_1 = M_n = 0\\ \frac{1}{6}(x_j - x_{j-1})M_{j-1} + \frac{1}{3}(x_{j+1}-x_{j-1})M_j + \frac{1}{6}(x_{j+1} -x_j)M_{j+1} = \frac{y_{j+1}-y_j}{x_{j+1}-x_j} - \frac{y_j - y_{j-1}}{x_j - x_{j-1}} & j = 2, 3, ..., n-1 \end{matrix}\right. \end{align}

Now instead, suppose that instead the data points $(x_1, y_1)$, $(x_2, y_2)$, …, $(x_n, y_n)$ are obtained in attempting to approximation a function $y = f(x)$. Then we will also want our cubic spline to be an accurate representation of $f$ on the interval $[x_1, x_n]$. Since these data points are on $f$, then we can impose another condition to improve the accuracy of the cubic spline.

Provided that the first and second derivatives of $f$ is known, then we can also require that the endpoints of our cubic spline satisfies:

(3)
We can use the same formula for each $s(x)$ on each subinterval $[x_{j-1}, j_n]$, $j = 2, 3, ..., n$ from above, but now, we require that the $M$'s satisfy: