Piecewise Polynomial Interpolation
Piecewise Polynomial Interpolation
Piecewise Polynomial Interpolation
For certain x-values x1 x2 xn we are given the function values yi = f (xi ). In some cases below we will also assume
that we are additionally given some derivatives si = f 0 (xi ). We want to find an interpolating function p(x) which satisfies all
the given data and is hopefully close to the function f (x).
We could use a single interpolating polynomial p(x). But this is usually a bad idea: for a large value of n we will obtain
large oscillations.
We should only use an interpolating polynomial if we know that this will not be a problem and several of the following
conditions hold
the derivatives f (k) do not grow very fast (e.g., f (x) = sin x)
the points x1 , . . . , xn are close together, and we evaluate p(x) at a point x inside of the interval [x1 , xn ]
for equidistant nodes, we only evaluate p(x) for x near the center of the interval [x1 , . . . , xn ]
if we want to evaluate p(x) over a whole interval [a, b] we should choose x1 , . . . , xn as Chebyshev nodes for this interval.
In all other cases it is much better to use a piecewise polynomial: We break the interval [a, b] into smaller subintervals, and
use polynomial interpolation with low degree polynomials on each subinterval. Typically we choose polynomial degree of
about 3. This is a good compromise between small errors and control of oscillations.
(1)
p(x) = Li (x)
We then have from the error formula for polynomial interpolation with 2 points that with hi := xi+1 xi
for x [xi , xi+1 ] :
f 00 (t)
(x xi )(x xi+1 )
2!
h2
| f (x) p(x)| 21 max f 00 (t) i
4
t[xi ,xi+1 ]
f (x) p(x) =
hi
2
We see that the interpolation error satisfies | f (x) p(x)| Ch2i where C = 18 maxt[x1 ,xn ] | f 00 (t)|. If we choose equidistant
points with hi = (b a)/(n 1) we have | f (x) p(x)| C(b a)2 /n2 , i.e., doubling the number of points reduces the error
bound by a factor of 4.
However, if the function f (x) has different behavior on different parts of the interval we can get better results by choosing
the points x1 , . . . , xn accordingly: If | f 00 (x)| is small in a certain region we can use a wider spacing hi ; if | f 00 (x)| is large in
another reason we should place the nodes more closely, so that hi is small there. In this way we can achieve a small overall
error
00
2
1
|
max f (x) p(x)| 8 max
hi max f (t)
x[x1 ,xn ]
i=1,...,n1
t[xi ,xi+1 ]
with a small number of nodes. We say the choice of the nodes x1 , . . . , xn is adapted to the behavior of the function f .
One advantage of piecewise linear interpolation is that the behavior of p resembles the behavior of f :
whereever the function f is increasing/decreasing, we have that the function p is increasing/decreasing
However, we have drawbacks:
the function p(x) is not smooth: it has kinks (jumps of p0 (x)) at the nodes x2 , . . . , xn1 in general
the error | f (x) p(x)| Ch2i for x [xi , xi+1 ] only decreases fairly slowly with decreasing spacing hi . We would rather
have a higher power like Ch4i .
pi (xi ) = yi ,
p(xi+1 ) = yi+1 ,
p0 (xi+1 ) = si+1 .
We can construct this polynomial pi (x) using the divided difference method (using the nodes xi , xi , xi+1 , xi+1 ). We will now
explain a different way to express this polynomial pi (x) since this will be useful for cubic splines later. The idea is to write
pi (x) as the linear function Li (x) plus to extra terms. The function Li (x) already has the correct function values yi , yi+1 at the
endpoints, so the two extra terms have to be chosen such that we get the given derivatives si , si+1 at the endpoints. We let
pi (x) = Li (x) + A (x xi )(x xi+1 )2 + B (x xi )2 (x xi+1 )
with certain values A, B which we will figure out now. Note that the two functions (x xi )(x xi+1 )2 and (x xi )2 (x xi+1 )
have function value zero at both endpoints, and the following values of its derivatives:
q(x)
(x xi )(x xi+1 )2
(x xi )2 (x xi+1 )
q0 (xi )
2
hi
0
q0 (xi+1 )
0
h2i
q00 (xi )
4hi
2hi
q00 (xi+1 )
2hi
4hi
Note that
Li0 (x) =
yi+1 yi
=: si
xi+1 xi
and hence
!
p0 (xi ) = si + Ai h2i = si
and similarly Bi =
si+1 si
h2i
Ai =
si si
h2i
so that we have an explicit formula for the cubic Hermite polynomial pi (x):
pi (x) = Li (x) +
si si
si+1 si
(x xi )(x xi+1 )2 +
(x xi )2 (x xi+1 ).
2
2
hi
hi
(2)
p(x) = pi (x)
(3)
Then we obtain from the error formula for polynomial interpolation with 4 points xi , xi , xi+1 , xi+1 that
for x [xi , xi+1 ] :
f (4) (t)
(x xi )2 (x xi+1 )2
4!
h4
1
| f (x) p(x)| 24
max f 00 (t) i
16
t[xi ,xi+1 ]
f (x) p(x) =
hi
2
another reason we should place the nodes more closely, so that hi is small there.
error
1
h4i max
max | f (x) p(x)| 2416 max
i=1,...,n1
x[x1 ,xn ]
t[xi ,xi+1 ]
Therefore (4) gives (substituting i 1 for i in the second equation above) for i = 2, . . . , n 1
si si
si+1 si
si1 si1
si si1
(4hi ) +
(2hi ) =
(2hi1 ) +
(4hi1 )
2
2
2
hi
hi
hi1
h2i1
2
4
4
2
6
6
si1 +
+
si + si+1 =
si1 + si
hi1
hi1 hi
hi
hi1
hi
Note that the value s1 in the last equation and the value sn in the last equation are given, and should therefore be moved to
the right hand side. Hence we obtain the tridiagonal linear system (after diving each equation by 2)
2
2
1
s2
h1 + h2
h2
s3
s2
1
2
2
1
+
3
s3
h2
h3
h2
h2
h3
h3
.
..
..
..
. =
.
(5)
.
.
.
.
.
1
2
2
1
sn2
3 hn3
+ hn2
hn3
hn3 + hn2
hn2
n3
n2
1
2
2
s
n1
+
s
s
n2
n1
n
hn2
hn2
hn1
3 hn2 + hn1 hn1
This gives the following algorithm for finding the cubic spline interpolation:
yi+1 yi
hi
define the matrix A on the left hand side of (5) and the vector b on the right hand side of (5)
s2
solve the tridiagonal linear system A ... = b using Gaussian elimination without pivoting
sn1
For a given point x [x1 , xn ] we evaluate the cubic spline as follows:
find the interval [xi , xi+1 ] containing x
evaluate pi (x)
using (2), (1)
In Matlab we can find the complete cubic spline as follows: yt = spline([x1 , . . . , xn ],[s1 , y1 , . . . , yn , sn ],xt)
Here xt is a vector of points where we want to evaluate the spline, and yt is the corresponding vector of function values.
C (s)2 ds
E=
s=0
Here C is a stiffness constant. If one tries to pass a thin piece of wood through a number of points and allows it to relax it
will assume the shape with lowest possible energy E.
If we describe the curve by a function y = p(x) we have for small slopes p0 (x) that (s) p00 (x) and
E E0 :=
Z xn
x=x1
It turns out that the complete cubic spline is the smoothest possible interpolating function in the following sense:
Among all functions p(x) (not only piecewise polynomials) satisfying
p0 (x1 ) = s1 ,
p(x1 ) = y1 , . . . , p(xn ) = yn ,
Z xn
p0 (xn ) = sn
x=x1