Docsity

Cubic Spline Interpolation - Lecture Notes | PHYS 6720, Study notes of Physics

Toggle sidebar
bg1
Physics 6720 – Cubic Spline Interpolation – October 30, 2002
Splines and particularly cubic splines are very popular models for interpo-
lation. Historically, a “spline” was a common drafting tool, a flexible rod, that
was used to help draw smooth curves connecting widely spaced points. The
cubic spline curve accomplishes the same result for an interpolation problem.
In these notes we describe cubic splines and discuss their use in interpolation
and curve fitting. Many texts give the algorithms for determining the spline
coefficients, so we do not do that here.
1 Cubic Spline Interpolation
We start from a table of points [xi, yi] for i= 0,1, . . . , n for the function
y=f(x). That makes n+ 1 points and nintervals between them. The cubic
spline interpolation is a piecewise continuous curve, passing through each of
the values in the table. There is a separate cubic polynomial for each interval,
each with its own coefficients:
Si(x) = ai(x−xi)3+bi(x−xi)2+ci(x−xi) + difor x∈[xi, xi+1].
together, these polynomial segments are denoted S(x), the spline.
Since there are nintervals and four coefficients for each we require a total
of 4nparameters to define the spline S(x). We need to find 4nindependent
conditions to fix them. We get two conditions for each interval from the
requirement that the cubic polynomial match the values of the table at both
ends of the interval:
Si(xi) = yi, Si(xi+1) = yi+1 .
Notice that these conditions result in a piecewise continuous function.
We still need 2nmore conditions. Since we would like to make the interpo-
lation as smooth as possible, we require that the first and second derivatives
also be continuous:
S0
i−1(xi) = S0
i(xi), S00
i−1(xi) = S00
i(xi).
These conditions apply for i= 1,2, . . . , n −1, resulting in 2(n−1) constraints.
So we need two more conditions to completely fix the spline. There are some
standard choices left to the user:
1. “natural” S00
0(x0) = 0, S00
n−1(xn) = 0
1
pf3

Partial preview of the text

Download Cubic Spline Interpolation - Lecture Notes | PHYS 6720 and more Study notes Physics in PDF only on Docsity!

Physics 6720 – Cubic Spline Interpolation – October 30, 2002

Splines and particularly cubic splines are very popular models for interpo- lation. Historically, a “spline” was a common drafting tool, a flexible rod, that was used to help draw smooth curves connecting widely spaced points. The cubic spline curve accomplishes the same result for an interpolation problem. In these notes we describe cubic splines and discuss their use in interpolation and curve fitting. Many texts give the algorithms for determining the spline coefficients, so we do not do that here.

1 Cubic Spline Interpolation

We start from a table of points [xi, yi] for i = 0, 1 ,... , n for the function y = f(x). That makes n + 1 points and n intervals between them. The cubic spline interpolation is a piecewise continuous curve, passing through each of the values in the table. There is a separate cubic polynomial for each interval, each with its own coefficients:

Si(x) = ai(x − xi)^3 + bi(x − xi)^2 + ci(x − xi) + di for x ∈ [xi, xi+1].

together, these polynomial segments are denoted S(x), the spline. Since there are n intervals and four coefficients for each we require a total of 4n parameters to define the spline S(x). We need to find 4n independent conditions to fix them. We get two conditions for each interval from the requirement that the cubic polynomial match the values of the table at both ends of the interval:

Si(xi) = yi, Si(xi+1) = yi+1.

Notice that these conditions result in a piecewise continuous function. We still need 2n more conditions. Since we would like to make the interpo- lation as smooth as possible, we require that the first and second derivatives also be continuous:

S i′− 1 (xi) = S i′(xi), S i′′− 1 (xi) = S i′′ (xi).

These conditions apply for i = 1, 2 ,... , n − 1, resulting in 2(n − 1) constraints. So we need two more conditions to completely fix the spline. There are some standard choices left to the user:

  1. “natural” S 0 ′′ (x 0 ) = 0, S n′′− 1 (xn) = 0
  1. “clamped” S′ 0 (x 0 ) = f ′(x 0 ), S n′− 1 (xn) = f ′(xn)

Other choices are possible if the function is periodic. Which is best depends on the application. With 4n coefficients and 4n linear conditions it is straightforward to work out the equations that determine them. The conditions can be reduced easily to a tridiagonal system with the coefficients ci as the unknowns. Once solved, the remaining coefficients are easily determined. There are many good codes in the public domain. Cubic splines are popular because they are easy to implement and produce a curve that appears to be seamless. As we have seen, a straight polynomial interpolation of evenly spaced data tends to build in distortions near the edges of the table. Cubic splines avoid this problem, but they are only piecewise continuous, meaning that a sufficiently high derivative (third) is discontinous. So if the application is sensitive to the smoothness of derivatives higher than second, cubic splines may not be the best choice.

2 Cubic Spline Smoothing

When interpolating we start from reasonably exact tabulated values and re- quire that the interpolating function pass exactly through the values. In curve fitting we generally start with a table of experimental data in which the yi val- ues are imperfectly known, so come with a confidence interval [yi − σi, yi + σi], and we require that the fitting function come only reasonably close to the data. The table of experimental data consists of three columns [xi, yi, σi], with the last value specifying the confidence range (commonly one standard deviation). In cubic spline fitting we relax the requirement that the spline pass exactly through the points and demand only that the spline and its first and second derivatives be continuous:

Si− 1 (xi) = Si(xi), S i′− 1 (xi) = S′ i(xi), S i′′− 1 (xi) = S i′′ (xi).

So continuity still leaves n + 3 degrees of freedom. They are determined by balancing two opposing criteria:

  1. The spline must come reasonably close to the data.
  2. The spline must have low curvature.