Solution (source code)

= Solution

A <natural cubic spline> is piecewise cubic, interpolates the data, has <continuous> first and second derivatives at the knot, and has zero second derivative at the outer endpoints. Its nodal second derivatives here satisfy $M_0=M_2=0$ and the usual matching equation
$$
M_0+4M_1+M_2=6[(4-0)-(0-0)]=24,
$$
so $M_1=6$. The resulting pieces are
$$
\boxed{S(x)=\begin{cases}x^3-x,&0\leq x\leq1,\\2t+3t^2-t^3,\quad t=x-1,&1\leq x\leq2.\end{cases}}
$$
Directly, the values are $0,0,4$, both first derivatives at one equal two, both second derivatives there equal six, and $S''(0)=S''(2)=0$. Thus all spline conditions hold.

The second data set adds the values of the affine <function> $x$ to the first. Adding $x$ to the spline preserves derivative matching and the zero endpoint second derivatives, so uniqueness of the natural interpolant gives \b[the new spline $S(x)+x$]. Its first piece is $x^3$, and its second is $1+3t+3t^2-t^3$. This is the <affine covariance of natural cubic spline interpolation>.

\Image[/past-exam-of-the-options-i-course-of-the-university-of-oxford/2008-natural-splines.png]
{title=Natural cubic interpolation and an affine change of the data}
{description=The second interpolant is obtained by adding $x$ to the first. Dots mark the three interpolation nodes of each curve.}