0% found this document useful (0 votes)
38 views10 pages

Lecture 11 W

Uploaded by

Như Vũ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views10 pages

Lecture 11 W

Uploaded by

Như Vũ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

144 CHAPTER 3 Interpolation and Polynomial Approximation

b. Derive the error term in Theorem 3.9. [Hint: Use the same method as in the Lagrange error
derivation, Theorem 3.3, defining

(t − x0 )2 · · · (t − xn )2
g(t) = f (t) − H2n+1 (t) − [f (x) − H2n+1 (x)]
(x − x0 )2 · · · (x − xn )2

and using the fact that g (t) has (2n + 2) distinct zeros in [a, b].]
12. Let z0 = x0 , z1 = x0 , z2 = x1 , and z3 = x1 . Form the following divided-difference table.

z0 = x0 f [z0 ] = f (x0 )
f [z0 , z1 ] = f  (x0 )
z1 = x0 f [z1 ] = f (x0 ) f [z0 , z1 , z2 ]
f [z1 , z2 ] f [z0 , z1 , z2 , z3 ]
z2 = x1 f [z2 ] = f (x1 ) f [z1 , z2 , z3 ]
f [z2 , z3 ] = f  (x1 )
z3 = x1 f [z3 ] = f (x1 )

Show that the cubic Hermite polynomial H3 (x) can also be written as f [z0 ] + f [z0 , z1 ](x − x0 ) +
f [z0 , z1 , z2 ](x − x0 )2 + f [z0 , z1 , z2 , z3 ](x − x0 )2 (x − x1 ).

3.5 Cubic Spline Interpolation1


The previous sections concerned the approximation of arbitrary functions on closed intervals
using a single polynomial. However, high-degree polynomials can oscillate erratically, that
is, a minor fluctuation over a small portion of the interval can induce large fluctuations
over the entire range. We will see a good example of this in Figure 3.14 at the end of this
section.
An alternative approach is to divide the approximation interval into a collection of
subintervals and construct a (generally) different approximating polynomial on each sub-
interval. This is called piecewise-polynomial approximation.

Piecewise-Polynomial Approximation
The simplest piecewise-polynomial approximation is piecewise-linear interpolation, which
consists of joining a set of data points

{(x0 , f (x0 )), (x1 , f (x1 )), . . . , (xn , f (xn ))}

by a series of straight lines, as shown in Figure 3.7.


A disadvantage of linear function approximation is that there is likely no differ-
entiability at the endpoints of the subintervals, which, in a geometrical context, means
that the interpolating function is not “smooth.” Often it is clear from physical condi-
tions that smoothness is required, so the approximating function must be continuously
differentiable.
An alternative procedure is to use a piecewise polynomial of Hermite type. For example,
if the values of f and of f  are known at each of the points x0 < x1 < · · · < xn , a cubic
Hermite polynomial can be used on each of the subintervals [x0 , x1 ], [x1 , x2 ], . . . , [xn−1 , xn ]
to obtain a function that has a continuous derivative on the interval [x0 , xn ].

1
The proofs of the theorems in this section rely on results in Chapter 6.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
3.5 Cubic Spline Interpolation 145

Figure 3.7

y  f (x)

x0 x1 x2 ... xj x j1 x j2 ... x n1 xn x

Isaac Jacob Schoenberg To determine the appropriate Hermite cubic polynomial on a given interval is simply
(1903–1990) developed his work a matter of computing H3 (x) for that interval. The Lagrange interpolating polynomials
on splines during World War II needed to determine H3 are of first degree, so this can be accomplished without great
while on leave from the difficulty. However, to use Hermite piecewise polynomials for general interpolation, we
University of Pennsylvania to need to know the derivative of the function being approximated, and this is frequently
work at the Army’s Ballistic
unavailable.
Research Laboratory in
The remainder of this section considers approximation using piecewise polynomials
Aberdeen, Maryland. His original
work involved numerical
that require no specific derivative information, except perhaps at the endpoints of the interval
procedures for solving on which the function is being approximated.
differential equations. The much The simplest type of differentiable piecewise-polynomial function on an entire interval
broader application of splines to [x0 , xn ] is the function obtained by fitting one quadratic polynomial between each successive
the areas of data fitting and pair of nodes. This is done by constructing a quadratic on [x0 , x1 ] agreeing with the function
computer-aided geometric design at x0 and x1 , another quadratic on [x1 , x2 ] agreeing with the function at x1 and x2 , and so
became evident with the on. A general quadratic polynomial has three arbitrary constants—the constant term, the
widespread availability of coefficient of x, and the coefficient of x 2 —and only two conditions are required to fit the
computers in the 1960s.
data at the endpoints of each subinterval. So flexibility exists that permits the quadratics to
be chosen so that the interpolant has a continuous derivative on [x0 , xn ]. The difficulty arises
because we generally need to specify conditions about the derivative of the interpolant at
the endpoints x0 and xn . There is not a sufficient number of constants to ensure that the
conditions will be satisfied. (See Exercise 26.)

The root of the word “spline” is


the same as that of splint. It was
originally a small strip of wood
Cubic Splines
that could be used to join two
The most common piecewise-polynomial approximation uses cubic polynomials between
boards. Later the word was used
each successive pair of nodes and is called cubic spline interpolation. A general cubic
to refer to a long flexible strip,
generally of metal, that could be
polynomial involves four constants, so there is sufficient flexibility in the cubic spline pro-
used to draw continuous smooth cedure to ensure that the interpolant is not only continuously differentiable on the interval,
curves by forcing the strip to pass but also has a continuous second derivative. The construction of the cubic spline does not,
through specified points and however, assume that the derivatives of the interpolant agree with those of the function it is
tracing along the curve. approximating, even at the nodes. (See Figure 3.8.)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
146 CHAPTER 3 Interpolation and Polynomial Approximation

Figure 3.8

S(x)

S n2
S n1
S1 Sj
S j1
S0
S j (x j1)  f (x j1)  S j1(x j1)
S j (x j1)  Sj1(x j1)
S j(x j1)  S j1
 (x j1)

x0 x1 x2 ... xj x j1 x j2 ... x n2 x n1 x n x

Definition 3.10 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
A natural spline has no conditions j = 0, 1, . . . , n − 1;
imposed for the direction at its
endpoints, so the curve takes the (b) Sj (xj ) = f (xj ) and Sj (xj+1 ) = f (xj+1 ) for each j = 0, 1, . . . , n − 1;
shape of a straight line after it (c) Sj+1 (xj+1 ) = Sj (xj+1 ) for each j = 0, 1, . . . , n − 2; (Implied by (b).)
passes through the interpolation 
points nearest its endpoints. The (d) Sj+1 (xj+1 ) = Sj (xj+1 ) for each j = 0, 1, . . . , n − 2;

name derives from the fact that (e) Sj+1 (xj+1 ) = Sj (xj+1 ) for each j = 0, 1, . . . , n − 2;
this is the natural shape a flexible
strip assumes if forced to pass (f) One of the following sets of boundary conditions is satisfied:
through specified interpolation
points with no additional
(i) S  (x0 ) = S  (xn ) = 0 (natural (or free) boundary);
constraints. (See Figure 3.9.) (ii) S  (x0 ) = f  (x0 ) and S  (xn ) = f  (xn ) (clamped boundary).

Although cubic splines are defined with other boundary conditions, the conditions given
in (f) are sufficient 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
Figure 3.9 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 have either the values of the derivative at the endpoints
or an accurate approximation to those values.

Example 1 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 first for the interval [1, 2], denoted

S0 (x) = a0 + b0 (x − 1) + c0 (x − 1)2 + d0 (x − 1)3 ,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
3.5 Cubic Spline Interpolation 147

and the other for [2, 3], denoted

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. Four conditions come
from the fact that the splines must agree with the data at the 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 .

Two more come from the fact that S0 (2) = S1 (2) and S0 (2) = S1 (2). These are

S0 (2) = S1 (2) : b0 + 2c0 + 3d0 = b1 and S0 (2) = S1 (2) : 2c0 + 6d0 = 2c1

The final two come from the natural boundary conditions:

S0 (1) = 0 : 2c0 = 0 and S1 (3) = 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 − 41 (x − 2)3 , for x ∈ [2, 3]

Construction of a Cubic Spline


As the preceding example demonstrates, a spline defined on an interval that is divided into n
subintervals will require determining 4n constants. To construct the cubic spline interpolant
for a given function f , the conditions in the definition are applied to the cubic polynomials

Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 ,
Clamping a spline indicates that
the ends of the flexible strip are for each j = 0, 1, . . . , n − 1. Since Sj (xj ) = aj = f (xj ), condition (c) can be applied to
fixed so that it is forced to take a
obtain
specific direction at each of its
endpoints. This is important, for
example, when two spline aj+1 = Sj+1 (xj+1 ) = Sj (xj+1 ) = aj + bj (xj+1 − xj ) + cj (xj+1 − xj )2 + dj (xj+1 − xj )3 ,
functions should match at their
endpoints. This is done for each j = 0, 1, . . . , n − 2.
mathematically by specifying the The terms xj+1 − xj are used repeatedly in this development, so it is convenient to
values of the derivative of the introduce the simpler notation
curve at the endpoints of the
spline.
hj = xj+1 − xj ,

for each j = 0, 1, . . . , n − 1. If we also define an = f (xn ), then the equation

aj+1 = aj + bj hj + cj hj2 + dj hj3 (3.15)

holds for each j = 0, 1, . . . , n − 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
148 CHAPTER 3 Interpolation and Polynomial Approximation

In a similar manner, define bn = S  (xn ) and observe that

Sj (x) = bj + 2cj (x − xj ) + 3dj (x − xj )2

implies Sj (xj ) = bj , for each j = 0, 1, . . . , n − 1. Applying condition (d) gives

bj+1 = bj + 2cj hj + 3dj hj2 , (3.16)

for each j = 0, 1, . . . , n − 1.
Another relationship between the coefficients of Sj is obtained by defining cn =
S  (xn )/2 and applying condition (e). Then, for each j = 0, 1, . . . , n − 1,

cj+1 = cj + 3dj hj . (3.17)

Solving for dj in Eq. (3.17) and substituting this value into Eqs. (3.15) and (3.16) gives,
for each j = 0, 1, . . . , n − 1, the new equations

hj2
aj+1 = aj + bj hj + (2cj + cj+1 ) (3.18)
3

and

bj+1 = bj + hj (cj + cj+1 ). (3.19)

The final relationship involving the coefficients is obtained by solving the appropriate
equation in the form of equation (3.18), first for bj ,

1 hj
bj = (aj+1 − aj ) − (2cj + cj+1 ), (3.20)
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.19), 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.21)
hj hj−1

for each j = 1, 2, . . . , n − 1. This system involves only the {cj }nj=0 as unknowns. The values
of {hj }n−1
j=0 and {aj }j=0 are given, respectively, by the spacing of the nodes {xj }j=0 and the
n n

values of f at the nodes. So once the values of {cj }j=0 are determined, it is a simple matter
n

to find the remainder of the constants {bj }n−1 j=0 from Eq. (3.20) and {dj }j=0 from Eq. (3.17).
n−1

Then we can construct the cubic polynomials {Sj (x)}n−1 j=0 .


The major question that arises in connection with this construction is whether the values
of {cj }nj=0 can be found using the system of equations given in (3.21) and, if so, whether
these values are unique. The following theorems indicate that this is the case when either of
the boundary conditions given in part (f) of the definition are imposed. The proofs of these
theorems require material from linear algebra, which is discussed in Chapter 6.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
3.5 Cubic Spline Interpolation 149

Natural Splines
Theorem 3.11 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  (a) = 0 and S  (b) = 0.

Proof The boundary conditions in this case imply that cn = S  (xn )/2 = 0 and that

0 = S  (x0 ) = 2c0 + 6d0 (x0 − x0 ),

so c0 = 0. The two equations c0 = 0 and cn = 0 together with the equations in (3.21)


produce a linear system described by the vector equation Ax = b, where A is the (n + 1) ×
(n + 1) matrix
⎡ ⎤
1 0 0 . .. .. .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0.
⎢ .... .. ⎥
⎢ .... .. ⎥
⎢h0 2(h0 + h1 ) h1 .... ⎥
⎢ .... .. ⎥
⎢ ....
.... .. ⎥
⎢ 0. . . . h1 . . . . 2(h1 .+. . h2 ) h2 . . . . . ⎥

A = ⎢ .. . . .... . .... . ....
.
. .... . . . . . . ... ⎥ ⎥,
⎢ .. . .... . .... . .... . . .... ⎥
. 0
⎢ .. . .... . .... . .. . .... ⎥
⎢. . .... . .h . . ⎥
⎢ .. . .... 2(h + h ) h ⎥
⎣. ....
n−2 n−2 n−1 n−1

0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .0. 0 1

and b and x are the vectors


⎡ ⎤
0
⎡ ⎤
⎢ 3
(a
3
− )
(a − a0 )
a − ⎥ c0
⎢ 1 h 2
h0 1 1

⎢ ⎥ ⎢ c1 ⎥
⎢ . ⎥ ⎢ ⎥
b=⎢ .. ⎥ and x = ⎢ . ⎥.
⎢ 3 ⎥ ⎣ .. ⎦
⎢ (a − a ) − 3
(a − a ) ⎥
⎣ hn−1 n n−1 hn−2 n−1 n−2 ⎦
cn
0

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. A linear
system with a matrix of this form will be shown by Theorem 6.21 in Section 6.6 to have a
unique solution for c0 , c1 , . . . , cn .

The solution to the cubic spline problem with the boundary conditions S  (x0 ) =
S  (xn ) = 0 can be obtained by applying Algorithm 3.4.

ALGORITHM Natural Cubic Spline


3.4
To construct the cubic spline interpolant S for the function f , defined at the numbers
x0 < x1 < · · · < xn , satisfying S  (x0 ) = S  (xn ) = 0:

INPUT n; x0 , x1 , . . . , xn ; a0 = f (x0 ), a1 = f (x1 ), . . . , an = f (xn ).


OUTPUT aj , bj , cj , dj for j = 0, 1, . . . , n − 1.
(Note: S(x) = Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 for xj ≤ x ≤ xj+1 .)
Step 1 For i = 0, 1, . . . , n − 1 set hi = xi+1 − xi .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
150 CHAPTER 3 Interpolation and Polynomial Approximation

Step 2 For i = 1, 2, . . . , n − 1 set


3 3
αi = (ai+1 − ai ) − (ai − ai−1 ).
hi hi−1
Step 3 Set l0 = 1; (Steps 3, 4, 5, and part of Step 6 solve a tridiagonal linear system
using a method described in Algorithm 6.7.)
μ0 = 0;
z0 = 0.
Step 4 For i = 1, 2, . . . , n − 1
set li = 2(xi+1 − xi−1 ) − hi−1 μi−1 ;
μi = hi /li ;
zi = (αi − hi−1 zi−1 )/li .
Step 5 Set ln = 1;
zn = 0;
cn = 0.
Step 6 For j = n − 1, n − 2, . . . , 0
set cj = zj − μj cj+1 ;
bj = (aj+1 − aj )/hj − hj (cj+1 + 2cj )/3;
dj = (cj+1 − cj )/(3hj ).

Step 7 OUTPUT (aj , bj , cj , dj for j = 0, 1, . . . , n − 1);


STOP.

Example 2 At the beginning of Chapter 3 we gave some Taylor polynomials to approximate the expo-
nential f (x) = ex . Use the data points (0, 1), (1, e), (2, e2 ), and (3, e3 ) to form a natural
spline S(x) that approximates f (x) = ex .

Solution We have n = 3, h0 = h1 = h2 = 1, a0 = 1, a1 = e, a2 = e2 , and a3 = e3 . So the


matrix A and the vectors b and x given in Theorem 3.11 have the forms
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
1 0 0 0 0 c0
⎢1 4 1 0⎥ ⎢ 3(e2 − 2e + 1) ⎥ ⎢ c1 ⎥
A=⎢
⎣0
⎥, b=⎢ ⎥
⎣3(e3 − 2e2 + e)⎦ , and x=⎢ ⎥
⎣c2 ⎦ .
1 4 1⎦
0 0 0 1 0 c3

The vector-matrix equation Ax = b is equivalent to the system of equations

c0 = 0,
c0 + 4c1 + c2 = 3(e2 − 2e + 1),
c1 + 4c2 + c3 = 3(e3 − 2e2 + e),
c3 = 0.

This system has the solution c0 = c3 = 0, and to 5 decimal places,

1 1 3
c1 = (−e3 + 6e2 − 9e + 4) ≈ 0.75685, and c2 = (4e − 9e2 + 6e − 1) ≈ 5.83007.
5 5

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
3.5 Cubic Spline Interpolation 151

Solving for the remaining constants gives


1 h0
b0 = (a1 − a0 ) − (c1 + 2c0 )
h0 3
1
(−e3 + 6e2 − 9e + 4) ≈ 1.46600,
= (e − 1) −
15
1 h1
b1 = (a2 − a1 ) − (c2 + 2c1 )
h1 3
1
= (e2 − e) −
(2e3 + 3e2 − 12e + 7) ≈ 2.22285,
15
1 h2
b2 = (a3 − a2 ) − (c3 + 2c2 )
h2 3
1
= (e3 − e2 ) − (8e3 − 18e2 + 12e − 2) ≈ 8.80977,
15
1 1
d0 = (c1 − c0 ) = (−e3 + 6e2 − 9e + 4) ≈ 0.25228,
3h0 15
1 1
d1 = (c2 − c1 ) = (e3 − 3e2 + 3e − 1) ≈ 1.69107,
3h1 3
and
1 1
d2 = (c3 − c1 ) = (−4e3 + 9e2 − 6e + 1) ≈ −1.94336.
3h2 15
The natural cubic spine is described piecewise by


⎨1 + 1.46600x + 0.25228x ,
3
for x ∈ [0, 1],
S(x) = 2.71828 + 2.22285(x −1) + 0.75685(x −1)2 +1.69107(x −1)3 , for x ∈ [1, 2],


7.38906 + 8.80977(x −2) + 5.83007(x −2)2 −1.94336(x −2)3 , for x ∈ [2, 3].
The spline and its agreement with f (x) = ex are shown in Figure 3.10.

Figure 3.10
y
e3

y = S(x)

y = ex

e2

e
1
1 2 3 x

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
152 CHAPTER 3 Interpolation and Polynomial Approximation

The NumericalAnalysis package can be used to create a cubic spline in a manner similar
to other constructions in this chapter. However, the CurveFitting Package in Maple can also
be used, and since this has not been discussed previously we will use it to create the natural
spline in Example 2. First we load the package with the command

with(CurveFitting)

and define the function being approximated with

f := x → ex

To create a spline we need to specify the nodes, variable, the degree, and the natural end-
points. This is done with

sn := t → Spline([[0., 1.0], [1.0, f (1.0)], [2.0, f (2.0)], [3.0, f (3.0)]], t, degree = 3,


endpoints = ‘natural’)

Maple returns

t → CurveFitting:-Spline([[0., 1.0], [1.0, f (1.0)], [2.0, f (2.0)], [3.0, f (3.0)]], t,


degree = 3, endpoints = ’natural’)

The form of the natural spline is seen with the command

sn(t)

which produces


⎨1. + 1.465998t + 0.2522848t
2 3
t < 1.0
0.495432 + 2.22285t + 0.756853(t − 1.0)2 + 1.691071(t − 1.0)3 t < 2.0


−10.230483 + 8.809770t + 5.830067(t − 2.0)2 − 1.943356(t − 2.0)3 otherwise

Once we have determined a spline approximation for a function we can use it to


approximate other properties of the function. The next illustration involves the integral
of the spline we found in the previous example.

Illustration To approximate the integral of f (x) = ex on [0, 3], which has the value

 3
ex dx = e3 − 1 ≈ 20.08553692 − 1 = 19.08553692,
0

we can piecewise integrate the spline that approximates f on this integral. This gives

 3  1
S(x) = 1 + 1.46600x + 0.25228x 3 dx
0 0
 2
+ 2.71828 + 2.22285(x − 1) + 0.75685(x − 1)2 + 1.69107(x − 1)3 dx
1
 3
+ 7.38906 + 8.80977(x − 2) + 5.83007(x − 2)2 − 1.94336(x − 2)3 dx.
2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
3.5 Cubic Spline Interpolation 153

Integrating and collecting values from like powers gives


 3  1
x2 x4
S(x) = x + 1.46600 + 0.25228
0 2 4 0
 2
(x−1)2 (x−1)3 (x−1)4
+ 2.71828(x−1) + 2.22285 + 0.75685 +1.69107
2 3 4 1
 4 3
(x−2) 2
(x−2)3
(x−2)
+ 7.38906(x−2) + 8.80977 + 5.83007 −1.94336
2 3 4 2
1
= (1 + 2.71828 + 7.38906) + (1.46600 + 2.22285 + 8.80977)
2
1 1
+ (0.75685 + 5.83007) + (0.25228 + 1.69107 − 1.94336)
3 4
= 19.55229.

Because the nodes are equally spaced in this example the integral approximation is
simply
 3
1 1 1
S(x) dx = (a0 +a1 +a2 )+ (b0 +b1 +b2 )+ (c0 +c1 +c2 )+ (d0 +d1 +d2 ). (3.22)
0 2 3 4


If we create the natural spline using Maple as described after Example 2, we can then
use Maple’s integration command to find the value in the Illustration. Simply enter
int(sn(t), t = 0 .. 3)

19.55228648

Clamped Splines
Example 3 In Example 1 we found a natural spline S that passes through the points (1, 2), (2, 3),
and (3, 5). Construct a clamped spline s through these points that has s (1) = 2 and
s (3) = 1.
Solution Let

s0 (x) = a0 + b0 (x − 1) + c0 (x − 1)2 + d0 (x − 1)3 ,

be the cubic on [1, 2] and the cubic on [2, 3] be

s1 (x) = a1 + b1 (x − 2) + c1 (x − 2)2 + d1 (x − 2)3 .

Then most of the conditions to determine the 8 constants are the same as those in Example
1. That is,

2 = f (1) = a0 , 3 = f (2) = a0 + b0 + c0 + d0 , 3 = f (2) = a1 , and


5 = f (3) = a1 + b1 + c1 + d1 .
s0 (2) = s1 (2) : b0 + 2c0 + 3d0 = b1 and s0 (2) = s1 (2) : 2c0 + 6d0 = 2c1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

You might also like