Again, the basic idea of the cubic spline is that we represent the function by a different cubic function on each interval between data points. That is, if there are \(n\) data points, then the spline \(S(x)\) is the function
\begin{equation*}
S(x) = \left\{ \begin{array}{ll}C_1(x), & \quad x_0 \le x \le x_1 \\ C_i(x), & \quad x_{i-1} \le x \le x_i \\ C_n(x), & \quad x_{n-1} \le x \le x_n\end{array} \right.\text{,}
\end{equation*}
where each \(C_{i}\) is a cubic function. The most general cubic function has the form
\begin{equation*}
C_{i}(x) = a_{i} + b_{i} x + c_{i} x^{2} + d_{i} x^{3}\text{.}
\end{equation*}
To determine the spline we must determine the coefficients, \(a_{i}\text{,}\) \(b_{i}\text{,}\) \(c_{i}\text{,}\) and \(d_{i}\) for each \(i\text{.}\) Since there are \(n\) intervals, there are \(4n\) coefficients to determine. First we require that the spline interpolate by requiring
\begin{equation*}
C_{i}(x_{i-1}) = y_{i-1}\quad \text{and}\quad C_{i}(x_{i}) = y_{i}\text{,}
\end{equation*}
at every data point. In other words,
\begin{equation*}
a_{i} + b_{i} x_{i-1}+ c_{i} x_{i-1}^{2} + d_{i} x_{i-1}^{3} = y_{i-1}\quad \text{and}\quad a_{i} + b_{i} x_{i} + c_{i} x_{i}^{2} + d_{i} x_{i}^{3} = y_{i}\text{.}
\end{equation*}
Notice that there are \(2n\) of these conditions. Then to make \(S(x)\) as smooth as possible we require
\begin{equation*}
\begin{split}C'_{i}(x_{i})&= C'_{i+1}(x_{i})\quad\text{and}\\ C''_{i}(x_{i})&= C''_{i+1}(x_{i})\end{split}
\end{equation*}
at all the internal points, i.e. \(x_{1}\text{,}\) \(x_{2}, x_{3}, \ldots, x_{n-1}\text{.}\) In terms of the points these conditions can be written as
\begin{equation*}
\begin{split}b_{i} + 2 c_{i} x_{i} + 3 d_{i} x_{i}^{2}&= b_{i+1}+ 2 c_{i+1}x_{i} + 3 d_{i+1}x_{i}^{2} \quad\text{and}\\ 2 c_{i} + 6 d_{i} x_{i}&= 2 c_{i+1}+ 6 d_{i+1}x_{i}.\end{split}
\end{equation*}
There are \(2(n-1)\) of these conditions. Since each \(C_{i}\) is cubic, there are a total of \(4n\) coefficients in the formula for \(S(x)\text{.}\) So far we have \(4n - 2\) equations, so we are 2 equations short of being able to determine all the coefficients. At this point we have to make a choice. The usual choice is to require
\begin{equation*}
C''_{1}(x_{0}) = C''_{n}(x_{n}) = 0.
\end{equation*}
These are called natural or simple boundary conditions. The other common option is called clamped boundary conditions:
\begin{equation*}
C'_{1}(x_{0}) = C'_{n}(x_{n}) = 0.
\end{equation*}
The terminology used here is obviously parallel to that used for beams. That is not the only parallel between beams and cubic splines. It is an interesting fact that a cubic spline is exactly the shape of a (linear) beam restrained to match the data by simple supports.