Quadratic splines.
The set of the following five data points is given:
\begin{array}{rrrrrr}x & 8 & 11 & 15 & 18 & 22 \\y & 5 & 9 & 10 & 8 & 7\end{array}(a) Determine the quadratic splines that fit the data.
(b) Determine the interpolated value of y for x=12.7.
(c) Make a plot of the data points and the interpolating polynomials.
(a) There are five points (n=5) and thus four splines (i=1, \ldots, 4). The quadratic equation for the ith spline is:
f_{i}(x)=a_{i} x^{2}+b_{i} x+c_{i}
There are four polynomials, and since each polynomial has three coefficients, a total of 12 coefficients have to be determined. The coefficients are a_{1}, b_{1}, c_{1}, a_{2}, b_{2}, c_{2}, a_{3}, b_{3}, c_{3}, a_{4}, b_{4}, and c_{4}. The coefficient a_{1} is set equal to zero (see condition 3). The other 11 coefficients are determined from a linear system of 11 equations.
Eight equations are obtained from the condition that the polynomial in each interval passes through the endpoints, Eqs. (6.67) and (6.68):
Three equations are obtained from the condition that at the interior knots the slopes (first derivative) of the polynomials from adjacent intervals are equal, Eq. (6.70).
2 a_{i-1} x_i+b_{i-1}=2 a_i x_i+b_i \quad \text { for } \quad i=2,3, \ldots, n-1 (6.70)
The system of 11 linear equations can be written in a matrix form:
\left[\begin{array}{ccccccccccc} 8 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 11 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 11^{2} & 11 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 15^{2} & 15 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 15^{2} & 15 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 18^{2} & 18 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 18^{2} & 18 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 22^{2} & 22 & 1 \\ 1 & 0 & -22 & -1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 30 & 1 & 0 & -30 & -1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 36 & 1 & 0 & -36 & -1 & 0 \end{array}\right]\left[\begin{array}{l} b_{1} \\ c_{1} \\ a_{2} \\ b_{2} \\ c_{2} \\ a_{3} \\ b_{3} \\ c_{3} \\ a_{4} \\ b_{4} \\ c_{4} \end{array}\right]=\left[\begin{array}{c} 5 \\ 9 \\ 9 \\ 10 \\ 10 \\ 8 \\ 8 \\ 7 \\ 0 \\ 0 \\ 0 \end{array}\right] (6.72)
The system in Eq. (6.72) is solved with MATLAB:
>>A= [8 1 0 0 0 0 0 0 0 0 0; 11 1 0 0 0 0 0 0 0 0 0; 0 0 11^2 11 1 0 0 0 0 0 0
0 0 15^2 15 1 0 0 0 0 0 0; 0 0 0 0 0 15^2 15 1 0 0 0; 0 0 0 0 0 18^2 18 1 0 0 0
0 0 0 0 0 0 0 0 18^2 18 1; 0 0 0 0 0 0 0 0 22^2 22 1; 1 0 -22 -1 0 0 0 0 0 0 0
0 0 30 1 0 -30 -1 0 0 0 0; 0 0 0 0 0 36 1 0 -36 -1 0];
>>B= [5; 9; 9; 10; 10; 8; 8; 7; 0; 0; 0];
>> coefficients = (A\B) '
coefficients =
1.3333 | -5.6667 | -0.2708 | 7.2917 | -38.4375 | 0.0556 | -2.5000 | 35.0000 | 0.0625 | -2.7500 | 37.2500 |
↑ | ↑ | ↑ | ↑ | ↑ | ↑ | ↑ | ↑ | ↑ | ↑ | ↑ |
b_1 | c_1 | α_1 | b_2 | c_2 | α_3 | b_3 | c_3 | α_4 | b_4 | c_4 |
With the coefficients known, the polynomials are:
(b) The interpolated value of y for x=12.7 is calculated by substituting the value of x in f_{2}(x) : f_{2}(12.7)=(-0.2708) \cdot 12.7^{2}+7.2917 \cdot 12.7-38.4375=10.4898
(c) The plot on the right shows the data points and the polynomials. The plot clearly shows that the first spline is a straight line (constant slope).