Cubic Spline Interpolation

Cubic spline interpolation is a special case for Spline interpolation that is used very often to avoid the problem of Runge's phenomenon. This method gives an interpolating polynomial that is smoother and has smaller error than some other interpolating polynomials such as Lagrange polynomial and Newton polynomial.


Definition

Given a set of n + 1 data points (xi,yi) where no two xi are the same and a=x_0<x_1<\cdots<x_n=b, the spline S(x) is a function satisfying:

  1. S(x)\in C^2[a,b];
  2. On each subinterval [x_{i-1},x_{i}], S(x) is a polynomial of degree 3, where i=1,\cdots,n.
  3. S(x_i)=y_i, for all i=0,1,\cdots,n.


Let us assume that

S(x)=\left\{\begin{array}{rl}
C_1(x), & x_0 \leq x \leq x_1\\
\cdots &\\
C_i(x), & x_{i-1} < x \leq x_i\\
\cdots &\\
C_n(x), & x_{n-1} < x \leq x_n\end{array}\right.

where each C_i=a_i+b_ix+c_ix^2+d_ix^3 (d_i \neq 0) is a cubic function, i=1,\cdots,n..

Boundary Conditions

To determine this cubic spline S(x), we need to determine a_i, b_i, c_i \mbox{ and } d_i for each i by:

We can see that there are n+n+(n-1)+(n-1)=4n-2 conditions, but we need to determine 4n coefficients, so usually we add two boundary conditions to solve this problem.


There are three types of common boundary conditions:

I. First derivatives at the endpoints are known:

C'_1(x_{0})=f'_0, \mbox{ and } C^'_{n}(x_{n})=f'_n.

The special case C'_1(x_{0})=C^'_{n}(x_{n})=0 is called clamped boundary conditions.

II. Second derivatives at the endpoints are known:

C^{''}_1(x_{0})=f^{''}_0, \mbox{ and } C^{''}_{n}(x_{n})=f^{''}_n .

The special case C^{''}_1(x_{0})=C^{''}_{n}(x_{n})=0 is called natural or simple boundary conditions.

III. When the exact function f(x) is a periodic function with period x_n-x_0, S(x) is a periodic function with period x_n-x_0 too. Thus

C_1(x_{0})=C_n(x_{n}), C'_1(x_{0})=C'_n(x_{n}), \mbox{ and } C^{''}_1(x_{0})=C^{''}_n(x_{n}).

The spline functions S(x) satisfying this type of boundary condition are called periodic splines.

Methods

There are several methods that can be used to find the spline function S(x) according to its corresponding conditions. Since there are 4n coefficients to determine with 4n conditions, we can easily plug the values we know into the 4n conditions and then solve the system of equations. Note that all the equations are linear with respect to the coefficients, so this is workable and computer can do it quite well.

The algorithm given in w:Spline interpolation is also a method by solving the system of equations to obtain the cubic function in the symmetrical form.

The other method used quite often is w:Cubic Hermite spline, this gives us the spline in w:Hermite form.


Here, we discuss another method using second derivatives S''(x_i)=M_i (i=0,1,\cdots,n) to find the expression for spline S(x).

Let h_i=x_{i}-x_{i-1}, i=1,\cdots,n, S''(x_i)=C''_i(x_i)=C''_{i+1}(x_i)=M_i (i=1,\cdots,n-1) and S''(x_0)=C''_1(x_0)=M_0, \mbox{ and } S''(x_n)=C''_n(x_n)=M_n. Note that M_i's are unknown (except for type II boundary condition, M_0 \mbox{ and } M_n are given).

Since each C_i is a cubic polynomial, C''_i is linear.

By w:Lagrange interpolation, we can interpolate each C''_i on [x_{i-1},x_i] since C''_i(x_{i-1})=M_{i-1} and C''_i(x_{i})=M_{i}, the Lagrange form of this interpolating polynomial is:

C''_i(x)=M_{i-1}\frac{x_{i}-x}{h_i}+M_i\frac{x-x_{i-1}}{h_i} for x\in [x_{i-1},x_i].

Integrating the above equation twice and using the condition that C_i(x_{i-1})=y_{i-1} and C_i(x_{i})=y_{i} to determine the constants of integration, we have

C_i(x)=M_{i-1}\frac{(x_i-x)^3}{6h_i}+M_i\frac{(x-x_{i-1})^3}{6h_i}+(y_{i-1}-\frac{M_{i-1}h_i^2}{6})\frac{x_i-x}{h_i}+(y_{i}-\frac{M_{i}h_i^2}{6})\frac{x-x_{i-1}}{h_i}\quad\text{for}\quad x\in [x_{i-1},x_i].

 

 

 

 

(1 )

This expression gives us the cubic spline S(x) if M_i, i=0,1,\cdots,n can be determined.

For i=1,\cdots,n-1, when x\in [x_{i},x_{i+1}],, we can calculate that

C'_{i+1}(x)=-M_i\frac{(x_{i+1}-x)^2}{2h_{i+1}}+M_{i+1}\frac{(x-x_i)^2}{2h_{i+1}}+\frac{y_{i+1}-y_i}{h_{i+1}}-\frac{M_{i+1}-M_i}{6}h_{i+1}.

Therefore, C'_{i+1}(x_i)=-M_i\frac{h_{i+1}}{2}+\frac{y_{i+1}-y_i}{h_{i+1}}-\frac{M_{i+1}-M_i}{6}h_{i+1}.

Similarly, when x\in [x_{i-1},x_{i}],, we can shift the index to obtain

C'_{i}(x)=-M_{i-1}\frac{(x_{i}-x)^2}{2h_{i}}+M_{i}\frac{(x-x_{i-1})^2}{2h_{i}}+\frac{y_{i}-y_{i-1}}{h_{i}}-\frac{M_{i}-M_{i-1}}{6}h_{i}.

 

 

 

 

(2 )

Thus, C'_{i}(x_i)=M_i\frac{h_{i}}{2}+\frac{y_{i}-y_{i-1}}{h_{i}}-\frac{M_{i}-M_{i-1}}{6}h_{i}.

Since C'_{i+1}(x_i)=C'_{i}(x_i), we can derive

 \mu_i M_{i-1}+2 M_i+\lambda_i M_{i+1}=d_i\quad\text{for}\quad i=1,2,\cdots,n-1,

 

 

 

 

(3 )

where

\mu_i=\frac{h_i}{h_{i}+h_{i+1}},\quad \lambda_i=1-\mu_i=\frac{h_{i+1}}{h_{i}+h_{i+1}},\quad\text{and}\quad d_i=6 f[x_{i-1},x_i,x_{i+1}]\,

 

 

 

 

(4 )

and f[x_{i-1},x_i,x_{i+1}] is a divided difference.

According to different boundary conditions, we can solve the system of equations above to obtain the values of M_i's.

I. For type I boundary condition, we are given C'_1(x_0)=f'_0 and C'_n(x_n)=f'_n. According to equation (2 ), we can obtain

C'_{1}(x_0)=-M_{0}\frac{(x_{1}-x_0)^2}{2h_{1}}+M_{1}\frac{(x_0-x_{0})^2}{2h_{1}}+\frac{y_{1}-y_{0}}{h_{1}}-\frac{M_{1}-M_{0}}{6}h_{1}.
\Rightarrow f'_0=-M_{0}\frac{h_1}{2}+f[x_0,x_1]-\frac{M_{1}-M_{0}}{6}h_{1}

\Rightarrow 2M_{0}+M_{1}= \frac{6}{h_1}(f[x_0,x_1]-f'_0)=6f[x_0,x_0,x_1].

 

 

 

 

(5.1 )

Similarly, simplifying

C'_{n}(x_n)=-M_{n-1}\frac{(x_{n}-x_n)^2}{2h_{n}}+M_{n}\frac{(x_n-x_{n-1})^2}{2h_{n}}+\frac{y_{n}-y_{n-1}}{h_{n}}-\frac{M_{n}-M_{n-1}}{6}h_{n}

we will have

M_{n-1}+2M_{n}= \frac{6}{h_n}(f'_n-f[x_{n-1},x_n])=6f[x_{n-1},x_n,x_{n}].

 

 

 

 

(5.2 )

Therefore, let \lambda_0=\mu_n=1, d_0=6f[x_0,x_0,x_1] and d_n=6f[x_{n-1},x_n,x_n], combine (3 ), (5.1 ) and (5.2 ) together, so the system of equations that we need to solve is

\left[\begin{array}{ccccccc}
2 & \lambda_0 & & & & & \\
\mu_1 & 2 & \lambda_1 & & & & \\
 & \ddots & \ddots & \ddots & & &\\
& & \ddots & \ddots & \ddots & & \\
& & & \ddots & \ddots & \ddots & \\
& & & &\mu_{n-1} & 2 & \lambda_{n-1}\\
& & & & & \mu_n & 2
\end{array} \right]
\left[\begin{array}{c}
M_0 \\
M_1 \\
\vdots\\
\vdots\\
\vdots\\
M_{n-1}\\
M_n\end{array} \right]= 
\left[\begin{array}{c}
d_0 \\
d_1 \\
\vdots\\
\vdots\\
\vdots\\
d_{n-1}\\
d_n\end{array} \right].

 

 

 

 

(6 )

II. For type II boundary condition, we are given

M_0=f''_0 and M_n=f''_n

 

 

 

 

(7 )

directly, so let \lambda_0=\mu_n=0, d_0=2f''_0, and d_n=2f''_n, and we need to solve the system of equations in the same form as (6 ).

Example

For points (0,0), (1,0.5), (2,2) and (3,1.5), find the interpolating cubic spline S(x) satisfying S'(0)=0.2 and S'(3)=-1.

Exercise

1.

For points (0,0), (1,0.5), (2,2) and (3,1.5), find the interpolating cubic spline S(x) satisfying S''(0)=-0.3 and S''(3)=3.3.
Since this is the type II boundary condition, we use
M_0= and M_3= .
Also, we have
\lambda_0= , \mu_3= , d_0= and d_3= .
Same as the above example, we have
\lambda_1=\lambda_2=\mu_1=\mu_2= and
d_1= and d_2= .

Your score is 0 / 0

Therefore, we can construct the system of equations:

You can see the difference of the two cubic splines in Figure 1.

Figure 1: Interpolating Cubic Splines

References

Polynomial and Spline Interpolation, http://www.math.ohiou.edu/courses/math3600/lecture19.pdf

数值分析,李庆扬,王能超,易大易,2001. ISBN 7-302-04561-5 (Numerical Analysis, Qinyang Li, Nengchao Wang, Dayi yi.)

This article is issued from Wikiversity - version of the Friday, March 11, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.