Conditions
Given \(n\) points on a two-dimensional plane$$
(X_1, Y_1),(X_2,Y_2) , \ldots ,(X_{n-1},Y_{n-1}) , (X_n,Y_n)
$$(where \(X_1<X_2<\cdots<X_n\)), how can we connect them as “smoothly” as possible? The cubic spline curve (function) is one answer to this problem.
A cubic spline curve has the following properties:
- Each interval between adjacent points is a cubic function
- The intervals \([-\infty,X_1]\) and \([X_n,\infty]\) are linear functions
- The value, slope, and curvature of the curve are continuous at each point
Below is a brief explanation of the specific derivation method.
First, define the function in the interval \( (X_m ,X_{m+1})\) between the \(m\)-th point and the \((m+1)\)-th point as$$ F_m(x)=a_mx^3+b_mx^2+c_mx+d_m$$ However, the region to the left of the first point is \( F_0(x)=c_0x+d_0\), and the region to the right of the \(n\)-th point is \( F_n(x)=c_nx+d_n\). To satisfy the last requirement of the spline curve (continuity of the value, slope, and curvature at each point), the 0th, 1st, and 2nd derivatives must be equal at all \(n\) points.
First, for the points where \(2 <= m <= n-1\), the following four conditions must be satisfied:
- \( F_{m-1}(X_m)= a_{m-1}X_m^3+b_{m-1}X_m^2+c_{m-1}X_m+d_{m-1} =Y_m\)
- \( F_m(X_m)= a_mX_m^3+b_mX_m^2 + c_m X_m + d_m =Y_m\)
- \( F’_{m-1}(X_m) = 3a_{m-1}X_m^2+2b_{m-1}X_m+c_{m-1}= F’_m(X_m) = 3a_mX_m^2+2b_m X_m + c_m\)
- \( F”_{m-1}(X_m) = 6a_{m-1}X_m+2b_{m-1}= F”_m(X_m) = 6a_mX_m+2b_m\)
There are a total of \(4(n-2)\) such conditions.
Also, when \(m=1\), the conditions are:
- \(F_0(X_1)= c_0X_0+d_0 =Y_1\)
- \(F_1(X_1)= a_1X_1^3+b_1X_1^2+c_1X_1+d_1 =Y_1\)
- \(F’_{0} (X_1)= c_0 = F’_1(X_1) = 3 a_1 X_1^2 + 2 b_1 X_1 + c_1 \)
- \(F”_{0}(X_1)= 0 = F”_1(X_1)= 6 a_1X_1 + 2 b_1 \)
When \(m=n\), the conditions are:
- \(F_{n-1}(X_n)= a_{n-1}X_n^3+b_{n-1} X_n^2+c_{n-1}X_n+d_{n-1} =Y_n\)
- \(F_n(X_n)= c_n X_n+d_n =Y_n\)
- \(F’_{n-1}(X_n)= 3a_{n-1}X_n^2+2b_{n-1}X^n+c_{n-1} = F’_n(X_n)= c_n\)
- \(F”_{n-1}(X_n)= 6a_{n-1}X_n+2b_{n-1}= F”_n(X_n)=0\)
To summarize the above, the problem reduces to determining the following \(4n\) unknown parameters $$
(c_0, d_0), (a_1,b_1,c_1,d_1), (a_2,b_2,c_2,d_2),\cdots, (a_{n-1}, b_{n-1},c_{n-1},d_{n-1}), (c_n,d_n)
$$from \(4n\) conditional equations.
Matrix Representation
Since the number of unknown parameters equals the number of linear conditional equations, the most straightforward approach is to express the conditions in matrix form and then solve for the inverse matrix.
First, the conditions for \(2 <= m <= n-1\) can be written as:
$$ \alpha_m= \begin{pmatrix} X_m^3 & X_m^2 & X_m & 1 & 0 & 0 & 0 & 0 \\ 0 &0 & 0 & 0 & X_m^3 & X_m^2 & X_m &1 \\ 3X_m^2 &2X_m & 1 & 0 &- 3X_m^2 & -2X_m & -1 &0 \\ 6X_m & 2 & 0 & 0 &-6X_m &-2 &0 & 0 \end{pmatrix}$$and can be rewritten as$$
\alpha_m
\begin{pmatrix}
a_{m-1}\\b_{m-1}\\c_{m-1}\\d_{m-1}\\a_m\\b_m\\c_m\\d_m
\end{pmatrix}=
\begin{pmatrix}
Y_m\\Y_m\\0\\0
\end{pmatrix}
$$Similarly, the conditions for \(m=1\) are
$$ \alpha_1= \begin{pmatrix}
X_1 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & X_1^3 & X_1^2 & X_1 &1 \\
1 & 0 & -3X_1^2 & -2X_1 & -1 &0 \\
0 & 0 &-6X_1 &-2 &0 & 0
\end{pmatrix},
\,\,\,\, \alpha_1
\begin{pmatrix}
c_0\\d_0\\a_1\\b_1\\c_1\\d_1
\end{pmatrix}=
\begin{pmatrix}
Y_1\\Y_1\\0\\0
\end{pmatrix}
$$ For \(m=n\):$$
\alpha_n= \begin{pmatrix}
X_n^3 & X_n^2 & X_n &1 & 0 & 0\\
0 &0 & 0 & 0 & X_n &1 \\
3X_n^2 & 2X_n & 1 &0 & -1 &0 \\
6X_n & 2 & 0 & 0 & 0 & 0
\end{pmatrix},
\,\,\,\, \alpha_n
\begin{pmatrix}
a_{n-1} \\ b_{n-1} \\ c_{n-1} \\ d_{n-1} \\ c_n \\ d_n
\end{pmatrix}=
\begin{pmatrix}
Y_n\\Y_n\\0\\0
\end{pmatrix}
$$
Furthermore, define the submatrices obtained by splitting \(\alpha\) into left and right halves as follows:$$
\alpha^\textrm{L}_m= \begin{pmatrix} X_m^3 & X_m^2 & X_m & 1 \\
0 &0 & 0 & 0 \\
3X_m^2 &2X_m & 1 & 0 \\
6X_m & 2 & 0 & 0 \end{pmatrix},\,\,
\alpha^\textrm{R}_m= \begin{pmatrix}
0 & 0 & 0 & 0 \\
X_m^3 & X_m^2 & X_m &1 \\
-3X_m^2 & -2X_m & -1 &0 \\
-6X_m &-2 &0 & 0 \end{pmatrix}\\ \, \\
\alpha^\textrm{L}_1= \begin{pmatrix} X_1 & 1 \\0 & 0 \\ 1 & 0 \\0 & 0 \end{pmatrix},
\,\,\,\, \alpha^\textrm{R}_1= \begin{pmatrix}
0 & 0 & 0 & 0 \\X_1^3 & X_1^2 & X_1 &1 \\ -3X_1^2 & -2X_1 & -1 &0 \\-6X_1 &-2 &0 & 0
\end{pmatrix}\\ \, \\
\alpha^\textrm{L}_n= \begin{pmatrix}
X_n^3 & X_n^2 & X_n &1\\
0 &0 & 0 & 0 \\
3X_n^2 & 2X_n & 1 &0 \\
6X_n & 2 & 0 & 0
\end{pmatrix}, \,\,\,\,
\alpha^\textrm{R}_n= \begin{pmatrix} 0 & 0\\ X_n &1 \\ -1 &0 \\ 0 & 0 \end{pmatrix}
$$ Now the preparation is complete. By arranging \(\alpha^\textrm{L}\) and \(\alpha^\textrm{R}\) appropriately into one large matrix, all conditions can be summarized as follows:$$
\begin{pmatrix}
\alpha^\textrm{L}_1 & \alpha^\textrm{R}_1 & 0 & & & & \\
0 & \alpha^\textrm{L}_2 & \alpha^\textrm{R}_2 & 0 & & \huge{0} & \\
& 0 & \alpha^\textrm{L}_3 & \alpha^\textrm{R}_3 & 0 & & \\
& & \ddots & \ddots & \ddots & \ddots & \\
& \huge{0} & & 0 & \alpha^\textrm{L}_{n-1} & \alpha^\textrm{R}_{n-1} & 0 \\
& & & & 0 & \alpha^\textrm{L}_n & \alpha^\textrm{R}_n \\
\end{pmatrix}
\begin{pmatrix}c_0 \\ d_0 \\ a_1 \\ b_1 \\ c_1 \\ d_1 \\ a_2 \\ b_2 \\ c_2 \\ d_2 \\ \vdots \\ \ a_{n-1} \\ b_{n-1} \\ c_{n-1} \\ d_{n-1} \\ c_n \\ d_n \end{pmatrix}
=
\begin{pmatrix}Y_1 \\ Y_1 \\ 0 \\ 0 \\ Y_2 \\ Y_2 \\ 0 \\ 0 \\ \vdots \\ Y_{n-1} \\ Y_{n-1} \\ 0 \\ 0 \\ Y_n \\ Y_n \\ 0 \\ 0 \end{pmatrix}$$
Although it is large, the problem is expressed as a simple matrix operation. The matrix formed by \(\alpha\) on the left-hand side is always a nonsingular matrix, so by computing its inverse and multiplying it from the left to the right-hand side, we obtain the desired parameters \(a, b, c, d\). The rest is straightforward and is omitted.