11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... ·...

20

Click here to load reader

Transcript of 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... ·...

Page 1: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

11 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 thefunction f are its values yj = f(xj), j = 1, 2, . . . , n. For instance, we may have obtained thesevalues through measurements and now would like to determine f(x) for other values of x.

Example 11.1

Assume that we need to evaluate cos(π/6), but the trigonometric function-key on our calculatoris broken and we do not have access to a computer. We recall that cos(0) = 1, cos(π/4) = 1/

√2,

and cos(π/2) = 0. How can we use this information about the cosine function to determine anapproximation of cos(π/6)? 2

Example 11.2

Let x represent time (in hours) and f(x) be the amount of rain falling at time x. Assume thatf(x) is measured once an hour at a weather station. We would like to determine the total amountof rain fallen during a 24-hour period, i.e., we would like to compute

∫ 24

0f(x)dx.

How can we determine an estimate of this integral? 2

Example 11.3

Let f(x) represent the position of a car at time x and assume that we know f(x) at the timesx1, x2, . . . , xn. How can we determine the velocity at time x? Can we also find out the accelera-tion? 2

Interpolation by polynomials or piecewise polynomials provide approaches to solving the prob-lems in the above examples. We first discuss polynomial interpolation and then turn to interpolationby piecewise polynomials.

Polynomial least-squares approximation is another technique for computing a polynomial thatapproximates given data. Least-squares approximation was discussed and illustrated in Lecture 6.

11.1 Polynomial interpolation

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

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

0Version January 29, 2014

1

Page 2: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

The polynomial is said to interpolate the values yj at the nodes xj , and is referred to as theinterpolating polynomial. The nodes xj are referred to as interpolation points.

Example 11.4

Let n = 1. Then the interpolation polynomial reduces to the constant y1. When n = 2, theinterpolating polynomial is linear and can be expressed as

p(x) = y1 +y2 − y1

x2 − x1(x − x1).

2

Example 11.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 theyexist and are unique. We also will consider several representations of the interpolating polynomial,starting with the power form

p(x) = a1 + a2x + a3x2 + · · · + anxn−1. (2)

This is a polynomial of degree at most n− 1. We would like to determine the coefficients aj , whichmultiply powers of x, so that the conditions (1) are satisfied. This gives the equations

a1 + a2xj + a3x2j + · · · + anxn−1

j = yj , j = 1, 2, . . . , n.

They can be expressed as a linear system of equations with a Vandermonde matrix,

1 x1 x21 . . . xn−2

1 xn−11

1 x2 x22 . . . xn−2

2 xn−12

......

......

...

1 xn−1 x2n−1 . . . xn−2

n−1 xn−1n−1

1 xn x2n . . . xn−2

n xn−1n

a1

a2...

an−1

an

=

y1

y2...

yn−1

yn

. (3)

As noted in Section 7.5, Vandermonde matrices are nonsingular when the nodes xj are distinct.This secures 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 formany applications, because this representation easily can be integrated or differentiated. Moreover,the polynomial (2) easily can be evaluated by nested multiplication without explicitly computing

2

Page 3: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

the powers xj . For instance, pulling out common powers of x from the terms of a polynomial ofdegree three gives

p(x) = a1 + a2x + a3x2 + a4x

3 = a1 + (a2 + (a3 + a4x)x)x. (4)

Exercise 11.2 is concerned with the evaluation of polynomials of arbitrary degree by nested multi-plication.

However, Vandermonde matrices generally are severely ill-conditioned. This is illustrated inExercise 11.3. When the function values yj are obtained by measurements, and therefore arecontaminated by measurement 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) alsocan give rise to a large propagated error in the computed coefficients. We are therefore interestedin investigating other polynomial bases than the power basis.

The Lagrange basis for polynomials of degree n − 1 is given by

ℓk(x) =n

j=1j 6=k

x − xj

xk − xj

, k = 1, 2, . . . , n.

The ℓk(x) are known as Lagrange polynomials. They are of degree n − 1. It is easy to verify thatthe Lagrange polynomials satisfy

ℓk(xj) =

{

1, k = j,0, k 6= j.

(5)

This property makes it possible to determine the interpolation polynomial without solving a linearsystem of equations. It follows from (5) that the interpolation polynomial is given by

p(x) =n

k=1

ykℓk(x). (6)

We refer to this expression as the interpolation polynomial in Lagrange form. This representationestablishes the existence of an interpolation polynomial without using properties of Vandermondematrices. Unicity also can be shown without using Vandermonde matrices: assume that there aretwo polynomials p(x) and q(x) of degree at most n − 1, such that

p(xj) = q(xj) = yj , 1 ≤ j ≤ n.

Then the polynomial r(x) = p(x) − q(x) is of degree at most n − 1 and vanishes at the n distinctnodes xj . According to the fundamental theorem of algebra, a polynomial of degree n − 1 has atmost n− 1 zeros or vanishes identically. Hence, r(x) vanishes identically, and it follows that p andq are the same polynomial. Thus, the interpolation polynomial is unique.

3

Page 4: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

The only drawback of the representation (6) of the interpolation polynomial is that its evaluationis cumbersome; straightforward evaluation of each Lagrange polynomial ℓk(x) at a point x requiresO(n) arithmetic floating point operations1, which suggests that the evaluation of the sum (6)requires O(n2) arithmetic floating point operations. The latter operation count can be reduced byexpressing the Lagrange polynomials in a different way. Introduce the nodal polynomial

ℓ(x) =

n∏

j=1

(x − xj)

and define the weights

wk =1

n∏

j=1j 6=k

(xk − xj)

. (7)

Then the Lagrange polynomials can be written as

ℓk(x) = ℓ(x)wk

x − xk

, k = 1, 2, . . . , n.

Since the value of the interpolating polynomial p(x) is known to be yk at the interpolation point xk,we only are interested in evaluating p(x) for x-values different from interpolation points. Therefore,we may assume that x 6= xk for k = 1, 2, . . . , n. 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

p(x) = ℓ(x)n

k=1

yk

wk

x − xk

. (8)

We noted above that the interpolation polynomial is unique. Therefore, interpolation of theconstant 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, and the expression (8) simplifies to

1 = ℓ(x)n

k=1

wk

x − xk

.

It follows that

ℓ(x) =1

n∑

k=1

wk

x − xk

.

1O(n) stands for an expression bounded by cn as n → ∞, where c > 0 is a constant independent of n.

4

Page 5: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

Substituting the above expression into (8) yields

p(x) =

n∑

k=1

yk

wk

x − xk

n∑

k=1

wk

x − xk

. (9)

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 becomputed, e.g., by using the definition (7). This requires O(n2) arithmetic floating point operations.Given the weights, p(x) can be evaluated at any point x in only O(n) arithmetic floating pointoperations. Exercises 11.4 and 11.5 are concerned with these computations.

The representation (9) can be shown to be quite insensitive to round-off errors and thereforecan be used to represent polynomials of high degree, provided that overflow and underflow areavoided during the computation of the weights wk. This easily can be achieved by rescaling allthe weights when necessary; note that the formula (9) allows all weights to be multiplied by anarbitrary nonzero constant.

11.2 The approximation error

When carrying out polynomial interpolation, one generally assumes that the y1, y2, . . . , yn in (1) arevalues of a smooth but unknown function f at the points x1, x2, . . . , xn. We would like to know thefunction f and hope that the interpolating polynomial p determined by (1) will provide an accurateapproximation of f at points x of interest. Let us assume that we are interested in knowing how flooks in the interval [−1, 1] and that the interpolation points xj all live in this interval.

Example 11.5

Let the n interpolation points be equidistant in the interval [−1, 1]. The interval end points areamong the interpolation points. Then the interpolation points are

xj = −1 + 2j − 1

n − 1, j = 1, 2, . . . , n. (10)

We would like to approximate the exponential function f(x) = exp(x) on [−1, 1] by the polynomialof degree at most n − 1 that is determined by interpolating f at the n interpolation points xj .First let n = 3. Figure 1 displays the function f , the interpolating polynomial p, and the threeinterpolation points. We can see that f and p agree at the interpolation points and are quite closeon the whole interval.

If we know f at more points, then we can use this information to determine an interpolationpolynomials that provides a more accurate approximation of f . Assume that we know f at five

5

Page 6: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

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

0.5

1

1.5

2

2.5

3

Figure 1: The exponential function f(x) = exp(x) (dashed red graph), three equidistant interpola-tion points {xj , exp(xj)}3

j=1 (blue ∗), and the interpolating polynomial p (solid blue graph).

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

0.5

1

1.5

2

2.5

3

Figure 2: The exponential function f(x) = exp(x) (dashed red graph), five equidistant interpolationpoints {xj , exp(xj)}5

j=1 (blue ∗), and the interpolating polynomial p (solid blue graph).

equidistant points on [−1, 1], that is we let n = 5 in (10). Our interpolation points are theones from Figure 1 and two additional ones. Figure 2 is analogous to Figure 1 and shows f , thefive interpolation points, and the interpolating polynomial p. The graph for p is on top of thegraph for f . Therefore these graphs cannot be distinguished. Clearly, p is a much more accurate

6

Page 7: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

approximation of f than in Figure 1. If f were known at more interpolation points, then we coulduse them to determine an interpolation polynomial of higher degree that would approximate f evenmore accurately. 2

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

−0.2

0

0.2

0.4

0.6

0.8

1

Figure 3: The Runge function (11) (dashed red graph), five equidistant interpolation points{xj , exp(xj)}5

j=1 (blue ∗), and the interpolating polynomial p (solid blue graph).

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

−0.2

0

0.2

0.4

0.6

0.8

1

Figure 4: The Runge function (11) (dashed red graph), five equidistant interpolation points{xj , exp(xj)}10

j=1 (blue ∗), and the interpolating polynomial p (solid blue graph).

7

Page 8: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

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

0

1

2

3

4

5

6

7

8

9

Figure 5: The Runge function (11) (dashed red graph), five equidistant interpolation points{xj , exp(xj)}20

j=1 (blue ∗), and the interpolating polynomial p (solid blue graph).

Example 11.6

We consider interpolation of the function

f(x) =1

1 + 25x2(11)

at n = 5 equidistant points (10) in the interval [−1, 1]. This function is known as the Runge

function2 Figure 3 is similar to Figure 2; the only difference is that the exponential function inthe latter figure is replaced by the Runge function. The interpolating polynomial (blue continuousgraph) is seen not to approximate the Runge function (red dashed graph) well.

In Example 11.5 we obtained a more accurate polynomial approximation of the exponentialfunction by interpolating the function at more points. We will try to do the same for the Rungefunction. Figure 4 differs from Figure 3 in that we have doubled the number of interpolation points.The interpolation points now are given by (10) with n = 10.

The interpolating polynomial p of Figure 4 might approximate the Runge function f on theinterval [−1, 1] slightly better than interpolating polynomial of Figure 3, but clearly the differencef(x) − p(x) is large for many points x in the interval. In our quest for an accurate polynomialapproximation of f , we therefore double the number of interpolation points one more time. Figure5 is similar to Figure 4; the only difference is that we have increased the number of equidistantinterpolation points (10) to n = 20. Unfortunately, the interpolation polynomial p does not behave

2The function is named after Carl Runge, a German mathematician, who studied polynomial interpolation of thisfunction around 1900.

8

Page 9: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

as we would like. The difference f(x)−p(x) is very large for x close to the end points of the interval.Moreover, increasing the number of equidistant interpolation points further does not reduce theerror close to the end points. We conclude that there are functions that cannot be approximatedaccurately by polynomial interpolation at equidistant interpolation points. 2

How well an interpolating polynomial p approximates the interpolated function f on the intervalwhere the interpolation points xj live depends both on the function and on the distribution of theinterpolation points. The following error formula sheds some light on this issue. Let the nodes xj

be distinct in the real interval [a, b], and let f(x) be an n times continuously differentiable functionin [a, b]. Denote the nth derivative by f (n)(x). Assume that yj = f(xj), j = 1, 2, . . . , n, and let thepolynomial p(x) of degree at most n − 1 satisfy the interpolation conditions (1). Then the errorf(x) − p(x) can be expressed as

f(x) − p(x) =n

j=1

(x − xj)f (n)(ξ)

n!, a ≤ x ≤ b, (12)

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 canderive the expression (12) by using a variant of the mean-value theorem from Calculus.

We will not prove the error-formula (12) in this course. Instead, we will use the formula tolearn about some properties of the polynomial interpolation problem. Usually, the nth derivativeof f is not available and only the product over the nodes xj can be studied easily. It is remarkablehow much useful information can be gained by investigating this product! First we note that theapproximation error

maxa≤x≤b

|f(x) − p(x)| (13)

is likely to be larger when the interval [a, b] is long than when it is short. We can see this bydoubling the size of the interval, i.e., we multiply a, b, x and the xj by 2. Then the product in theright-hand side of (12) is replaced by

n∏

j=1

(2x − 2xj) = 2n

n∏

j=1

(x − xj),

which shows that the interpolation error might be multiplied by 2n when doubling the size of theinterval. Actual computations show that, indeed, the error typically increases with the length ofthe interval [a, b] when other relevant quantities remain unchanged.

The error-formula (12) also can be used to investigate how the nodes xj should be distributed inthe interval [a, b] in order to give a small approximation error (13). The function f is only assumedto be known at the interpolation points. We therefore neither know the derivative f (n) nor thevalue of ξ in the right-hand side of (12). However, we do know the product in the right-hand sideand can evaluate it for different choices of interpolation points xj . To achieve a small difference

9

Page 10: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

|f(x) − p(x)| for all x in [a, b], we could try to distribute the interpolation points xj so that theproduct

∏nj=1 |x − xj | is small for all x in [a, b]. In fact, we would like this product to be as small

as possible. This leads to the following minimization problem:

minxj

maxa≤x≤b

n∏

j=1

|x − xj |. (14)

It would be quite difficult to solve this problem by a numerical optimization method, becausethe product is a nonlinear function of the xj . Moreover, the function

x →n

j=1

|x − xj |

is not differentiable, because the function |x| is not differentiable at the origin.However, it turns out that this complicated optimization problem has a simple solution! Let

for the moment a = −1 and b = 1. Then the solution is given by

xj = cos

(

2j − 1

2nπ

)

, j = 1, 2, . . . , n. (15)

These points are the projection of n equidistant points on the upper half of the unit circle onto thex-axis; see Figure 6. The xj are known as Chebyshev points.

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

−0.2

0

0.2

0.4

0.6

0.8

1

1.2

Figure 6: Upper half of the unit circle with 8 equidistant points marked in red, and their projectiononto the x-axis marked in magenta. The latter are, from left to right, the points x1, x2, . . . , x8

defined by (15) for n = 8.

10

Page 11: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

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

−1.5

−1

−0.5

0

0.5

1

1.5

2x 10

−3

Figure 7: The product in the error formula (12) for −1 ≤ x ≤ 1 when n = 10 and the interpolationpoints are Chebyshev points.

The function x → ∏nj=1(x− xj) with xj Chebyshev points and is shown in Figure 7 for n = 10

and −1 ≤ x ≤ 1. The product has a local maximum and a local minimum between each pair ofadjacent interpolation points. What make the Chebyshev points special is that the magnitude ofeach local maximum and minimum is the same. This property holds for any set of n Chebyshevpoints and can be used to show that the Chebyshev points solve the minimization problem (14).

For comparison, we depict in Figure 8 the function x → ∏10j=1(x−xj) with xj equidistant points

defined by (10) with n = 10. The function achieves a local maximum or minimum between eachpair of adjacent interpolation points, but the magnitude of the minima close to the interval endpoints are much larger than the magnitude of the other maxima and minima. The magnitudesof the local maxima and minima differ even more when the number of equidistant interpolationpoints is increased. Figure 9 is analogous to Figure 8 and shows the product

∏20j=1(x − xj) for 20

equidistant interpolation points xj . The large magnitude of the product close to the end points ofthe interval results in a large error in the interpolation polynomial p(x) for x near the end points.This was illustrated by Figure 5.

Example 11.6

This example discusses polynomial interpolation at Chebyshev points. Figure 10 is analogous toFigure 4 and displays the polynomial obtained by interpolating the Runge function at 10 Chebyshevpoints. The interpolating polynomial approximates the Runge function better at the end points ofthe interval than when equidistant interpolation points are used, however, the polynomial is a poorapproximation of the Runge function around x = 0.

11

Page 12: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

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

−12

−10

−8

−6

−4

−2

0

2x 10

−3

Figure 8: The product in the error formula (12) for −1 ≤ x ≤ 1 when n = 10 and the interpolationpoints are equidistant.

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

−3

−2.5

−2

−1.5

−1

−0.5

0

0.5x 10

−4

Figure 9: The product in the error formula (12) for −1 ≤ x ≤ 1 when n = 10 and the interpolationpoints are equidistant.

When we interpolate the Runge function at 20 Chebyshev points, we obtain the interpolationpolynomial of Figure 11. It can be seen to be a fairly good approximation of the Runge function inthe whole interval [−1, 1] and, in particular, furnishes a much better approximation of the Rungefunction than the interpolation polynomial obtained by interpolating at 20 equidistant points. The

12

Page 13: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

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

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Figure 10: The Runge function (11) (dashed red graph), Chebyshev interpolation points{xj , exp(xj)}10

j=1 (blue ∗) (15), and the interpolating polynomial p (solid blue graph).

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

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Figure 11: The Runge function (11) (dashed red graph), Chebyshev interpolation points{xj , exp(xj)}20

j=1 (blue ∗) (15), and the interpolating polynomial p (solid blue graph).

latter is shown in Figure 5. An even more accurate approximation of the Runge function canbe achieved by increasing the number of interpolation points. Figure 12 shows the interpolationpolynomial obtained by interpolating the Runge functions at 30 Chebyshev points. The graphs forthe Runge function and the interpolation polynomial are so close that they cannot be distinguished

13

Page 14: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

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

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Figure 12: The Runge function (11) (dashed red graph), Chebyshev interpolation points{xj , exp(xj)}30

j=1 (blue ∗) (15), and the interpolating polynomial p (solid blue graph).

in the figure. 2

The above example shows that interpolating a function f at n Chebyshev points can be a goodidea. Indeed, one can show that the interpolating polynomial of degree at most n − 1 obtainedis close to the best polynomial approximant of f of degree at most n − 1. This also holds if thefunction does not have n continuous derivatives and, therefore, the remainder formula (12) doesnot hold.

For intervals with endpoints a < b, the solution of (14) is given by shifting and scaling theChebyshev points:

xj =1

2(b + a) +

1

2(b − a) cos

(

2j − 1

2nπ

)

, j = 1, 2, . . . , n. (16)

The presence of a high-order derivative in the error-formula (12) indicates that interpolationpolynomials are likely to give small approximation errors when the function has many continuousderivatives that are not very large in magnitude. Conversely, equation (12) suggests that interpo-lating a function with few or no continuous derivatives in [a, b] by a polynomial of small to moderatedegree might not yield an accurate approximation of f(x) on [a, b]. This, indeed, often is the case.We therefore in the next section discuss an extension of polynomial interpolation which typicallygives more accurate approximations than standard polynomial interpolation when the function tobe approximated is not smooth.

14

Page 15: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

Exercise 11.1

Solve the interpolation problem of Example 11.1. 2

Exercise 11.2

Write a MATLAB/Octave function for evaluating a polynomial of degree at most n − 1 in nestedform (4). The input are the coefficients a1, a2, . . . , an and x; the output is the value p(x). 2

Exercise 11.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/Octave functions vander and cond. Determine the growthexperimentally. Describe how you designed the experiments. Show your MATLAB/Octave codesand relevant input and output. 2

Exercise 11.4

Write a MATLAB/Octave function for computing the weights of the barycentric representation(9) of the interpolation polynomial, using the definition (7). The code should avoid overflow andunderflow. 2

Exercise 11.5

Given the weights (7), write a MATLAB/Octave function for evaluating the polynomial (9) at apoint x. 2

Exercise 11.6

(Bonus exercise.) Assume that the weights (7) are available for the barycentric representation of theinterpolation polynomial (9) for the interpolation problem (1). Let another data point {xn+1, yn+1}be available. Write a MATLAB/Octave function for computing the barycentric weights for theinterpolation problem (1) with n replaced by n + 1. The computations can be carried out in onlyO(n) arithmetic floating point operations. 2

Exercise 11.7

The Γ-function is defined by

Γ(x) =

∫ ∞

0tx−1e−tdt.

15

Page 16: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

2 13 24 65 246 120

Table 1: n and Γ(n).

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 1.

(a) Determine the actual value of Γ(4.5) by interpolation in 3 and 5 nodes. Which 3 nodesshould 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.

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

Exercise 11.8

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

maxtj , j=1,2...,500

|f(tj) − p(tj)|

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 (15) 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 (15) as interpolation points.

How do the errors compare for equidistant and Chebyshev points? 2

16

Page 17: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

0 11 22 6

Table 2: t and f(t).

Exercise 11.9

Compute an approximation of the integral

∫ 1

0

√x exp(x2)dx

by first interpolating the integrand by a polynomial of degree at most 3 and then integratingthe polynomial. Which representation of the polynomial is most convenient to use? Use fourinterpolation points. Which points would be suitable? Justify your choice. 2

Exercise 11.10

The function f(t) gives the position of a ball at time t. Table 2 displays a few values of f and t.Interpolate f by a quadratic polynomial and estimate the velocity and acceleration of the ball attime t = 1. 2

11.3 Interpolation by piecewise polynomials

In the above section, we sought to determine one polynomial that approximates a function on aspecified 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 several continuous derivatives and interpolation can be carried out at theChebyshev points (15) or (16).

A quite natural and different approach to approximate a function on an interval is to first splitthe interval into subintervals and then approximate the function by a polynomial of fairly lowdegree on each subinterval. We now discuss this approach.

Example 11.5

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

17

Page 18: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

f(x) by a linear function on each subinterval [x1, x2] and [x2, x3]. We obtain, by using the Lagrangeform (6), that

p(x) = y1x − x2

x1 − x2+ y2

x − x1

x2 − x1= x + 1, −1 ≤ x ≤ 0,

p(x) = y2x − x3

x2 − x3+ y3

x − x2

x3 − x2= 1 − x, 0 ≤ x ≤ 1.

The MATLAB command plot([-1,0,1],[0,1,0]) gives the continuous graph of Figure 13. This is apiecewise linear approximation of the unknown function f(x). If f(x) indeed is a piecewise linearfunction with a kink at x = 0, then the computed approximation is appropriate. On the otherhand, if f(x) displays the trajectory of a baseball, then the smoother function p(x) = 1−x2, whichis depicted by the dashed curve, may be a more suitable approximation of f(x), since baseballtrajectories 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 interpolationpoints {xj , yj} are used. We can increase the accuracy of the piecewise linear approximant byreducing the lengths of the subintervals and thereby increasing the number of subintervals.

We conclude that piecewise linear approximations of functions are easy to compute. However,piecewise linear approximants display kinks. Therefore, many subintervals may be required todetermine a piecewise linear approximant of high accuracy. 2

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

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Figure 13: Example 11.5: Quadratic polynomial p(x) = 1 − x2 (red dashed graph) and piecewiselinear 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 differentapproach, which uses Bezier curves, is described in the next lecture.

18

Page 19: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

Assume that not only the function values yj = f(xj), but also the derivative values y′j = f ′(xj),are available at the nodes a ≤ x1 < x2 < . . . < xn ≤ b. We can then on each subinterval, say[xj , xj+1], approximate f(x) by a polynomial that interpolates both f(x) and f ′(x) at the endpointsof the interval. Thus, we would like to determine a polynomial pj(x), such that

pj(xj) = yj , pj(xj+1) = yj+1, p′j(xj) = y′j , p′j(xj+1) = y′j+1. (17)

These are 4 conditions, and we seek to determine a polynomial of degree 3,

pj(x) = a1 + a2x + a3x2 + a4x

3, (18)

which satisfies these conditions. Our reason for choosing a polynomial of degree 3 is that it has 4coefficients, the same number as the number of condition. Substituting the polynomial (18) intothe conditions (17) gives the linear system of equations,

1 xj x2j x3

j

1 xj+1 x2j+1 x3

j+1

0 1 2xj 3x2j

0 1 2xj+1 3x2j+1

a1

a2

a3

a4

=

yj

yj+1

y′jy′j+1

. (19)

The last two rows impose interpolation of the derivative values. The matrix can be shown to benonsingular when xj 6= xj+1. Matrices of the form (19) are referred to as confluent Vandermondematrices.

The polynomials p1(x), p2(x), . . . , pn−1(x) provide a piecewise cubic polynomial approximationof f(x) on the whole interval [a, b]. They can be computed independently and yield an approxi-mation with a continuous derivative on [a, b]. The latter can be seen as follows: The polynomialpj is defined and differentiable on the interval [xj , xj+1] for j = 1, 2, . . . , n − 1. What remains tobe established is that our approximant also has a continuous derivative at the interpolation points.This follows from the interpolation conditions (17). We have

limxրxj+1

p′j(x) = p′j(xj+1) = y′j+1, limxցxj+1

p′j+1(x) = p′j+1(xj+1) = y′j+1.

The existence of the limit follows from the continuity of each polynomial on the interval where itis 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 that derivative information be available. When no derivative infor-mation is explicitly known, modifications of the scheme outlined can be used. A simple modificationis to use estimates of the derivative values of the function f(x) at the nodes; see Exercise 11.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),

19

Page 20: 11 Polynomial and Piecewise Polynomial Interpolationreichel/courses/intr.num.comp.2/spring14/... · 11 Polynomial and Piecewise Polynomial Interpolation ... Polynomial least-squares

for j = 2, 3, . . . , n − 1. Thus, at the subinterval boundaries at x2, x3, . . . , xn−1, we require thepiecewise cubic polynomial to have continuous first and second derivatives. However, these deriva-tives are not required to take on prescribed values. The piecewise cubic polynomials obtained inthis manner are known as splines. They are popular design tools in industry. Their determinationrequires the solution of a linear system of equations, which is somewhat complicated to derive. Wewill therefore omit its derivation. Extra conditions at the interval endpoints have to be imposed inorder to make the resulting linear system of equations uniquely solvable.

Exercise 11.11

Consider the function in Example 11.5. Assume that we also know the derivative values y′1 = 2,y′2 = 0, and y′3 = −2. Determine a piecewise polynomial approximation on [−1, 1] by using theinterpolation conditions (17). Plot the resulting function. 2

Exercise 11.12

Assume the derivative values in the above exercise are not available. How can one determineestimates of these values? Use these estimates in the interpolation conditions (17) and compute apiecewise cubic approximation. How does it compare with the one from Exercise 11.11 and withthe piecewise linear approximation of Example 11.5. Plot the computed approximant. 2

Exercise 11.13

Compute a spline approximant of the function of Example 11.5, e.g., by using the function splinein MATLAB or Octave. Plot the computed spline. 2

20