Professional Documents
Culture Documents
Lecture4 (Piecewise Interpolation)
Lecture4 (Piecewise Interpolation)
BISHNU P. LAMICHHANE
Let Sl (∆) be the space of all pieceise-linear functions with respect to ∆. One can show that
University of Newcastle, School of Mathematical & Physical Sciences, Mathematics Building V, University
Drive, Callaghan, NSW 2308, Australia, Bishnu.Lamichhane@newcastle.edu.au.
1
2 BISHNU P. LAMICHHANE
The function S(x) is called a cubic spline interpolant. We first count the number of un-
known coefficients and number of conditions in the interpolation problem:
(1) A cubic polynomial has 4 coefficients, and thus there are 4n coefficients of the cubic
polynomial (4 on each interval [xi , xi+1 ], i = 0, 1, 2, · · · , n.)
(2) There are n + 1 interpolating conditions and n − 1 continuity conditions for S, S0 and
S00 . Thus there are 3(n − 1) continuity conditions. Hence, we have a total of 4n − 2
conditions for 4n unknown coefficients.
Depending on the choice of remaining two conditions, we can construct various interpolating
cubic splines. The most popular cubic spline is the natural cubic spline, which is defined as
follows.
Definition 2. The natural cubic spline is the cubic spline interpolant satisfying the end
conditions
S00 (x0 ) = S00 (xn ) = 0.
Now we prove that the two additional conditions uniquely determine S2 .
Example 1. Construct a natural cubic spline that passess through the points (1, 2), (2, 3), and
(3, 5).
Solution: This spline consists of two cubics. The first for the interval [1, 2], denoted by
S0 (x) = a0 + b0 (x − 1) + c0 (x − 1)2 + d0 (x − 1)3 ,
and the other for [2, 3], denoted by
S1 (x) = a1 + b1 (x − 2) + c1 (x − 2)2 + d1 (x − 2)3 .
There are 8 constants to be determined, which requires 8 conditions. We have four conditions
from the fact that the splines must agree with the data at nodes. Hence
2 = f (1) = a0 , 3 = f (2) = a0 + b0 + c0 + d0 , 3 = f (2) = a1 , and
5 = f (3) = a1 + b1 + c1 + d1 .
We have two conditions from the fact that S00 (2) = S10 (2), and S000 (2) = S100 (2). They give
S00 (2) = S10 (2) : b0 + 2c0 + 3d0 = b1 , and S000 (2) = S100 (2) : 2c0 + 6d0 = 2c1 .
4 BISHNU P. LAMICHHANE
The final two conditions come from the natural boundary conditions :
S000 (1) = 0 : 2c0 = 0, and S100 (3) = 0 : 2c1 + 6d1 = 0.
Eliminating c0 , a1 and a0 , we have a linear system for {b0 , b1 , c1 , d0 , d1 }:
b0 + d0 = 3 − 2 = 1
b1 + c1 + d1 = 5 − 3 = 2
b0 + 3d0 − b1 = 0
6d0 − 2c1 = 0
2c1 + 6d1 = 0.
Solving this system of equations gives the spline
(
2 + 43 (x − 1) + 41 (x − 1)3 , for x ∈ [1, 2]
S(x) =
3 + 23 (x − 2) + 43 (x − 2)2 − 14 (x − 2)3 , for x ∈ [2, 3].
Construction of the Natural Cubic Spline. We know that we have to determine 4n coeffi-
cients to define the cubic spline interpolant. We now apply the conditions in the definition to
compute the cubic polynomial S j (x) for each j = 0, 1, · · · , n − 1:
S j (x) = y j + b j (x − x j ) + c j (x − x j )2 + d j (x − x j )3
so that condition (1) and (2) are applied once. We now apply condition (3) to obtain
y j+1 = S j+1 (x j+1 ) = y j + b j (x j+1 − x j ) + c j (x j+1 − x j )2 + d j (x j+1 − x j )3
for each j = 0, 1, · · · , n − 2. Let h j = x j+1 − x j for j = 0, 1, · · · , n − 1. Then
y j+1 = y j + b j h j + c j h2j + d j h3j
for each j = 0, 1, · · · , n − 1. The case j = n − 1 is included as yn = Sn−1 (xn ) = yn−1 +
bn−1 hn−1 + cn−1 h2n−1 + dn−1 h3n−1 .
Similarly, differentiating S j (x) with respect to x, we have
S0j (x) = b j + 2c j (x − x j ) + 3d j (x − x j )2
which implies that S0j (x j ) = b j for each j = 0, 1, · · · , n − 1. Now defining bn = S0 (xn ) =
Sn−1 (xn ), we apply condition (4) S0j+1 (x j+1 ) = S0j (x j+1 ) to get
b j+1 = b j + 2c j h j + 3d j h2j
for each j = 0, 1, · · · , n − 1.
We want to find another relationship between the coefficients of S j by defining cn =
S (xn )/2 and applying the condition (5) S j+1 (x j+1 ) = S00j (x j+1 ) . Then, for each j =
00 00
0, 1, · · · , n − 1
c j+1 − c j
c j+1 = c j + 3d j h j or d j = .
3h j
Using the value of d j in the expression for y j+1 and b j+1 yields
h2j
(1) y j+1 = y j + b j h j + (2c j + c j+1 ) and b j+1 = b j + h j (c j + c j+1 ).
3
INTERPOLATION 5
for each j = 0, 1, · · · , n − 1 This system has {c j }nj=0 unknowns. Since the values {x j }nj=0 and
{y j }nj=0 are given, once we find the coefficients {c j }nj=0 , we can obtain {b j }nj=0 and {d j }nj=0
from the equations
y j+1 − y j h j c j+1 − c j
bj = − (2c j + c j+1 ) and dj = .
hj 3 3h j
Thus we can construct the cubic polynomials {S j (x)}nj=0 . To show that the piecewise cubic
polynomial is unique, we need the following definition.
|aii | ≥ ∑ |ai j |, i = 1, 2, · · · , n.
j=1
j6=i
Theorem 2. Let f be defined at each point of the set ∆ = {a = x0 < x1 < · · · < xn = b} of
[a, b] with yi = f (xi ), 0 ≤ i ≤ n. Then f has a unique natural cubic spline interpolant on the
set ∆; that is, a spline interpolant that satisfies the natural boundary conditions S00 (x0 ) = 0
and S00 (xn ) = 0.
Thus c0 = cn = 0. The two equations c0 = cn = 0 together with the equations in (2) can be
written as a linear system Ac = f, where A is n + 1 × n + 1 matrix
1 0 0 0 ··· 0 0 0
h0 2(h0 + h1 )
h1 0 ··· 0 0 0
0 h1 2(h1 + h2 ) h2 · · · 0 0 0
A = .. ,
.. .. .. . .
.
. . . . 0 0 0
0 0 0 0 · · · hn−2 2(hn−2 + hn−1 ) hn−1
0 0 0 0 ··· 0 0 1
and f and c are two vectors with
0 c0
3 3
(y
h1 2 − y 1 ) − h0 (y1 − y0 )
c1
f= .. c= ..
and .
. .
3 3
hn−1 (yn − yn−1 ) − hn−2 (yn−1 − yn−2 )
cn−1
0 cn
Since the matrix A is strictly diagonal dominant, the matrix A is non-singular and hence the
linear system Ac = f has a unique solution.
Example 2. Piecewise Cubic Hermite Interpolating Polynomial: Assume that no derivatives
are provided at the nodes, but only function values. A piecewise cubic polynomial can be
constructed also in this case assigning some suitable derivatives of the function at the nodes.
The derivatives are assigned in such a way that the resulting piecewise curve is continu-
ously differentiable. One such example can be found in [2] and is used in piecewise cubic
interpolation of M ATLAB. The derivatives zi are assigned in such a way that the function
is continuously differentiable and function values do not locally overshoot the data values
resulting in a shape-preserving, “visually pleasing” interpolant. Let di be defined as
yi+1 − yi
di = , i = 0, . . . , n − 1.
xi+1 − xi
For an inner point xi , if di and di−1 are of opposite signs or if either of them is zero, xi is
the local extremum. Thus zi is set to be zero. If di and di−1 have the same sign and the two
intervals (xi−1 , xi ) and (xi , xi+1 ) have the same length, then zi is taken to be the harmonic
mean of the two discrete slopes:
1 1 1 1
= + .
zi 2 di−1 di
That means at the support node xi , the reciprocal slope of the Hermite interpolant is the
average of the reciprocal slopes of the piecewise linear interpolant on either side.
If di and di−1 have the same sign, but the two intervals have different lengths, then zi is set
to be a weighted harmonic mean of the two discrete slopes
1 1 w1 w2
= +
zi w1 + w2 di−1 di
with w1 = 2hi + hi−1 and w2 = hi + 2hi−1 , hi = xi+1 − xi . Further modification is necessary at
the end points, see [2] for more detail.
INTERPOLATION 7
R EFERENCES
[1] R.L. Burden and J.D. Faires. Numerical Analysis. Brooks and Cole, eighth edition, 2005.
[2] F.N. Fritsch and R.E. Carlson. Monotone piecewise cubic interpolation. SIAM Journal on Numerical Analy-
sis, 17:238–246, 1980.