# Cubic Spline Interpolation Splines

Cubic spline interpolation for the set $$\mathcal{D}=\left\{\left(0,21\right),\left(1,24\right),\left(2,24\right),\left(3,18\right),\left(4,16\right)\right\}\,.$$ All splines of the interpolation function $$f(x) = \begin{cases}-0.30357 x^3 + 3.3036x + 21& \text{if } x \in [0,1]\\-1.4821x^3 + 3.5357x^2 -0.23214 x + 22.179& \text{if } x \in (1,2]\\3.2321x^3 -24.750x^2 + 56.339 x -15.536& \text{if } x \in (2,3]\\-1.4464x^3 + 17.357 x^2 -69.982 x + 110.79& \text{if } x \in (3,4]\end{cases}$$ are plotted and colored in black within the interval where they compose the interpolation function $f(x)$. The applied boundary condition is called “natural”.

LaTeX source

\documentclass[11pt]{article}

% graphics
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.12}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{minipage}{.35\textwidth}	\begin{tikzpicture}
\pgfplotsset{
scale only axis,
xmin=-.5,xmax=4.5,
ymin=15,ymax=25.5,
}

\begin{axis}[
xlabel=$x$,
ylabel=$y$,
samples=100,
xtick={0,1,2,3,4}
0 21
1 24
2 24
3 18
4 16
};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.35\textwidth}
\begin{tikzpicture}
\pgfplotsset{
scale only axis,
xmin=-.5,xmax=4.5,
ymin=15,ymax=25.5,
}

\begin{axis}[
xlabel=$x$,
ylabel=$y$,
samples=100,
xtick={0,1,2,3,4}
0 21
1 24
2 24
3 18
4 16
};
\end{axis}
\end{tikzpicture}
\end{minipage}\\\\

\begin{minipage}{.35\textwidth}
\begin{tikzpicture}
\pgfplotsset{
scale only axis,
xmin=-.5,xmax=4.5,
ymin=15,ymax=25.5,
}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
samples=100,
xtick={0,1,2,3,4}
0 21
1 24
2 24
3 18
4 16
};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.35\textwidth}
\begin{tikzpicture}
\pgfplotsset{
scale only axis,
xmin=-.5,xmax=4.5,
ymin=15,ymax=25.5,
}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
samples=100,
xtick={0,1,2,3,4}
0 21
1 24
2 24
3 18
4 16
};