Spline
Spline
Interpolation
Definition 3.0.1 Given a function f defined on [a, b] and a set of nodes a = x0 < x1 < ... < xn = b, a
cubic spline interpolant S for f is a function that satisfies the following conditions:
a). S(x) is a cubic polynomial, denoted Sj (x), on the subinterval [xj , xj+1 ] for each j = 0, 1, ..., n − 1;
b). (interpolating data) Sj (xj ) = f (xj ) and Sj (xj+1 ) = f (xj+1 ) for each j = 0, 1, ..., n − 1;
c). (continuity at interior points) Sj+1 (xj+1 ) = Sj (xj+1 ) for each j = 0, 1, ..., n − 2; (Implied by (b).)
0
d). (continuous slope at interior points) Sj+1 (xj+1 ) = Sj0 (xj+1 ) for each j = 0, 1, ..., n − 2;
00
e). (continuous curvature at interior points) Sj+1 (xj+1 ) = Sj00 (xj+1 ) for each j = 0, 1, ..., n − 2;
f). One of the following sets of boundary conditions is satisfied:
– S 00 (x0 ) = S 00 (xn ) = 0(natural (or free) boundary);
– S 0 (x0 ) = f 0 (x0 ) and S 0 (xn ) = f 0 (xn ) (clamped boundary).
Although cubic splines are defined with other boundary conditions, the conditions given in (f ) are suf-
ficient for our purposes. When the free boundary conditions occur, the spline is called a natural spline,
and its graph approximates the shape that a long flexible rod would assume if forced to go through the
data points (x0 , f (x0 )), (x1 , f (x1 )), ..., (xn , f (xn )).
In general, clamped boundary conditions lead to more accurate approximations because they include more
information about the function. However, for this type of boundary condition to hold, it is necessary to
24
25
have either the values of the derivative at the endpoints or an accurate approximation to those values.
Construct a natural cubic spline that passes through the points (1, 2), (2, 3), and (3, 5). Solution This
spline consists of two cubics.The nodes are x0 = 1, x1 = 2, x2 = 3 and
f (x0 ) = 2, f (x1 ) = 3, f (x2 ) = 5.
This spline consists of two cubic The first for the interval [1, 2], denoted
S0 (x) = a0 + b0 (x − 1) + c0 (x − 1)2 + d0 (x − 1)3 ,
and the other for [2, 3], denoted
S1 (x) = a1 + b1 (x − 2) + c1 (x − 2)2 + d1 (x − 2)3
The cubic splines must agree with the data at the nodes:
Sj (xj ) = f (xj )
and
Sj (xj+1 ) = f (xj+1 )
for j = 0, 1. Hence we have for equations,
S0 (1) = f (1) =⇒ a0 = 2 (3.1)
S0 (2) = f (2) =⇒ a0 + b0 + c0 + d0 = 3 (3.2)
S1 (2) = f (2) =⇒ a1 = 3 (3.3)
S1 (3) = f (3) =⇒ a1 + b1 + c1 + d1 = 5 (3.4)
Now as the first derivatives at the interior nodes must be equal and the second derivatives at the interior
nodes must be equal:
S00 (2) = S10 (2) and S000 (2) = S100 (2).
Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 ,
for each j = 0, 1, ..., n − 1. Since Sj (xj ) = aj = f (xj ), condition (c) can be applied to obtain
Another relationship between the coefficients of Sj is obtained by defining cn = S 00 (xn )/2 and applying
condition (e). Then, for each j = 0, 1, ..., n − 1,
cj+1 = cj + 3dj hj . (3.11)
Solving for dj in the above Eq 3.11 and substituting this value into Eqs. 3.9 and 3.10 gives, for each
j = 0, 1, ..., n − 1, the new equations
h2j
aj+1 = aj + bj hj + (2cj + cj+1 ) (3.12)
3
and
bj+1 = bj + hj (cj + cj+1 ). (3.13)
The final relationship involving the coefficients is obtained by solving the appropriate equation in the last
form of equation 3.12, first for bj ,
1 hj
bj = (aj+1 − aj ) − (2cj + cj+1 ) (3.14)
hj 3
and then, with a reduction of the index, for bj−1 . This gives
1 hj−1
bj−1 = (aj − aj−1 ) − (2cj−1 + cj )
hj−1 3
Substituting these values into the equation derived from Eq 3.13, with the index reduced by one, gives
the linear system of equations
3 3
hj−1 cj−1 + 2(hj−1 + hj )cj + hj cj+1 = (aj+1 − aj ) − (aj − aj−1 ), (3.15)
hj hj−1
for each j = 1, 2, ..., n − 1. This system involves only the cj nj=0 as unknowns. The values of {hj }n1
j=0
and {aj }nj=0 are given, respectively, by the spacing of the nodes {xj }nj=0 and the values of f at the
nodes.So once the values of {cj }nj=0 are determined, it is a simple matter to find the remainder of the
constants {bj }n−1 n−1
j=0 from Eq. 3.14 and {dj }j=0 from Eq.3.11. Then we can construct the cubic polynomials
{Sj (x)}n−1
j=0
27
Theorem 3.0.1 If f is defined at a = x0 < x1 < ... < xn = b, then f has a unique natural spline
interpolant S on the nodes x0 , x1 , ..., xn ; that is, a spline interpolant that satisfies the natural boundary
conditions S 00 (a) = 0 and S 00 (b) = 0.
Proof 3.0.1 The boundary conditions in this case imply that cn = S 00 (xn )/2 = 0 and that
so c0 = 0. The two equations c0 = 0 and cn = 0 together with the equations in 3.13 produce a linear system
described by the vector equation Ax = b, where A is the (n + 1) × (n + 1) matrix
The matrix A is strictly diagonally dominant, that is, in each row the magnitude of the diagonal entry
exceeds the sum of the magnitudes of all the other entries in the row. Hence the proof.
Theorem 3.0.2 If f is defined at a = x0 < x1 < ... < xn = b and differentiable at a and b,then f has a
unique clamped spline interpolant S on the nodes x0 , x1 , . . . , xn ; that is, a spline interpolant that satisfies
the clamped boundary conditions S 0 (a) = f 0 (a) and S 0 (b) = f 0 (b).
Proof 3.0.2 Since f 0 (a) = S 0 (a) = S 0 (x0 ) = b0 , Eq. 3.14 with j = 0 implies
h0
f 0 (a) = 1
h0 (a1 − a0 ) − 3 (2c0 + c1 ). Consequently,
3
2h0 c0 + h0 c1 = (a1 − a0 ) − 3f 0 (a).
h0
Similarly,
f 0 (b) = bn = bn−1 + hn−1 (cn−1 + cn ),
so Eq. 3.14 with j = n − 1 implies that
an − an−1 hn−1
f 0 (b) = − (2cn−1 + cn ) + hn−1 (cn−1 + cn ) (3.16)
hn−1 3
an − an−1 hn−1
= + (cn−1 + 2cn ) (3.17)
hn−1 3
and
3
hn−1 cn−1 + 2hn−1 cn = 3f 0 (b) − (an − an−1 ).
hn−1
28 CHAPTER III. INTERPOLATION
3
2h0 c0 + h0 c1 = (a1 − a0 ) − 3f 0 (a)
h
and
3
hn−1 cn−1 + 2hn−1 cn = 3f 0 (b) − (an − an1 )
hn−1
This matrix A is also strictly diagonally dominant. Therefore, the linear system has a unique solution for
c0 , c1 , ..., cn .
Example 3.0.1 Use the data points (0, 1), (1, e), (2, e2 ), and (3, e3 ) to form a clamped spline S(x) that
approximates f (x) = ex on the interval [0, 3] . since f 0 (x) = ex ,so f 0 (0) = 1 and f 0 (3) = e3
1
c0 = (2e3 − 12e2 + 42e − 59) = 0.44468, (3.22)
15
1
c1 = (4e3 + 24e2 − 39e + 28) = 1.26548, (3.23)
15
1
c2 = (14e3 − 39e2 + 24e − 8) = 3.35087, (3.24)
15
1
c3 = (7e3 + 42e2 − 12e + 4) = 9.40815. (3.25)
15
(3.26)
S(x)=
2 3
S0 (x) = 1 + x + 0.44468x + 0.27360x ,
If x ∈ [0, 1)
S1 (x) = 2.71828 + 2.71016(x − 1) + 1.26548(x − 1)2 + 0.69513(x − 1)3 , If x ∈ [1, 2).
S2 (x) = 7.38906 + 7.32652(x − 2) + 3.35087(x − 2)2 + 2.01909(x − 2)3 , If x ∈ [2, 3].
3.0.3 Error
An error-bound formula for the cubic spline with clamped boundary conditions is given in following
theorem.
Theorem 3.0.3 Let f ∈ C 4 [a, b] with maxa≤b |f ( 4)(x)| = M. If S is the unique clamped cubic spline
interpolant to f with respect to the nodes a = x0 < x1 < ... < xn = b,then for all x ∈ [a, b],
5M
|f (x) − S(x)| ≤ max (xj+1 − xj )4 .
384 0≤j≤n−1
A fourth-order error-bound result also holds in the case of natural boundary conditions, but it is more
difficult to express.
Example 3.0.2 Let’s compute the error bound for the previous example using the Theorem. Since f (x) =
e4 , f 4 (x) = ex .Alsoex is an increasing function. Therefore maximum occurs at the right end point. Thus
M = max |f 4 (x)| = e3
0≤x≤3
max(xj+1 − xj )4 = 1.
Thus,
5M 5e3
|f (x) − S(x)| ≤ max (xj+1 − xj )4 = (1) = 0.26153.
384 0≤j≤n−1 384