0% found this document useful (0 votes)
13 views

Lecture 7

Uploaded by

mingkit.2021
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Lecture 7

Uploaded by

mingkit.2021
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

7 Polynomial and piecewise polynomial interpolation

Let f be a function, which is only known at the nodes x1 , x2 , . . . , xn , i.e., all we know about the function
f are its values yj = f (xj ), j = 1, 2, . . . , n. For instance, we may have obtained these values through
measurements and now would like to determine f (x) for other values of x.
Example 7.1: Assume that we need to evaluate cos(π/6), but the trigonometric function-key on your
calculator
√ is broken and we do not have access to a computer. We do remember that cos(0) = 1, cos(π/4) =
1/ 2, and cos(π/2) = 0. How can we use this information about the cosine function to determine an
approximation of cos(π/6)? 2
Example 7.2: Let x represent time (in hours) and f (x) be the amount of rain falling at time x. Assume
that f (x) is measured once an hour at a weather station. We would like to determine the total amount of
rain fallen during a 24-hour period, i.e., we would like to compute
Z 24
f (x)dx.
0

How can we determine an estimate of this integral? 2


Example 7.3: Let f (x) represent the position of a car at time x and assume that we know f (x) at the
times x1 , x2 , . . . , xn . How can we determine the velocity at time x? Can we also find out the acceleration?
2
Interpolation by polynomials or piecewise polynomials provide approaches to solving the problems in
the above examples. We first discuss polynomial interpolation and then turn to interpolation by piecewise
polynomials.

7.1 Polynomial interpolation


Given n distinct nodes x1 , x2 , . . . , xn and associated function values y1 , y2 , . . . , yn , determine the polynomial
p(x) of degree at most n − 1, such that

p(xj ) = yj , j = 1, 2, . . . , n. (1)

The polynomial is said to interpolate the values yj at the nodes xj , and is referred to as the interpolating
polynomial.
Example 7.4: Let n = 1. Then the interpolation polynomial reduces to the constant y1 . When n = 2,
the interpolating polynomial is linear and can be expressed as
y2 − y1
p(x) = y1 + (x − x1 ).
x2 − x1
2
Example 7.1 cont’d: We may seek to approximate cos(π/6) by first determining the polynomial p of
degree at most 2, which interpolates cos(x) at x = 0, x = π/4, and x = π/2, and then evaluating p(π/6). 2
Before dwelling more on applications of interpolating polynomials, we have to establish that they exist
and are unique. We also will consider several representations of the interpolating polynomial, starting with
the power form
p(x) = a1 + a2 x + a3 x2 + · · · + an xn−1 . (2)

1
This is a polynomial of degree at most n − 1. We would like to determine the coefficients aj , which multiply
powers of x, so that the conditions (1) are satisfied. This gives the equations
a1 + a2 xj + a3 x2j + · · · + an xjn−1 = yj , j = 1, 2, . . . , n.
They can be expressed in matrix form as follows,
x21 . . . x1n−2 x1n−1
    
1 x1 a1 y1
 1 x2 x22 . . . x2n−2 x2n−1  a2   y2 
 .. .. .. .. .. .. ..
    
= . (3)
   
 .
 . . . . 
 .   . 
 1 xn−1 x2 n−2 n−1   an−1   yn−1
n−1 ... xn−1 xn−1 
1 xn x2n ... xnn−2 xnn−1 an yn
The above matrix is known as a Vandermonde matrix. It is nonsingular when the nodes xj are distinct. For
instance, when n = 2, we have  
1 x1
det = x2 − x1 6= 0.
1 x2
The nonsingularity of the Vandermonde matrix guarantees the existence of a unique interpolation polynomial.
The representation of a polynomial p(x) in terms of the powers of x, like in (2), is convenient for many
applications, because this representation easily can be integrated or differentiated. Moreover, the polynomial
(2) easily can be evaluated by nested multiplication without explicitly computing the powers xj . For instance,
pulling out common powers of x from the terms of a polynomial of degree three gives
p(x) = a1 + a2 x + a3 x2 + a4 x3 = a1 + (a2 + (a3 + a4 x)x)x. (4)
The right-hand side is easy to evaluate; only O(n) arithmetic floating point operations are required, see
Exercise 7.2.
However, Vandermonde matrices generally are severely ill-conditioned. This is illustrated in Exercise
7.3. When the function values yj are obtained by measurements, and therefore are contaminated by mea-
surement errors, the ill-conditioning implies that the computed coefficients aj may differ significantly from
the coefficients that would have been obtained with error-free data. Moreover, round-off errors introduced
during the solution of the linear system of equations (3) also can give rise to a large propagated error in the
computed coefficients. We are therefore interested in investigating other polynomial bases than the power
basis.
The Lagrange basis for polynomials of degree n − 1 is given by
n
Y x − xj
ℓk (x) = , k = 1, 2, . . . , n.
x − xj
j=1 k
j6=k

The ℓk (x) are known as Lagrange polynomials. They are of degree n−1. It is easy to verify that the Lagrange
polynomials satisfy 
1, k = j,
ℓk (xj ) = (5)
0, k 6= j.
This property makes it possibly to determine the interpolation polynomial in terms solving a linear system
of equations. It follows from (5) that the interpolation polynomial is given by
n
X
p(x) = yk ℓk (x). (6)
k=1

2
We refer to this expression as the interpolation polynomial in Lagrange form.
The only drawback of the representation (6) of the interpolation polynomial is that it is somewhat cum-
bersome to evaluate; straighforward evaluation of each Lagrange polynomial ℓk (x) requires O(n) arithmetic
floating point operations, which suggests that the evaluation of the sum (6) requires O(n2 ) arithmetic float-
ing point operations. The latter operation count can be reduced by expressing the Lagrange polynomials in
a different way. Introduce the nodal polynomial
n
Y
ℓ(x) = (x − xj )
j=1

and define the weights


1
wk = n . (7)
Y
(xk − xj )
j=1
j6=k

Then the Lagrange polynomials can be written as


wk
ℓk (x) = ℓ(x) , k = 1, 2, . . . , n.
x − xk
We assume for simplicity that x 6= xk . All terms in the sum (6) contain the factor ℓ(x), which is independent
of k. We therefore can move this factor outside the sum, and obtain
n
X wk
p(x) = ℓ(x) yk . (8)
x − xk
k=1

We noted above that the interpolation polynomial is unique. Therefore, interpolation of the constant
function f (x) = 1, which is a polynomial, gives the interpolation polynomial p(x) = 1. Since f (x) = 1, we
have yk = 1 for all k. The expression (8) simplifies to
n
X wk
1 = ℓ(x) ,
x − xk
k=1

which shows that


1
ℓ(x) = n .
X wk
x − xk
k=1

Finally, substituting the above expression into (8) yields


n
X wk
yk
x − xk
k=1
p(x) = n . (9)
X wk
x − xk
k=1

This formula is known as the barycentric representation of the Lagrange interpolating polynomial, or simply
as the interpolating polynomial in barycentric form. It requires that the weights be computed, e.g., by using

3
the definition (7). This requires O(n2 ) arithmetic floating point operations. Given the weights, p(x) can be
determined for each value of x in only O(n) arithmetic floating point operations; see Exercise 7.4 for further
details.
The representation (9) can be shown to be quite insensitive to round-off errors and therefore also can be
used to represent polynomials of high degree, provided that overflow and underflow is avoided during the
computation of the weights wk . This easily can be achieved by rescaling all the weights when necessary;
note that the formula (9) allows the weights to be multiplied by an arbitrary nonzero constant.

7.2 The approximation error


Let the nodes xj be distinct and live in the real interval [a, b], and let f (x) be a function, which is n times
differentiable in [a, b]. Let f (n) (x) denote the nth derivative. Assume that yj = f (xj ), j = 1, 2, . . . , n. Then
the difference f (x) − p(x) can be expressed as
n
Y f (n) (ξ)
f (x) − p(x) = (x − xj ) , (10)
j=1
n!

where ξ is a function of the nodes x1 , x2 , . . . , xn and x. The exact value of ξ is difficult to pin down, however,
it is known that ξ is in the interval [a, b] when x and x1 , x2 , . . . , xn are there. One can derive the expression
(10) by using a variant of the mean-value theorem from Calculus.
We will not prove the error-formula (10) in this course. Instead, we will use the formula to learn about
some properties of the polynomial interpolation problem. Usually, the nth derivative of f is not available and
only the product over the nodes xj can be studied easily. It is remarkable how much useful information can
be gained by investigating this product! First we note that the interpolation error maxa≤x≤b |f (x) − p(x)| is
likely to be larger when the interval [a, b] is long than when it is short. We can see this by doubling the size
of the interval, i.e., we multiply a, b, x and the xj by 2. Then the product in the right-hand side of (10) is
replaced by
Y n Yn
(2x − 2xj ) = 2n (x − xj ),
j=1 j=1

which shows that the interpolation error might be multiplied by 2n when doubling the size of the interval.
Actual computations show that, indeed, the error typically increases with the length of the interval when
other relevant quantities remain unchanged.
The error-formula (10) also raises the question how the nodes xj should be distributed in the interval
[a, b] in order to give a small error maxa≤x≤b |f (x) − p(x)|. For instance, we may want to choose nodes xj
that solve the minimization problem
Yn
min max |x − xj |. (11)
xj a≤x≤b
j=1

This complicated problem turns out to have a simple solution! Let for the moment a = −1 and b = 1. Then
the solution is given by  
2j − 1
xj = cos π , j = 1, 2, . . . , n. (12)
2n
These points are the projection of n equidistant points on the upper half of the unit circle onto the x-axis;
see Figure 1. The xj are known as Chebyshev points.

4
1.2

0.8

0.6

0.4

0.2

−0.2

−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1

Figure 1: Upper half of the unit circle with 8 equidistant points marked in red, and their projection onto
the x-axis marked in magenta. The latter are, from left to right, the points x1 , x2 , . . . , x8 defined by (12) for
n=8

For intervals with endpoints a < b, the solution of (11) is given by


 
1 1 2j − 1
xj = (b + a) + (b − a) cos π , j = 1, 2, . . . , n. (13)
2 2 2n

Finally, the presence of a high-order derivative in the error-formula (10) suggests that interpolation
polynomials are likely to give small approximation errors when the function has many continuous derivatives
that are not very large in magnitude. In the next subsection, we will discuss a modifications of polynomial
interpolation, that can work better when the function to be approximated does not have many (or any)
continuous derivatives.

Exercises
Exercise 7.1: Solve the interpolation problem of Example 7.1. 2
Exercise 7.2: Write a MATLAB or Octave function for evaluating the polynomial (2) in nested form (4).
The input are the coefficients aj and x; the output is the value p(x). 2
Exercise 7.3: Let Vn be an n × n Vandermonde matrix determined by n equidistant nodes in the interval
[−1, 1]. How quickly does the condition number of Vn grow with n? Linearly, quadratically, cubically, . . .,
exponentially? Use the MATLAB or Octave functions vander and cond. Determine the growth experimen-
tally. Describe how you designed the experiments. Show your MATLAB or Octave codes and relevant input
and output. 2
Exercise 7.4: Write a MATLAB or Ocatve function for computing the weights of the barycentric repre-
sentation (9) of the interpolation polynomial, using the definition (7). The code should avoid overflow and
underflow. 2

5
1 11.0
2 12.5
3 14.5
4 16.0
5 18.0

Table 1: Grind size (left-hand side column) versus pressure (right-hand side column).

2 1
3 2
4 6
5 24
6 120

Table 2: n and Γ(n).

Exercise 7.5: (Bonus exercise.) Assume that the weights (7) are available for the barycentric representation
of the interpolation polynomial (9) for the interpolation problem (1). Let another data point {xn+1 , yn+1 } be
available. Write a MATLAB or Octave function for computing the barycentric weights for the interpolaion
problem (1) with n replaced by n + 1. The computations can be carried out in only O(n) arithmetic floating
point operations. 2
Exercise 7.6: The pressure in a fully automatic espresso machine varies with size of the coffee grinds. The
pressure is measured in bar and the grind size in units, where 1 signifies a coarse grind and 5 a fine one. The
relation is tabulated in Table 1.
(a) Determine by linear interpolation, which pressure grind size 2.1 gives rise to. Which data should be
used?
(b) Determine by quadratic interpolation, which pressure grind size 2.1 gives rise to. Which data should
be used? Are the results for linear and quadratic interpolation close? 2
Exercise 7.7: The Γ-function is defined by
Z ∞
Γ(x) = tx−1 e−t dt.
0

Direct evaluation of the integral yields Γ(1) = 1 and integration by parts shows that Γ(x + 1) = xΓ(x). In
particular, for integer-values n > 1, we obtain that

Γ(n + 1) = nΓ(n)

and therefore Γ(n + 1) = n(n − 1)(n − 2) · · · 1. We would like to determine an estimate of Γ(4.5) by using
the tabulated values of Table 2.
(a) Determine the actual value of Γ(4.5) by interpolation in 3 and 5 nodes. Which 3 nodes should be
used? Determine the actual value of Γ(4.5). Are the computed approximations close? Which one is more
accurate.
(b) Also, investigate the following approach. Instead of interpolating Γ(x), interpolate ln(Γ(x)) by
polynomials at 3 and 5 nodes. Evaluate the computed polynomial at 4.5 and exponentiate.

6
0 1
1 2
2 6

Table 3: t and f (t).

How do the computed approximations in (a) and (b) compare? Explain! 2


Exercise 7.8: (a) Interpolate the function f (x) = ex at 20 equidistant nodes in [−1, 1]. This gives an
interpolation polynomial p of degree at most 19. Measure the approximation error f (x) − p(x) by measure
the difference at 500 equidistant nodes tj in [−1, 1]. We refer to the quantity

max |f (tj ) − p(tj )|


tj , j=1,2...,500

as the error. Compute the error.


(b) Repeat the above computations with the function f (x) = ex /(1 − 25x2 ). Plot p(tj ) − f (tj ), j =
1, 2, . . . , 500. Where in the interval [−1, 1] is the error the largest?
(c) Repeat the computations in (a) using 20 Chebyshev points (12) as interpolation points. How do the
errors compare for equidistant and Chebyshev points? Plot the error.
(d) Repeat the computations in (b) using 20 Chebyshev points (12) as interpolation points. How do the
errors compare for equidistant and Chebyshev points? 2
Exercise 7.9: Compute an approximation of the integral
Z 1

x exp(x2 )dx
0

by first interpolating the integrand by a 3rd degree polynomial and then integrating the polynomial. Which
representation of the polynomial is most convenient to use? Specify which interpolation points you use. 2
Exercise 7.10: The function f (t) gives the position of a ball at time t. Table 3 displays a few values of
f and t. Interpolate f by a quadratic polynomial and estimate the velocity and acceleration of the ball at
time t = 1.

7.3 Interpolation by piecewise polynomials


In the above subsection, we sought to determine one polynomial that approximates a function on a specified
interval. This works well if either one of the following conditions hold:
• The polynomial required to achieve desired accuracy is of fairly low degree.
• The function has a few continuous derivatives and interpolation can be carried out at the Chebyshev
points (12) or (13).
A quite natural and different approach to approximate a function on an interval is to first split the
interval into subintervals and then approximate the function by a polynomial of fairly low degree on each
subinterval.

7
Example 7.6: We would like to approximate a function on the interval [−1, 1]. Let the function values
yj = f (xj ) be available, where x1 = −1, x2 = 0, x3 = 1, and y1 = y3 = 0, y2 = 1. It is easy to approximate
f (x) by a linear function on each subinterval [x1 , x2 ] and [x2 , x3 ]. We obtain, using the Lagrange form (6),
x − x2 x − x1
p(x) = y1 + y2 = x + 1, −1 ≤ x ≤ 0,
x1 − x2 x2 − x1
x − x3 x − x2
p(x) = y2 + y3 = 1 − x, 0 ≤ x ≤ 1.
x2 − x3 x3 − x2
The MATLAB command plot([-1,0,1],[0,1,0]) gives the continuous graph of Figure 2. This is a piecewise
linear approximation of the unknown function f (x). If f (x) indeed is a piecewise linear function with a
kink at x = 0, then the computed approximation is appropriate, On the other hand, if f (x) displays the
trajectory of a baseball, then the smoother function p(x) = 1 − x2 , which is depicted by the dashed curve,
may be a more suitable approximation of f (x), since baseball trajectories do not exhibit kinks - even if some
players occasionally may wish they do.
Piecewise linear functions give better approximations of a smooth function if more interpolation points
{xj , yj } are used. We can increase the accuracy of the approximation by reducing the lengths of the subin-
tervals.
We conclude that piecewise linear approximations of functions are easy to compute. These approximations
display kinks. Many interpolation points may be required to determine a piecewise linear approximant of
desired accuracy. The benefits of piecewise linear approximation is the ease of the computations on each
subinterval. 2
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1

Figure 2: Example 7.6: Quadratic polynomial p(x) = 1 − x2 (red dashed graph) and piecewise linear
approximation (continuous blue graph).

There are several ways to modify piecewise linear functions to give them a more pleasing look. Here
we will discuss how to use derivative information to obtain smoother approximants. A different approach,
which uses Bézier curves is described in the next lecture.
Assume that not only the function values yj = f (xj ), but also the derivative values yj′ = f ′ (xj ), are
available at the nodes a ≤ x1 < x2 < . . . < xn ≤ b. We can then on each subinterval, say [xj , xj+1 ],

8
approximate f (x) by a polynomial that interpolates both f (x) and f ′ (x) at the endpoints. Thus, we would
like to determine a polynomial pj (x), such that
pj (xj ) = yj , pj (xj+1 ) = yj+1 , p′j (xj ) = yj′ , p′j (xj+1 ) = yj+1

. (14)
These are 4 conditions, and we seek to determine a polynomial of degree 3,
pj (x) = a1 + a2 x + a3 x2 + a4 x3 , (15)
which satisfies these conditions. Our reason for choosing a polynomial of degree 3 is that it has 4 coefficients,
one for each condition. Substituting the polynomial (15) into the conditions (14) gives the linear system of
equations,
x2j x3j
    
1 xj a1 yj
 1 xj+1 x2j+1 x3j+1 
  a2  =  yj+1  .
   
(16)
3x2j   a3   yj′ 

 0 1 2xj

0 1 2xj+1 3x2j+1 a4 yj+1
The last 2 rows impose interpolation of the derivative values. The matrix can be shown to be nonsingular
when xj 6= xj+1 .
The polynomials p1 (x), p2 (x), . . . , pn−1 (x) provide a piecewise cubic polynomial approximation of f (x) on
the whole interval [a, b]. They can be computed independently and yield an approximation with a continuous
derivative on [a, b]. The latter can be seen as follows: The polynomial pj is defined and differentiable on the
interval [xj , xj+1 ] for j = 1, 2, . . . , n − 1. What remains to be established is that our approximant also has
a continuous derivative at the interpolation points. This, however, follows from the interpolation conditions
(14). We have that
lim p′j (x) = p′j (xj+1 ) = yj+1

, lim p′j+1 (x) = p′j+1 (xj+1 ) = yj+1

.
xրxj+1 xցxj+1

The existence of the limit follows from the continuity of each polynomial on the interval where it is defined,
and the other equalities are the interpolation conditions. Thus, p′j (xj+1 ) = p′j+1 (xj+1 ), which shows the
continuity of the derivative at xj+1 of our piecewise cubic polynomial approximant.
The use of piecewise cubic polynomials as described gives attractive approximations. However, the
approach discussed requires derivative information be available. When no derivative information is explicitly
known, modifications of the scheme outlined can be used. A simple modification is to use estimates the
derivative-values of the function f (x) at the nodes; see Exercise 7.12.
Another possibility is to impose the conditions
pj (xj ) = yj , pj (xj+1 ) = yj+1 , p′j (xj ) = p′j−1 (xj ), p′′j (xj ) = p′′j−1 (xj ),
for j = 2, 3, . . . , n − 1. Thus, at the subinterval boundaries at x2 , x3 , . . . , xn−1 we require the piecewise cubic
polynomial to have continuous first and second derivatives. However, these derivatives are not required to
take on prescibed values. The piecewise cubic polynomials obtained in the manner are known as splines.
They are popular design tools in industry. Their determination requires the solution of a linear system
of equations, which is somewhat complicated to derive. We will therefore omit its derivation. Also, extra
conditions at the interval endpoints have to be imposed in order to make the linear system of solvable with
a unique solution.
Exercise 7.11: Consider the function in Example 7.6. Assume that we also know the derivative values
y1′ = 2, y2′ = 0, and y3′ = −2. Determine a piecewise polynomial approximation on [−1, 1] by using the
interpolation conditions (14). Plot the resulting function. 2

9
Exercise 7.12: Assume the derivative values in the above exercise are not available. How can one determine
estimates of these values? Use these estimates in the interpolation conditions (14) and compute a piecewise
cubic approximation. How does it compare with the one from Exercise 7.11 and with the piecewise linear
approximation of Example 7.6. 2
Exercise 7.13: Compute a spline approximant, e.g., by using the function spline in MATLAB or Octave. 2

10

You might also like