Chapter 4
Chapter 4
Chapter 4
POLYNOMIAL INTERPOLATION
AND SPLINES DATA FITTING
Nabil R. Nassif and Dolly K. Fayad
April 2010
Introduction
(1)
We assume that this data represents an unknown function y = f (x), such that
yi = f (xi ). Our basic objective in this chapter is to look for a suitable and
convenient polynomial approximation of the function f allowing to obtain
f (x), x 6= xi , and that takes on the corresponding values of yi for each of the
n + 1 distinct xi s in Dn . Such a polynomial is said to interpolate the data
Dn , and the points xi are called nodes of the interpolation.
An interpolating polynomial can be written in a variety of forms. Among these,
are known the Lagrange, the Newton and the Neville forms that we shall consider consecutively in this chapter.
Assume we are given the set (??), with increasing x-data, i.e. x0 < x1 <
... < xn . Let also hi = xi xi1 , i 1. We state now the basic Lagrange
Interpolation theorem.
Theorem 1 There exists a unique polynomial of degree less than or equal to n,
pn (x) = p01...n (x), such that pn (xi ) = yi , i = 0, 1, ..., n.
Proof. The proof of this theorem is based on the Lagrangian cardinal basis
associated with Dn given by:
Ln = {li (x) : 0 i n}
where the cardinal functions li are special polynomials of degree n in IPn
(set of all polynomials of degree less than or equal to n). They are defined as
follows:
Q
(x x0 )(x x1 )...(x xi1 )(x xi+1 )...(x xn )
0j6=in (x xj )
=
li (x) = Q
(x
x
)
(x
i
j
i x0 )(xi x1 )...(xi xi1 )(xi xi+1 )...(xi xn )
0j6=in
(2)
Once the cardinal functions (??) are available, we can interpolate any function
f by Lagrange form of the interpolation polynomial:
p01...n (x) =
n
X
li (x)f (xi ).
(3)
i=0
Obviously then, the following properties are satisfied by the defined polynomials:
2
- li (xj ) = ij =
0 if i 6= j
1 if i = j
- p01...n (xi ) = yi i = 0, 1, . . . , n
The definition of the Lagrange polynomial above is enough to establish the
existence part of Theorem ??.
To establish the uniqueness of such a polynomial p01...n , we suppose that another
polynomial q of degree at most n, claims to accomplish what p does; that is q
also satisfies q(xi ) = yi for 0 i n. Then the polynomial (p01...n q) is of
degree at most n and takes on the value 0 at x0 , x1 , . . . , xn . Recall however
that a non-zero polynomial of degree n can have at most n roots. We conclude
then that (p01...n q) = 0, and that p01...n = q, which establishes the uniqueness
of p01...n .
Example 1 Write out the cardinal functions appropriate to the problem of interpolating the following data D2 = { (1/4, 1), (1/3, 2), (1, 7)}.
Using equation (??), we have:
(x 31 )(x 1)
1
= 16(x )(x 1)
1
1 1
3
( 4 3 )( 4 1)
l0 (x) =
l1 (x) =
(x 14 )(x 1)
1
= 18(x )(x 1)
4
( 13 41 )( 13 1)
(x 31 )(x 14 )
1
1
1
1 = 2(x 3 )(x 4 )
(1 3 )(1 4 )
Therefore, the interpolating polynomial in Lagranges form is:
1
1
1
1
349
79
p012 (x) = 36(x )(x1)16(x )(x1)+14(x )(x ) = 38x2 +
x
4
3
3
4
6
6
This form of the polynomial might be useful in computing f (x) in the vicinity
of the nodes 1/3, 1/4, 1.
l2 (x) =
Example 2 Consider the following table of data associated with the function
f (x) = log(x).
i
0
1
2
3
4
5
xi
1.0
1.5
2.0
3.0
3.5
4.0
yi
0
0.17609
0.30103
0.47712
0.54407
0.60206
3
x 1.5
x 1.0
+ 0.17609
1.0 1.5
1.5 1.0
(x 1.5)(x 2)
+
(1.0 1.5)(1.0 2)
(x 1.0)(x 1.5)
(x 1.0)(x 2)
+ 0.30103
(1.5 1.0)(1.5 2)
(2 1.0)(2 1.5)
Thus p012 (1.2) = 0.076574, which practically remains correct up to 1 significant figure, although the relative error of 3.292757102 < 0.51012 .
- Cubic interpolation based on the points {x0 , x1 , x2 , x3 }.
To implement a 3rd degree interpolation, we may repeat the process and
construct the consequent cardinal Lagrangian basis in IP3 , {l1 , l2 , l3 } leading to a cubic interpolating polynomial.
Note that p01...k (x) with k < n, cannot be obtained from p01...k1 (x). The
cardinal functions of the latter are in Pk1 , while those of the former are polynomials in Pk .
3.1
p0 (x) = a0
p01 (x) = a0 + a1 (x x0 )
p012 (x) = a0 + a1 (x x0 ) + a2 (x x0 )(x x1 )
(n)
n
X
i=0
ai
i1
Y
(x xj )
j=0
For example, solving the equations above we obtain the following values:
(0)
a0 = y0
(1)
y1 = y0 + a1 (x1 x0 ) a1 =
(2)
y2 = y0 +
y1 y0
x1 x0
y1 y0
(x1 x0 )+a2 (x2 x0 )(x2 x1 ) a2 =
x1 x0
y2 y1
x2 x1
y1 y0
x1 x0
x2 x0
..
.
We see that a0 depends on f (x0 ), that a1 depends on f (x0 ) and f (x1 ), and
in general that ak depends on f (x0 ), f (x1 ), . . . f (xk ). We write then ak =
f [x0 , x1 , . . . , xk ], or equivalently ak = [x0 , x1 , . . . , xk ].
This new parameter ak is called the divided difference of order k for f .
It is defined as follows:
Definition 1 Given the set of data {(xi , yi = f (xi )| i = 0, 1, . . . , n} with
xi 6= xj for i 6= j,
- The 0th order divided difference is [xi ] = yi i = 0, 1, . . . , n.
- The 1st order divided difference is [xi , xi+1 ] =
yi+1 yi
xi+1 xi .
And recursively,
- The k th order divided difference is [xi , xi+1 , . . . , xi+k ] =
n
X
i=0
ai
i1
Y
(x xj ) =
j=0
n
i1
X
Y
[x0 , x1 , . . . , xi ]
(x xj )
i=0
(4)
j=0
Equivalently:
p01...n (x) = [x0 ] + [x0 , x1 ](x x0 ) + [x0 , x1 , x2 ](x x0 )(x x1 ) +
+[x0 , x1 , x2 , . . . , xn ](x x0 )(x x1 ) . . . (x xn1 )
Note also that the divided difference is invariant with respect to the permutation of indices, that is:
3.2
D5 = {(1, 0) , (1.5, 0.17609) , (2.0, 0.30103) , (3, 0.47712) , (3.5, 0.54407) , (4, 0.60206)}.
i
0
xi
1.0
yi
0
1.5
0.17609
[., .]
[., ., .]
[., ., ., .]
[., ., ., ., .]
[., ., ., ., ., .]
0.35218
0.1023
0.24988
2
2.0
0.02655
0.0492
0.30103
0.17609
3.0
0.47712
3.5
0.54407
4.0
0.60206
0.006404
0.01054
0.02813
0.13390
0.001411
0.002172
0.00511
0.01792
0.11598
Let us consider approximations of f (x) for values of x at the top of the table,
for example x = 1.2, then at the middle of the table, as x = 2.5.(In general, one
can prove that the approximation-error is smaller for mid-values of x).
Relative error
1.10446 101
3.2928 102
1.6833 102
9.845 103
6.30384 103
act value of the function for values of x at the top of the table.
In order to get approximations to f (2.5), and using Theorem ??, we obtain successively linear, quadratic and cubic polynomials as follows:
p23 (x) = y2 + [x2 , x3 ](x x2 )
p231 (x) = p23 (x) + [x2 , x3 , x1 ](x x2 )(x x3 )
= p23 (x) + [x1 , x2 , x3 ](x x2 )(x x3 )
p2314 (x) = p231 (x) + [x2 , x3 , x1 , x4 ](x x2 )(x x3 )(x x1 )
= p231 (x) + [x1 , x2 , x3 , x4 ](x x2 )(x x3 )(x x1 )
p2310 (x) = p231 (x) + [x2 , x3 , x1 , x0 ](x x2 )(x x3 )(x x1 )
= p231 (x) + [x0 , x1 , x2 , x3 ](x x2 )(x x3 )(x x1 )
Another alternative starting with p23 would be:
p234 (x) = p23 (x) + [x2 , x3 , x4 ](x x2 )(x x3 )
p2345 (x) = p234 (x) + [x2 , x3 , x4 , x5 ](x x2 )(x x3 )(x x4 )
p2341 (x) = p234 (x) + [x2 , x3 , x4 , x1 ](x x2 )(x x3 )(x x4 )
= p234 (x) + [x1 , x2 , x3 , x4 ](x x2 )(x x3 )(x x4 )
This process can be carried through to obtain higher order interpolation
polynomials.
Numerically one gets the following results for the approximation of log(2.5) =
0.39794001:
p... (2.5)
Value
p23 (x)
0.389075
p234 (x) 0.3961067
p231 (x) 0.4013733
p2345 (x) 0.3973825
p2341 (x)
0.39874
Relative error
2.227725 102
4.6070814 103
8.62774435 103
1.4009867 103
2.0103315 103
3.3
i = 0, 1..., n k
k yi
.
hk k!
(5)
Proof. The proof is done by induction on k. After verifying the result for
k = 1, assume that it is true for 1, ..., k 1, i.e.:
[xi , xi+1 , ..., xi+k1 ] =
k1 yi
.
hk1 (k 1)!
Since,
[xi , xi+1 , ..., xi+k ] =
then:
[xi , xi+1 , ..., xi+k ] =
k1 yi+1 k1 yi
k1 yi+1 k1 yi
=
.
hk1 (k 1)!(xi+k xi )
hk1 (k 1)! kh
Since, by definition:
k yi k1 yi+1 k1 yi ,
one reaches the required identity.
10
n y 0
y0
2 y 0
(xx0 )(xx1 )+ +
(xx0 )(xx1 ) . . . (xxn1 )
(xx0 )+
2
1!h
2!h
n!hn
The result of the above theorem allows us therefore to compute divided difference tables by simply computing first differences as follows:
i
0
xi
x0
yi
y0
y0 = y1 y0
1
x1
x2
n2
xn2
yn2
n1
xn1
yn1
xn
yn
..
.
3 y0 = 2 y1 2 y0
y1 = y2 y1
y2 = y3 y2
x3
..
.
y2
3
..
.
2 y0 = y1 y0
y1
y1 = y2 y1
..
.
..
.
y3
..
.
..
.
..
.
..
.
..
.
..
.
..
.
n y 0
11
..
.
Example 3 The following data are associated with 0-th order Bessels function
of the first kind.
i
0
1
2
3
4
xi
1.0
1.3
1.6
1.9
2.2
yi
0.7651977
0.6200860
0.4554022
0.2818186
0.1103623
Since the x-data are equally space with h = 0.3, the differences table can be
easily constructed out of this data:
i
0
xi
1.0
yi
0.7651977
1.3
0.6200860
y0 = 0.1451117
2 y0 = 0.0195721
3 y0 = 0.0106723
y1 = 0.1646838
2
1.6
y2 = 0.1735836
3
1.9
0.2818186
2.2
0.1103623
4 y0 = 0.0003548
y1 = 0.0088998
0.4554022
y1 = 0.0110271
2 y2 = 0.0021273
y3 = 0.1714563
Using this table, we may subsequently write any of the interpolation polynomials. For example:
p234 (x) = y2 +
y2
0.3 (x
x2 ) +
= 0.4554022
2 y2
(0.3)2 2! (x
0.1735836
(x
0.3
x2 )(x x3 )
1.6) +
0.0021273
(0.3)2 (x
1.6)(x 1.9)
p231 (x) = p23 (x)+[x2 , x3 , x1 ](xx2 )(xx3 ) = p23 (x)+[x1 , x2 , x3 ](xx2 )(xx3 )
2
y1
0.0088998
= p23 (x) + (0.3)
2 2! (x x2 )(x x3 ) = p23 (x) (0.3)2 2! (x 1.6)(1 1.9)
Another method for obtaining a polynomial interpolant from some set of data
Dn is given by Neville. It starts building the polynomial in steps, just as Newtons polynomial does. The polynomials are defined ecursively as follows:
12
i+1
xi
xi+1 xi pi (x)
In generalfor i < j:
xx
i
pi,j (x) = xxx
pj (x) xj xji pi (x)
j xi
- Quadratic Nevilles
polynomials
xxi+2
xxi
p
(x)
pi,i+1 (x)
pi,i+1,i+2 (x)
p0,1 (x)
p1,2 (x)
p2,3 (x)
p3,4 (x)
p0,1,2 (x)
p1,2,3 (x)
p2,3,4 (x)
...
xi
x0
x1
x2
x3
x4
pi (x)
p0 (x)
p1 (x)
p2 (x)
p3 (x)
p4 (x)
...
xn
...
...
...
pn (x) pn1,n (x) pn2,n1,n (x)
...
...
pi,i+1,...,i+n (x)
...
p0,1,...,n (x)
For example,
0
1
p01 (x) = xxx
p1 (x) xxx
p0 (x)
x
x
1
0
1
0
1
3
p1,2,3 = xxx
p2,3 (x) xxx
p1,2 (x)
3 x1
3 x1
13
When a function f is approximated on an interval [a, b] by means of an interpolating polynomial pn , a natural expectation is that the function be well
approximated at all intermediate points between the nodes, and that as the
number of nodes increases, this agreement will become better and better. Nevertheless, this expectation is wrong and ill-founded.
A theoretical estimate is derived in ([?], page 189) and leads to the following
result:
Theorem 4 Let f be a function in C n+1 [a, b], and pn the Lagrange polynomial
of degree at most n, that interpolates f based on the set of data Dn . Then there
exists c (a, b) such that:
f (x) pn (x) = wn (x)
f (n+1) (c)
,
(n + 1)!
14
max
n 5x+5
|f (x) pn (x)| = .
In a more advanced study of this topic, it could be proved that the divergence
of the polynomials can often be ascribed to the fact that the nodes are equally
spaced, which contrary to intuition, is usually a very poor choice in interpolation.
A much better choice leading to more accurate results, is for example the set of
Chebyshev nodes:
2i + 1
] , 0 i n
xi = cos[
2n + 2
This problem motivates the use of local piecewise polynomial interpolation as
in what follows.
6.1
16
xi
1.0
1.3
1.6
1.9
2.2
yi
7.6
2.0
4.5
2.8
11
1. Determine the linear spline function interpolating D4 , and plot its graph.
2. Interpolate f (1.4)
1. Given that si (x) = yi +
yi+1 yi
xi+1 xi (x
xi ):
s0 (x) = y0 +
y1 y0
x1 x0 (x
x0 ) = 7.6 18.6(x 1)
s1 (x) = y1 +
y2 y1
x2 x1 (x
x1 ) = 2 + 8.3(x 1.3)
s2 (x) = y2 +
y3 y2
x3 x2 (x
s3 (x) = y3 +
y4 y3
x4 x3 (x
6.2
Splines of degree higher than 1 are more complicated. As for linear splines ,
quadratic splines are not often used for interpolation, due to the lack of smoothness, . The discussion here is provided mainly as a preparation for the study of
higher order and more accurate spline interpolation.
17
4. s(xi ) = yi , i = 0, 1, ..., n.
Remark 3 In brief, a quadratic spline interpolating the data Dn , is a continuously differentiable piecewise quadratic function which consists of n separate
quadratic functions of the form si (x) = ai x2 + bi x + ci , one for each subinterval
[xi , xi+1 ], created by the n + 1 nodes. Thus, we start with a total of 3n unknown
coefficients. On each of these n subintervals, si must satisfy the interpolation
conditions si (xi ) = yi and si (xi+1 ) = yi+1 , for i = 0, 1, ...n 1 which imposes
2n conditions. (Obviously, the continuity of s does not add any additional condition). Furthermore, the continuity of s0 at each of the interior nodes, gives
n 1 more conditions. Thus we have a total of 2n + (n 1) = 3n 1 conditions,
or 1 condition short of the 3n conditions required. There is a variety of ways to
impose this additional condition, for example by fixing:
s0 (x0 ) = 0, or s0 (x0 ) = [x0 , x1 ] =
y1 y0
x1 x0
(6)
We now derive the equations for the interpolating quadratic spline s(x) systematically. In this view, let us introduce a new set of unknowns:
zi = s0 (xi ), for i = 0, 1, ...n
Since s0i IP1 , Newtons formula can be applied on the subinterval [xi , xi+1 ],
giving specifically:
s0i (x) = zi +
zi+1 zi
(x xi ), i = 0, 1, ..n 1
xi+1 xi
zi+1 zi (x xi )2
xi+1 xi
2
(7)
zi+1 zi (xi+1 xi )2
xi+1 xi
2
zi+1 zi hi+1 2
hi+1
2
yi+1 yi
zi+1 + zi
=
, i = 0, 1, ..., n 1.
hi+1
2
18
(8)
where [xi , xi+1 ], is the set of first order divided differences associated with
the data Dn .
It suffices then to get back si (x) from equation (??), and therefore the
quadratic spline s(x) on [a, b].
19
0
Compute z0 = xy11 y
x0 (or set z0 = 0 for Natural spline)
Compute zi with zi+1 = zi + 2[xi , xi+1 ]y , i = 0, 1, ..., n 1
Seek i such that x (xi , xi+1 )
2
i+1 zi (xxi )
, i = 0, 1, ..., n 1
Evaluate si (x) = yi + zi (x xi ) + xzi+1
xi
2
6.3
The 1st and 2nd degree splines discussed in the preceding sections suffer an
obvious imperfection: their lower order derivatives are discontinuous.
- In the case of the linear splines, the lack of smoothness of the polygonal
line is evident, because the slope of the spline may change abruptly at
each node.
- For the quadratic splines, the discontinuity is in the 2nd derivative, and is
therefore not so evident; nevertheless, the curvature of the spline changes
abruptly at each node, and the curve may not be pleasing to the eye.
The cubic splines are most frequently used in applications. It can be proved
that in a certain precise sense, the cubic spline function is the best interpolation
function available. In this case, we join cubic polynomials together in such a way
that the resulting spline function has 2 continuous derivatives everywhere. At
20
each interior node 3 conditions will be imposed, so that the graph of the function
will look smooth. Discontinuities, of course, may occur in the 3rd derivative,
but cannot be easily detected visually.
Given the data Dn , Cubic splines are defined as follows:
Definition 5 A cubic spline that interpolates the data Dn , is a function s(x)
such that:
1. s(x) is globally continuous on [a, b], (s C([a, b]), the set of all continuous
functions on [a, b]).
2. s0 (x) is globally continuous on [a, b], (s0 C([a, b])).
3. s00 (x) is globally continuous on [a, b], (s00 C([a, b])).
4. s(x)|x[xi ,xi+1 ] = si (x), where si (x) is a polynomial of degree at most 3 ,
i.e.
si IP 3 , i = 0, 1, ..., n 1.
5. s(xi ) = yi , i = 0, 1, ..., n.
A cubic spline is therefore a twice continuously differentiable piecewise cubic
function. We start by counting the number of conditions available and the
number of unknown coefficients needed to determine s(x):
Since a cubic polynomial on the interval [xi , xi+1 ] written in its standard form
ai x3 + bi x2 + ci x + di has 4 unknown coefficients, a total of 4n coefficients are
then required. As for the interpolation conditions imposed, we have specified
that within each subinterval the interpolating polynomial must go through 2
points: si (xi ) = yi and si (xi+1 ) = yi+1 , which gives 2n conditions. The 1st
and 2nd derivatives must be continuous at the n 1 interior nodes, which adds
2(n 1) more conditions. In order to get the same number of imposed conditions and sought coefficients, we impose (for example), the natural spline
conditions s00 (x0 ) = s00 (xn ) = 0, yielding then a total of 2n + 2(n 1) + 2 = 4n
conditions.
Thus, to determine the spline s(x), let us introduce 2 new sets of unknowns:
{zi = s0 (xi )}, and {wi = s00 (xi )}, for i = 0, 1, ..., n. These 2 sets represent respectively the sets of slopes and moments at the nodes xi for all i = 0, 1, ..., n.
wi+1 wi
(x xi ), i = 0, 1, ..., n 1
xi+1 xi
21
(9)
wi+1 wi (x xi )2
, i = 0, 1, ..., n 1 (10)
xi+1 xi
2
wi+1 wi (xi+1 xi )2
, i = 0, 1, ..., n 1.
xi+1 xi
2
This yields:
zi+1 zi
wi+1 + wi
, i = 0, 1, ..., n 1.
=
hi+1
2
(11)
Given the value of z0 calculated later on, the sequence {zi } can be found
from the following recurrence relation, once the sequence {wi } has been
found.
wi + wi+1
, i = 1, ..., n 1.
(12)
zi+1 = zi + hi+1
2
A second integration from xi to x of equation (??) yields the cubic polynomials {si (x)} where {zi } and {wi } are still undetermined:
si (x) = yi +zi (xxi )+wi
(x xi )2 wi+1 wi
+
(xxi )3 , i = 0, 1, ..., n1
2
6hi+1
(13)
(wi+1 wi )h2i+1
h2i+1
+
, i = 0, 1, ..., n 1
2
6
Writing also this last equation on the 2 consecutive intervals [xi , xi+1 ] and
[xi1 , xi ], leads to 2 simultaneous equations written at each internal node
of the spline, i.e. for all i = 1, .., n 1:
(
yi+1 yi
= zi + (wi+1 + 2wi ) hi+1
hi+1
6
yi yi1
hi
=
z
+
(w
+
2w
)
i1
i
i1
hi
6
Subtracting these last 2 equations and using (??) gives:
[xi , xi+1 ] [xi1 , xi ] = hi
wi1 + wi
(wi+1 + 2wi )
(wi + 2wi1 )
+ hi+1
hi
2
6
6
22
Since the 2nd order divided difference associated with the data Dn is,
][xi1 ,xi ]
[xi1 , xi , xi+1 ] = [xi ,xxi+1
, then the preceding equation is also
i+1 xi1
written as follows:
hi
hi + hi+1
hi+1
wi1 +
wi +
wi+1 = (hi +hi+1 )[xi1 , xi , xi+1 ], i = 1, 2, ..., n1.
6
3
6
This provides therefore a system of n 1 equations in n + 1 unknowns
{wi }ni = 0. Adding also the 2 natural splines conditions imposed (w0 = wn = 0),
we reach then a system of n 1 equations in n 1 unknowns given by:
Aw = r,
where the matrix A is:
(h1 + h2 )/3
h2 /6
0
h
/6
(h
+
h
)/3
h
2
2
3
3 /6
0
h
/6
(h
+
h4 )/3
A=
3
3
0
0
h4 /6
0
...
...
(14)
0
0
h4 /6
...
0
0
0
0
...
...
...
...
...
...
...
0
0
0
...
...
...
...
...
...
hn1 /6
0
0
0
hn1 /6
(hn1 + hn )/3
n1n1
6.4
2/3 1/6 0
0...
1/6 2/3 1/6 0..
...
...
...
...
0
...
0
1/6
0
0
...
...
2/3
i +yi1
Since also [xi1 , xi , xi+1 ]y = yi+1 2y
, the right hand side r simplifies, and
2h2
the system (??) becomes:
w1
2/3 1/6
0
0...
0
y2 2y1 + y0
y3 2y2 + y1
... 1
0
.
y4 2y3 + y2
=
h
...
...
...
... ... h
...
......
...
...
...
...
... ...
yn 2yn1 + yn2
wn1
0
...
0
1/6 2/3
6.5
2/3 1/6
0
0...
1/6 2/3 1/6 0..
0
1/6 2/3 1/6
...
...
...
...
...
...
...
...
0
...
0
1/6
0
0
0..
...
...
2/3
w1
w2
...
...
...
wn1
1
=
h2
y2 2y1 + y0
y3 2y2 + y1
y4 2y3 + y2
...
...
yn 2yn1 + yn2
a1 b1
0
0...
0
w1
r1
c1 a2
b2
0..
0
w2 r2
0 c2
a3
b3
0.. ... ...
,
... ...
...
...
...
... ...
... ... cN 2 aN 1 bN 1 ... ...
0 ...
0
cN 1
aN
wN
rN
24
where the diagonal entry of the matrix A are generated by the vector ai : 1
i N and the upper and lower diagonal ones being respectively obtained
from bi , ci : 1 i N 1 satisfying the following properties:
|ai | > |bi | + |ci1 | : 2 i N 1
|a1 | > |b1 |, |aN | > |cN 1 |
The following algorithm solves this given system:
function w=SolveTridiag(a,b,c,r)
% N is the dimension of a and r
% N-1 is the dimension of b and c
% Start with the Gauss reduction process
for k=1:N-1
m=c(k)/a(k);
a(k+1)=a(k+1)-m*b(k);
r(k+1)=r(k+1)-m*r(k);
end
% Obtain the solution w by back-substitution
for k=N:-1:1
w(k)=r(k)/a(k);
if k>1
r(k-1)=r(k-1)-w(k)*b(k-1);
end
end
This algorithm takes 2N 1 divisions, 3(N 1) multiplications and as many
algebraic additions, thus a total of 8N 7 flops.
25
6.6
The steps for computing the natural cubic spline are as follows:
1. Obtain w, the vector of moments by solving (??):
(a) Generate r
(b) Generate A
(c) Perform Gauss Reduction on [A r]
(d) Perform back substitution on reduced system to get w.
2. Obtain z the vector of slopes by solving (refwz1)
zi+1 = zi + hi+1
wi + wi+1
, i = 1, ..., n,
2
wi+1 wi
(x xi )2
+
(x xi )3 .
2
6hi+1
26
6.7
From ([?], pages 14 and 61) , we can state the following convergence result:
Theorem 5 Let f be a function in C k+1 [a, b], and Sk the Spline Function ,
that interpolates f based on the set of data Dn , where k = 1, 2, 3. Then,
max |f (x) Sk (x)| Ck hk+1 max |f (k+1) (x)|
[a,b]
[a,b]
27
PROBLEMS
Polynomial Interpolation
1. Use the Lagrange interpolation process to obtain a polynomial of least degree that satisfies the following set of data: D3 = {(0, 7), (2, 11), (3, 28), (4, 63)}.
2. For the four interpolation nodes 1, 1, 3, 4, what are the li functions required in the Lagrange interpolation procedure ? Draw the graphs of these
functions to show their essential properties. Use Lagrange interpolation
form to obtain a polynomial of least degree that satisfies the following set
of data: D3 = {(1, 1), (1, 0), (3, 2), (4, 3)}.
3. Write the Lagrange form of the interpolating polynomial of degree 2
that interpolates f (x) at x0 , x1 and x2 , where x0 < x1 < x2 .
4. Given the data
D4 = {(1, 1), (2, 1/3), (2.5, 3/32), (3, 4/3), (4, 25)}
(a) Construct the divided difference table.
(b) Use the best quadratic then cubic Newtons interpolating polynomial, to find an approximation to f (2.9).
5. Write Newtons interpolating polynomial for the data shown:
{(0, 7), (2, 11), (3, 28), (4, 63)}
6. Using a difference table, derive the polynomial of least degree that assumes
the values 2, 14, 4, 2 and 2 respectively for x = 2, 1, 0, 1 and 2. Use that
result, to find a polynomial that takes the values shown and has at x = 3
the value 10.
7. The polynomial p(x) = x4 x3 + x2 x + 1 satisfies the following set of
data
i xi yi
0 2 31
1 1 5
2 0
1
3 1
1
4 2 11
5 3 61
28
xi yi
2 31
1 5
0
1
1
1
2 11
3 30
8. Construct a divided difference (or difference) table based on the two given
sets of data in the preceding exercise, then use Newtons polynomials of
all orders (1,2, 3, 4 and 5) to approximate f (2.5), in each case.
9. Create the table of all Nevilles polynomials in P4 satisfying the following
set of data:
i xi
yi
0 1.0 1.5
1 2.0 0.5
2 2.5 0.0
3 3.0 0.5
4 4.0 1.5
10. Determine by two methods the polynomial of degree 2 or less whose graph
passes through the points (0, 1.1), (1, 2), and (2, 4.2). Verify that they are
the same.
11. Let f (x) = x3 + 2x2 + x + 1. Find the polynomial of degree 4 that interpolates the values of f at x = 2, 1, 0, 1, 2. Find the polynomial of
degree 2 that interpolates the values of f at x = 1, 0, 1.
Spline Interpolation
12. Determine whether each of the following functions is a first degree spline,
and plot its graph.
(a)
S(x) =
x ; 1 x 0
1 x; 0 x < 1
2x 2 ; 1 x 2
(b)
S(x) =
x ; 1 x 0.5
0.5x + 2(x 0.5) ; 0.5 x 2
x + 1.5 ; 2 x 4
29
13. Determine the linear spline function s(x) interpolating the set of data D3
and plot its graph. Interpolate f (2.4).
D3 = {(0, 1); (1.5, 3); (2, 5); (3, 2)}
14. Is S(x) = |x| a first degree spline ? Why or why not ?
15. Find the natural quadratic spline interpolant for the following data
(a)
x
1
0
1/2
1
2
5/2
y
2
1
0
1
2
3
x
1
2
5/2
3
4
y
2
1
0
1
3
(b)
16. Are these functions quadratic splines ? Explain why or why not ?Plot
their graphs.
(a)
Q(x) =
x2 ; 0 x 1
x ; 0 x 100
(b)
x ; 50 x 1
x2 ; 1 x 2
Q(x) =
4 ; 2 x 50
17. Do there exist a,b, c and d so that the function
x ; 10 x 1
ax3 + bx2 + cx + d ; 1 x 1
S(x) =
x ; 1 x 10
is a natural cubic spline function ?
30
x + 1 ; 2 x 1
ax3 + bx2 + cx + d ; 1 x 1
S(x) =
x 1; 1 x 2
is a natural cubic spline function ? Why or why not ?
19. Determine the natural cubic spline that interpolates the function f (x) =
x6 over the interval [0, 2] using nodes 0, 1 and 2 .
20. Find the natural cubic spline interpolant for this table
x
1
2
3
4
5
y
0
1
0
1
0
21. Find the natural cubic spline interpolant for this table
x
1
2
3
4
5
6
y
0
1
0
1
0
1
22. Give an example of a cubic spline with nodes 0, 1, 2, and 3 that is quadratic
in [0, 1], cubic in [1, 2], and quadratic in [2, 3].
23. Give an example of a cubic spline with nodes 0, 1, 2, and 3 that is linear
in [0, 1], but of degree 3 in the other two intervals.
24. List all the ways in which the following functions fail to be natural cubic
splines:
(a)
S(x) =
x + 1 ; 2 x 1
x3 2x + 1 ; 1 x 1
x 1; 1 x 2
(b)
S(x) =
x3 + x 1 ; 1 x 0
x3 x 1 ; 0 x 1
31
32
References
[1] CHENEY, W., KINCAID D., Numerical Mathematics and Computing.
4th edition. Brooks, Cole 1999.
[2] ISAACSON I., KELLER, H., Analysis of Numerical Methods. Wiley,
1966.
[3] SCHULTZ, M.H.., Spline Analysis. Prentice Hall 1973.
33