Jump to content

Cubic Spline Interpolation

From Wikiversity

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

[edit | edit source]

Given a set of n + 1 data points (xi,yi) where no two xi are the same and a=x0<x1<<xn=b, the spline S(x) is a function satisfying:

  1. S(x)C2[a,b];
  2. On each subinterval [xi1,xi],S(x) is a polynomial of degree 3, where i=1,,n.
  3. S(xi)=yi, for all i=0,1,,n.


Let us assume that

S(x)={C1(x),x0xx1Ci(x),xi1<xxiCn(x),xn1<xxn

where each Ci=ai+bix+cix2+dix3(di0) is a cubic function, i=1,,n.

Boundary Conditions

[edit | edit source]

To determine this cubic spline S(x), we need to determine ai,bi,ci and di for each i by:

  • Ci(xi1)=yi1 and Ci(xi)=yi, i=1,,n.
  • Ci'(xi)=Ci+1'(xi), i=1,,n1.
  • Ci'(xi)=Ci+1'(xi), i=1,,n1.

We can see that there are n+n+(n1)+(n1)=4n2 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:

  1. First derivatives at the endpoints are known:
    C1'(x0)=f0', and Cn'(xn)=fn'.
    This is called clamped boundary conditions.
  2. Second derivatives at the endpoints are known:
    C1'(x0)=f0', and Cn'(xn)=fn'.
    The special case C1'(x0)=Cn'(xn)=0 is called natural or simple boundary conditions.
  3. When the exact function f(x) is a periodic function with period xnx0, S(x) is a periodic function with period xnx0 too. Thus
    C1(x0)=Cn(xn),C1'(x0)=Cn'(xn), and C1'(x0)=Cn'(xn).
    The spline functions S(x) satisfying this type of boundary condition are called periodic splines.

Methods

[edit | edit source]

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 computers can do it quite well.

The algorithm given in 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 Cubic Hermite spline, this gives us the spline in Hermite form.


Here, we discuss another method using second derivatives S(xi)=Mi(i=0,1,,n) to find the expression for spline S(x).

Let hi=xixi1, i=1,,n, S(xi)=C'i(xi)=C'i+1(xi)=Mi(i=1,,n1) and S(x0)=C'1(x0)=M0, and S(xn)=C'n(xn)=Mn. Note that Mi's are unknown (except for type II boundary condition, M0 and Mn are given).

Since each Ci is a cubic polynomial, C'i is linear.

By Lagrange interpolation, we can interpolate each C'i on [xi1,xi] since C'i(xi1)=Mi1 and C'i(xi)=Mi, the Lagrange form of this interpolating polynomial is:

C'i(x)=Mi1xixhi+Mixxi1hi for x[xi1,xi].

Integrating the above equation twice and using the condition that Ci(xi1)=yi1 and Ci(xi)=yi to determine the constants of integration, we have

Ci(x)=Mi1(xix)36hi+Mi(xxi1)36hi+(yi1Mi1hi26)xixhi+(yiMihi26)xxi1hiforx[xi1,xi].

 

 

 

 

(1)

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

For i=1,,n1, when x[xi,xi+1],, we can calculate that

C'i+1(x)=Mi(xi+1x)22hi+1+Mi+1(xxi)22hi+1+yi+1yihi+1Mi+1Mi6hi+1.

Therefore, C'i+1(xi)=Mihi+12+yi+1yihi+1Mi+1Mi6hi+1.

Similarly, when x[xi1,xi],, we can shift the index to obtain

C'i(x)=Mi1(xix)22hi+Mi(xxi1)22hi+yiyi1hiMiMi16hi.

 

 

 

 

(2)

Thus, C'i(xi)=Mihi2+yiyi1hiMiMi16hi.

Since C'i+1(xi)=C'i(xi), we can derive

μiMi1+2Mi+λiMi+1=difori=1,2,,n1,

 

 

 

 

(3)

where

μi=hihi+hi+1,λi=1μi=hi+1hi+hi+1,anddi=6f[xi1,xi,xi+1]

 

 

 

 

(4)

and f[xi1,xi,xi+1] is a divided difference.

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

I. For type I boundary condition, we are given C'1(x0)=f'0 and C'n(xn)=f'n. According to equation (2), we can obtain

C'1(x0)=M0(x1x0)22h1+M1(x0x0)22h1+y1y0h1M1M06h1.
f'0=M0h12+f[x0,x1]M1M06h1
2M0+M1=6h1(f[x0,x1]f'0)=6f[x0,x0,x1].

 

 

 

 

(5.1)

Similarly, simplifying

C'n(xn)=Mn1(xnxn)22hn+Mn(xnxn1)22hn+ynyn1hnMnMn16hn

we will have

Mn1+2Mn=6hn(f'nf[xn1,xn])=6f[xn1,xn,xn+1].

 

 

 

 

(5.2)

Therefore, let λ0=μn=1,d0=6f[x0,x0,x1] and dn=6f[xn1,xn,xn], combine (3), (5.1) and (5.2) together, so the system of equations that we need to solve is

[2λ0μ12λ1μn12λn1μn2][M0M1Mn1Mn]=[d0d1dn1dn].

 

 

 

 

(6)

II. For type II boundary condition, we are given

M0=f'0 and Mn=f'n

 

 

 

 

(7)

directly, so let λ0=μn=0, d0=2f'0, and dn=2f'n, and we need to solve the system of equations in the same form as (6).

Example

[edit | edit source]

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

[edit | edit source]

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
M0=

and M3=

.
Also, we have
λ0=

, μ3=

, d0=

and d3=

.
Same as the above example, we have
λ1=λ2=μ1=μ2=

and
d1=

and d2=

.


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

[edit | edit source]

Polynomial and Spline Interpolation, http://www.ohiouniversityfaculty.com/youngt/IntNumMeth/lecture19.pdf

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