# 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[edit]

Given a set of *n + 1* data points (*x*_{i},*y*_{i}) where no two *x*_{i} are the same and , the spline *S(x)* is a function satisfying:

- ;
- On each subinterval is a polynomial of degree 3, where
- for all

Let us assume that

where each is a cubic function, .

## Boundary Conditions[edit]

To determine this cubic spline *S(x)*, we need to determine for each *i* by:

- and ,
- ,
- ,

We can see that there are conditions, but we need to determine 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:

- .

This is called clamped boundary conditions.

II. Second derivatives at the endpoints are known:

- .

The special case is called natural or simple boundary conditions.

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

- .

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

## Methods[edit]

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 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 to find the expression for spline *S(x)*.

Let , , and . Note that 's are unknown (except for type II boundary condition, are given).

Since each is a cubic polynomial, is linear.

By w:Lagrange interpolation, we can interpolate each on since and , the Lagrange form of this interpolating polynomial is:

- for .

Integrating the above equation twice and using the condition that

and to determine the constants of integration, we have**String Module Error: function rep expects a number as second parameter, received "**

**"****(**)**String Module Error: function rep expects a number as second parameter, received "**

**"**

This expression gives us the cubic spline *S(x)* if can be determined.

For when , we can calculate that

Therefore,

Similarly, when , we can shift the index to obtain**String Module Error: function rep expects a number as second parameter, received "**

**"****(**)**String Module Error: function rep expects a number as second parameter, received "**

**"**

Thus,

Since , we can derive**String Module Error: function rep expects a number as second parameter, received "**

**"****(**)**String Module Error: function rep expects a number as second parameter, received "**

**"**
where**String Module Error: function rep expects a number as second parameter, received "**

**"****(**)**String Module Error: function rep expects a number as second parameter, received "**

**"**

and is a divided difference.

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

**I.** For type I boundary condition, we are given and . According to equation (**2**
), we can obtain

**String Module Error: function rep expects a number as second parameter, received "****"**

. **(**)**String Module Error: function rep expects a number as second parameter, received "**

**"**

Similarly, simplifying

we will have**String Module Error: function rep expects a number as second parameter, received "**

**"**. **(**)**String Module Error: function rep expects a number as second parameter, received "**

**"**

Therefore, let and , combine (**3**
), (**5.1**
) and (**5.2**
) together, so

the system of equations that we need to solve is**String Module Error: function rep expects a number as second parameter, received "**

**"****(**)**String Module Error: function rep expects a number as second parameter, received "**

**"**
**II.** For type II boundary condition, we are given**String Module Error: function rep expects a number as second parameter, received "**

**"**and **(**)**String Module Error: function rep expects a number as second parameter, received "**

**"**

directly, so let , , and , and we need to solve the system of equations in the same form as (**6**
).

## Example[edit]

For points (0,0), (1,0.5), (2,2) and (3,1.5), find the interpolating cubic spline satisfying and .

Solution:

We can easily see that for so and

Also, since this is the type I boundary condition problem, we can calculate that

- and

Therefore, plug into the system of equations, we have

The solution is and

Therefore, by the general expression of the solution, we have

Similarly,

- and

Thus the cubic spline is

## Exercise[edit]

Therefore, we can construct the system of equations:

Solution:

Since and , we can find the solution:

- and .

Plug these into the general expression for cubic spline and simplify, we can obtain

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

## References[edit]

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