\chapter*{Calculating Cubic Splines}

\begin{remark}[Problem]
    Given a set of \( m \) data points \( \{ (t_i, y_i) \}_{i=1}^{m} \) or \( \{ (t_i, f(t_i)) \}_{i=1}^{m} \), determine a smooth apline function \( S(t) \) that interpolates the data, and where \( S(t) = S_i(t) \) when \( t \in [t_i, t_{i+1}] \).
\end{remark}

\section*{Calculating Cubic Splines}

Define \( S_i(t) = a_i + b_i(t - t_i) + c_i(t - t_i)^2 + d_i(t - t_i)^3 \) for \( i = 1, 2, \dots, m \).

\begin{note}
    The polynomial \( S_m(t) \) is a ``fictitious'' piece that helps with the calculation of the polynomial coefficients.
\end{note}

\subsection*{Step 1 -- determine the step size \( \{ h_i \}_{i=1}^{m} \)}

Calculate \( h_i = t_{i + 1} - t_i \) for \( i = 1, 2, \dots, m - 1 \).

\subsection*{Step 2 -- Determine the coefficients \( \{ c_i \}_{i=1}^{m} \)}

We will have to set up and solve a dimension \( m \times m \) linear system \( \mathbf{M}\vec{C} = \vec{r} \). The system will depend on whether we are finding a \textbf{natural} spline, a \textbf{clamped} spline, or a \textbf{not-a-knot} spline. We only consider the first two cases here.

\subsubsection{Natural Splines}

In this case, the linear system has the form
% \[
%     \begin{bmatrix}
%         \mathbf{1} &              &              &                      &            \\
%         h_1        & 2(h_1 + h_2) & h_2          &                      &            \\
%                    & h_2          & 2(h_2 + h_3) & h_3                  &            \\
%                    &              & \ddots       & \ddots               & \ddots     \\
%                    &              & h_{m-2}      & 2(h_{m-2} + h_{m-1}) & h_{m-1}    \\
%                    &              &              &                      & \mathbf{1}
%     \end{bmatrix} \begin{bmatrix}
%         c_1 \\ c_2 \\ c_3 \\ \vdots \\ c_{m-1} \\ c_m
%     \end{bmatrix} =
%     \begin{bmatrix}
%         \mathbf{0}                                                                \\
%         \dfrac{3}{h_2}(y_3 - y_2) - \dfrac{3}{h_1}(y_2 - y_1)                     \\
%         % \dfrac{3}{h_3}(y_4 - y_3) - \dfrac{3}{h_2}(y_3 - y_2)                     \\
%         \vdots                                                                    \\
%         \dfrac{3}{h_{m-1}}(y_m - y_{m-1}) - \dfrac{3}{h_{m-2}}(y_{m-1} - y_{m-2}) \\
%         \mathbf{0}
%     \end{bmatrix}
% \]

\textbf{Solve} this linear system for \( \{ c_i \}_{i=1}^{m} \) using Gaussian Elimination.

\begin{note}
    This can be reduced to a dimension \( (m - 2) \times (m - 2) \) system because the first and last equations tell us that \( c_1 = 0 \) and \( c_m = 0 \).
\end{note}

\subsubsection{Clamped Splines}

The first and last equations from the natural spline cause change to account for the different boundary conditions.
% TODO: Matrices

\textbf{Solve} this linear system for \( \{ c_i \}_{i=1}^{m} \) using Gaussian Elimination.

\subsection*{Step 3 -- Determine the coefficients \( \{ a_i \}_{i=1}^{m} \)}

Calculate \( a_i = y_i \), \( i = 1, 2, \dots, m - 1 \).

\subsection*{Step 4 -- Determine the coefficients \( \{ b_i \}_{i=1}^{m} \)}

Calculate \( b_i = \dfrac{y_{i+1} - y_i}{h_i} - \dfrac{h_i}{3}(2c_i + c_{i+1}) \), \( i = 1, 2, \dots, m - 1 \).

\subsection*{Step 5 -- Determine the coefficients \( \{ d_i \}_{i=1}^{m} \)}

Calculate \( d_i = \dfrac{c_{i+1} - c_i}{3h_i} \), \( i = 1, 2, \dots, m - 1 \).