Cubic Spline Interpolation

From testwiki
Jump to navigation Jump to search

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

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: Template:Ordered list

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 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 Template:NumBlk 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 Template:NumBlk Thus, C'i(xi)=Mihi2+yiyi1hiMiMi16hi.

Since C'i+1(xi)=C'i(xi), we can derive Template:NumBlk where Template:NumBlk 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 (Template:EquationNote), we can obtain

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

Template:NumBlk

Similarly, simplifying

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

we will have Template:NumBlk

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

II. For type II boundary condition, we are given Template:NumBlk 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 (Template:EquationNote).

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

<quiz display=simple> { |type="{}"} 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= { -0.3 } and M3= { 3.3 }.

Also, we have

λ0= { 0.0 }, μ3= { 0.0 }, d0= { -0.6 } and d3= { 6.6 }.

Same as the above example, we have

λ1=λ2=μ1=μ2= { 0.5 } and

d1= { 3 } and d2= { -6 }. </quiz>

Therefore, we can construct the system of equations:

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

File:Spline xg.jpg
Figure 1: Interpolating Cubic Splines

References

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

数值分析,李庆扬,王能超,易大易,2001. Template:ISBN (Numerical Analysis, Qinyang Li, Nengchao Wang, Dayi yi.)