Question 6.7: Quadratic splines. The set of the following five data points......

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.

The 'Blue Check Mark' means that either the MATLAB code/script/answer provided in the answer section has been tested by our team of experts; or the answer in general has be fact checked.

Learn more on how do we answer questions.

Script File

(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):

\begin{aligned} & a_i x_i^2+b_i x_i+c_i=y_i \quad \text { for } \quad i=1,2, \ldots, n-1 & \qquad (6.67) \\ & a_i x_{i+1}^2+b_i x_{i+1}+c_i=y_{i+1} \quad \text { for } \quad i=1,2, \ldots, n-1 & \qquad (6.68) \end{aligned}
\begin{array}{ll} i=1 & f_{1}(x)=a_{1} x_{1}^{2}+b_{1} x_{1}+c_{1}=b_{1} 8+c_{1}=5 \\ & f_{1}(x)=a_{1} x_{2}^{2}+b_{1} x_{2}+c_{1}=b_{1} 11+c_{1}=9 \\ i=2 & f_{2}(x)=a_{2} x_{2}^{2}+b_{2} x_{2}+c_{2}=a_{2} 11^{2}+b_{2} 11+c_{2}=9 \\ & f_{2}(x)=a_{2} x_{3}^{2}+b_{2} x_{3}+c_{2}=a_{2} 15^{2}+b_{2} 15+c_{2}=10 \\ i=3 & f_{3}(x)=a_{3} x_{3}^{2}+b_{3} x_{3}+c_{3}=a_{3} 15^{2}+b_{3} 15+c_{3}=10 \\ & f_{3}(x)=a_{3} x_{4}^{2}+b_{3} x_{4}+c_{3}=a_{3} 18^{2}+b_{3} 18+c_{3}=8 \\ i=4 & f_{4}(x)=a_{4} x_{4}^{2}+b_{4} x_{4}+c_{4}=a_{4} 18^{2}+b_{4} 18+c_{4}=8 \\ & f_{4}(x)=a_{4} x_{5}^{2}+b_{4} x_{5}+c_{4}=a_{4} 22^{2}+b_{4} 22+c_{4}=7 \end{array}

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)

\begin{aligned} & i=2 \quad 2 a_{1} x_{2}+b_{1}=2 a_{2} x_{2}+b_{2} \longrightarrow b_{1}=2 a_{2} 11+b_{2} \quad \text { or: } \quad b_{1}-2 a_{2} 11-b_{2}=0 \\ & i=3 \quad 2 a_{2} x_{3}+b_{2}=2 a_{3} x_{3}+b_{3} \longrightarrow 2 a_{2} 15+b_{2}=2 a_{3} 15+b_{3} \quad \text { or: } \quad 2 a_{2} 15+b_{2}-2 a_{3} 15-b_{3}=0 \\ & i=4 \quad 2 a_{3} x_{4}+b_{3}=2 a_{4} x_{4}+b_{4} \longrightarrow 2 a_{3} 18+b_{3}=2 a_{4} 18+b_{4} \quad \text { or: } \quad 2 a_{3} 18+b_{3}-2 a_{4} 18-b_{4}=0 \end{aligned}

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:

\begin{aligned} & f_{1}(x)=1.333 x-5.6667 \text { for } 8 \leq x \leq 11, \quad f_{2}(x)=(-0.2708) x^{2}+7.2917 x-38.4375 \text { for } 11 \leq x \leq 15 \\ & f_{3}(x)=0.0556 x^{2}-2.5 x+35 \text { for } 15 \leq x \leq 18, \quad f_{4}(x)=0.0625 x^{2}-2.75 x+37.25 \text { for } 18 \leq x \leq 22 \end{aligned}

(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).

6.7

Related Answered Questions