polynomial interpolation - cs.purdue.edu · chap. 4. polynomial interpolation cs414 class notes 58...

14
Chapter 4 Polynomial Interpolation In this chapter, we consider the important problem of approximating a function f (x), whose values at a set of distinct points x 0 , x 1 , x 2 ,...,x n are known, by a polynomial P (x) such that P (x i )= f (x i ), i =0, 1, 2,...,n. Such a polynomial is known as an interpolating polynomial. An approximation of this function is desirable if f (x) is dicult to evaluate or manipulate like the error function erf(x)= 2 π x 0 e -t 2 dt, for example. Note that polynomials are easily evaluated, dierentiated or integrated. Another purpose of such an approximation is that a very long table of function values f (x i ) may be replaced by a short table and a compact interpolation subroutine. 4.1 Linear Interpolation Let f (x) be given at two distinct points x i and x i+1 . Now, given f (x i )= f i and f (x i+1 )= f i+1 , we wish to determine the interpolating polynomial P 1 (x) of degree 1 (i.e., a straight line) that approximates f (x) on the interval [x i ,x i+1 ]. Let P 1 (x)= αx + β. From the conditions P 1 (x i )= f i and P 1 (x i+1 )= f i+1 we obtain the two equations αx i + β = f i αx i+1 + β = f i+1 , i.e., x i 1 x i+1 1 α β = f i f i+1 . This system is clearly nonsingular since x i = x i+1 , and it has a unique solution: α = f i+1 - f i x i+1 - x i β = f i x i+1 - f i+1 x i x i+1 - x i . Therefore, P 1 (x)= f i + f i+1 - f i x i+1 - x i (x - x i ). Example 4.1 Using linear interpolation, approximate sin 6.5 from a table which gives (a) sin 6 =0.10453; sin 7 =0.12187. (b) sin 0 = 0; sin 10 =0.17365.

Upload: dangdiep

Post on 11-Jul-2019

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chapter 4

Polynomial Interpolation

In this chapter, we consider the important problem of approximating a function f(x), whose values at a set ofdistinct points x0, x1, x2, . . . , xn are known, by a polynomial P (x) such that P (xi) = f(xi), i = 0, 1, 2, . . . , n.Such a polynomial is known as an interpolating polynomial. An approximation of this function is desirableif f(x) is di!cult to evaluate or manipulate like the error function

erf(x) =2!!

! x

0e!t2dt,

for example. Note that polynomials are easily evaluated, di"erentiated or integrated. Another purpose ofsuch an approximation is that a very long table of function values f(xi) may be replaced by a short tableand a compact interpolation subroutine.

4.1 Linear Interpolation

Let f(x) be given at two distinct points xi and xi+1. Now, given f(xi) = fi and f(xi+1) = fi+1, we wishto determine the interpolating polynomial P1(x) of degree 1 (i.e., a straight line) that approximates f(x) onthe interval [xi, xi+1].

Let P1(x) = "x + #. From the conditions P1(xi) = fi and P1(xi+1) = fi+1 we obtain the two equations

"xi + # = fi

"xi+1 + # = fi+1,

i.e., "xi 1

xi+1 1

#""#

#="

fi

fi+1

#.

This system is clearly nonsingular since xi "= xi+1, and it has a unique solution:

" =fi+1 # fi

xi+1 # xi# =

fixi+1 # fi+1xi

xi+1 # xi.

Therefore,

P1(x) = fi +"

fi+1 # fi

xi+1 # xi

#(x# xi).

Example 4.1 Using linear interpolation, approximate sin 6.5" from a table which gives

(a) sin 6" = 0.10453; sin 7" = 0.12187.

(b) sin 0" = 0; sin 10" = 0.17365.

56

Page 2: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 57

Solution

(a) P1(6.5) = 0.10453 +$

0.12187!0.104537!6

%$ 0.11320.

(b) P1(6.5) = 0 + 0.1736510 (6.5) $ 0.11287.

The first answer is correct to 5 decimals whereas the second answer is correct only to 2 decimals! !

Conclusion: Linear interpolation is suitable only over small intervals.

4.2 Polynomial Interpolation

Since linear interpolation is not adequate unless the given points are closely spaced, we consider higher orderinterpolating polynomials. Let f(x) be given at the selected sample of (n + 1) points: x0 < x1 < · · · < xn,i.e., we have (n+1) pairs (xi, fi), i = 0, 1, 2, . . . , n. The objective now is to find the lowest degree polynomialthat passes through this selected sample of points.

f(x)Pn(x)

f(x)

x0 x1 x2 x3 ... xn

Figure 4.1: Interpolating the function f(x) by a polynomial of degree n, Pn(x).

Consider the nth degree polynomial

Pn(x) = a0 + a1x + a2x2 + · · · + anxn.

We wish to determine the coe!cients aj , j = 0, 1, . . . , n, such that

Pn(xj) = f(xj), j = 0, 1, 2, . . . , n.

These (n + 1) conditions yield the linear system

a0 + a1x0 + a2x20 + · · · + anxn

0 = f0

a0 + a1x1 + a2x21 + · · · + anxn

1 = f1

a0 + a1x2 + a2x22 + · · · + anxn

2 = f2...

......

......

a0 + a1xn + a2x2n + · · · + anxn

n = fn

or V a = f , where aT = (a0, a1, . . . , an), fT = (f0, f1, . . . , fn), and V is an (n + 1)% (n + 1) matrix given by

V =

&

'''''(

1 x0 x20 · · · xn

0

1 x1 x21 · · · xn

1

1 x2 x22 · · · xn

2...

......

...1 xn x2

n · · · xnn

)

*****+.

Page 3: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 58

The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero determinant

det(V ) =n!1,

j=0i>j

(xi # xj).

For n = 3, for example,

det(V ) = (x1 # x0)(x2 # x0)(x3 # x0)(x2 # x1)(x3 # x1)(x3 # x2)

Hence a can be uniquely determined as a = V !1f . Another proof of the uniqueness of the interpolatingpolynomial can be given as follows.

Theorem 4.1 Uniqueness of interpolating polynomial. Given a set of points x0 < x1 < · · · < xn,there exists only one polynomial that interpolates a function at those points.

Proof Let P (x) and Q(x) be two interpolating polynomials of degree at most n, for the same set of pointsx0 < x1 < · · · < xn. Also, let

R(x) = P (x)#Q(x).

Then R(x) is also a polynomial of degree at most n. Since

P (xi) = Q(xi) = fi,

we have, R(xi) = 0 for i = 0, 1, . . . , n. In other words R(x) has (n + 1) roots. From the FundamentalTheorem of Algebra however, R(x) cannot have more than n roots. A contradiction! Thus, R(x) & 0, andP (x) & Q(x). !

Example 4.2 Given the following table for the function f(x), obtain the lowest degree interpolatingpolynomial.

xk –1 2 4fk –1 –4 4

Solution Since the number of nodes = 3 = n + 1, therefore n = 2. Let

P2(x) = a0 + a1x + a2x2,

that satisfies the following conditions at the points x0 = 1; x1 = 2, x2 = 4:

P (#1) = #1; P (2) = #4; P (4) = 4.&

(1 #1 11 2 41 4 16

)

+

&

(a0

a1

a2

)

+ =

&

(#1#4

4

)

+ .

Using Gaussian elimination with partial pivoting, we compute the solution

a =

&

(a0

a1

a2

)

+ =

&

(#4#2

1

)

+ ,

Therefore, the interpolating polynomial is given by

P2(x) = #4# 2x + x2.

We can use this approximation to estimate the root of f(x) that lies in the interval [2, 4]:

$ =2 +!

4 + 162

= 1 +!

5.

Page 4: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 59

!

An important remark is in order. One, in general, should not determine the interpolating polynomial bysolving the Vandermonde linear system. These systems are surprisingly ill-conditioned for n no larger than10. For example, for 0 < x0 < x1 < · · · < xn = 1 uniformly distributed in [0,1], large n yields a Vandermondematrix with almost linearly dependent columns, and the Vandermonde system becomes almost singular.

A more satisfactory form of the interpolating polynomial is due to Lagrange,

Pn(x) = f(x0)L0(x) + f(x1)L1(x) + · · · + f(xn)Ln(x).

Here Lj(x), for 0 ' j ' n, are polynomials of degree n called fundamental polynomials or Lagrange polyno-mials. From the (n + 1) conditions

Pn(xi) = f(xi), 0 ' i ' n,

we see thatLj(xi) =

-0 i "= j1 i = j

The above property is certainly satisfied if we choose

Lj(x) =(x# x0)(x# x1) · · · (x# xj!1)(x # xj+1) · · · (x# xn)

(xj # x0)(xj # x1) · · · (xj # xj!1)(xj # xj+1) · · · (xj # xn)

i.e.,

Lj(x) =n,

i=0i#=j

(x# xi)(xj # xi)

.

The fact that Lj(x) is unique follows from the uniqueness of the interpolation polynomial.Recall that there is one and only one polynomial of degree n or less that interpolates f(x) at the (n + 1)

nodes x0 < x1 < · · · < xn. Thus, for this given set of nodes, both forms yield the same polynomial!

Vandermonde Approach.

Pn(x) =n.

i=0

aixi V a = f

Operation count: It can be shown that the Vandermonde system V a = f can be solved in O(n2) arithmeticoperations rather than O(n3) operations because of the special form of the Vandermonde matrix.

Lagrange Approach.

Pn(x) =n.

j=0

fjLj(x) =n.

j=0

gj

/

00001

n,

i=0

(x # xi)

(x# xj)

2

33334=

n.

j=0

gj · %j

wheregj =

f(xj)n,

i=0i#=j

(xj # xi).

Operation count: The Lagrange form avoids solving the ill-conditioned Vandermonde linear, systems, andevaluates the polynomials

%j =1

(x # xj)

n,

i=0

(x# xi)

Page 5: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 60

for a given x. The cost of these operations for each j = 0, 1, 2, . . . , n are:

u(x) =n,

i=0

(x# xi) ( (2n + 1) ops

%j =u(x)

(x# xj)( (n + 1) ops

gj =fj

n,

i=0i#=j

(xj # xi)( 2n(n + 1) ops (evaluated once only)

Now, the cost for evaluating the polynomial

Pn(x) =n.

j=0

gj%j ( (2n + 1) ops

Therefore, the total number of operations are 5n + 3 once gj’s are evaluated.

4.3 Error in Polynomial Interpolation

Let en(x) be the error in polynomial interpolation given by

en(x) = f(x)# Pn(x).

Since Pn(xi) = f(xi), we haveen(xi) = 0 x0 < x1 < · · · < xn.

In other words en(x) is a function with at least (n + 1) roots. Hence, we can write

f(x)Pn(x)

f(x)

x0 x1 x2 x3 ... xn

Figure 4.2: Computing the error in polynomial interpolation.

en(x) = (x # x0)(x # x1) · · · (x # xn)h(x) = !(x) · h(x)

where h(x) is a function of x. Let us define

g(z) = en(z)# !(z)h(x)

where x "= xj , for 0 ' j ' n. Thus,

g(x) = 0,

g(xj) = 0, 0 ' j ' n,

Page 6: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 61

i.e., g(z) has (n+2) distinct roots. Assuming that f(x) has at least n+1 continuous derivatives, the (n+1)thderivative of g(z), i.e.,

d(n+1)

dz(n+1)g(z) & g(n+1)(z)

has at least one root x$. Hence,

g(z)x0

x1

x2x3

x4

x*

g! z( )

g!! z( )

g!!! z( )

giv z( )

Figure 4.3: The (n + 1)th derivative of a function g(x) with n + 2 roots (n = 3) must have at least one root.

g(n+1)(z) = e(n+1)n (z)# h(x)!(n+1)(z),

where !(n+1)(z) = (n + 1)! Moreover, since en(z) = f(z)# Pn(z), therefore,

e(n+1)n (z) = f (n+1)(z)# P (n+1)

n (z)

in which the last term P (n+1)n (z) is zero. Using the above equations, we have

g(n+1)(z) = f (n+1)(z)# h(x)(n + 1)!

We had shown earlier that g(n+1)(z) has at least one root x$ in the interval containing x and xj , j = 0, . . . , n.This implies that g(n+1)(x$) = 0, and therefore,

h(x) =f (n+1)(x$)(n + 1)!

Consequently, we have the following representation of the error in polynomial interpolation

en(x) = f(x)# Pn(x) = (x # x0)(x # x1) · · · (x # xn)f (n+1)(x$)(n + 1)!

where x$ is in the interval containing x and xj , j = 0, . . . , n.

Page 7: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 62

Example 4.3 Obtain the Lagrange interpolating polynomial from the data

sin 0 = 0, sin!

6=

12, sin

!

3=!

32

, sin!

2= 1,

and use it to evaluate sin !12 and sin !

4

Solution The interpolating polynomial is given by

P3(x) = f0L0(x) + f1L1(x) + f2L2(x) + f3L3(x)

=12L1(x) +

!3

2L2(x) + L3(x)

At x = !12 ,

L1

$ !

12

%=5

!12 # 0

6 5!12 #

!3

6 5!12 #

!2

65

!6 # 0

6 5!6 #

!3

6 5!6 #

!2

6 =1516

L2

$ !

12

%=5

!12 # 0

6 5!12 #

!6

6 5!12 #

!2

65

!3 # 0

6 5!3 #

!6

6 5!3 #

!2

6 = # 516

L3

$ !

12

%=5

!12 # 0

6 5!12 #

!6

6 5!12 #

!3

65

!2 # 0

6 5!2 #

!6

6 5!2 #

!3

6 =116

Therefore,P3

$ !

12

%= 0.26062.

Since sin !12 = 0.25882, we have |error| = 0.0018.

At x = !4 ,

L1

$!

4

%= 0.5625, L2

$!

4

%= 0.5625, L3

$!

4

%= 0.0625.

ThereforeP3

$!

4

%= 0.70589.

Since sin !4 = 0.70711, we have |error| = 0.00122.

Let us estimate the error en(x) at x = !4 :

e3

$!

4

%=$!

4# 0%$!

4# !

6

%$!

4# !

3

%$!

4# !

2

% f (4)(x$)4!

Since f(x) = sin x; f (4)(x) = sin x, and thus,

|f (4)(x)| ' 1.

Therefore, 777e3

$!

4

%777 '!

4· !

12· !

12· !

4· 14!

= 1.76% 10!3.

Similarly, en(x) at x = !12 is bounded by

777e3

$ !

12

%777 '!

12· !

12· !

4· 5!

12· 14!

= 2.94% 10!3.

!

Page 8: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 63

4.4 Runge’s Function and Equidistant Interpolation

In this section, we discuss a problem that arises when one constructs a global interpolation polynomial on afairly large number of equally spaced nodes. Consider the problem of approximating the following functionon the interval [#1, 1]

f(x) =1

1 + 25x2

using the interpolation polynomial Pn(x) on the equidistant nodes

xj = #1 +2j

n, j = 0, 1, . . . , n.

Figure ?? shows how the polynomials P4(x), P8(x), P12(x), and P16(x) approximate f(x) on [#1, 1]. We see

−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

1n = 4

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

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1n = 8

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

−3.5

−3

−2.5

−2

−1.5

−1

−0.5

0

0.5

1n = 12

−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

2n = 16

Figure 4.4: Equal spaced interpolation of Runge’s function.

that as n increases, the interpolation error in the central portion of the interval diminishes, while increasingrapidly near the ends of the interval. Such behavior is typical in equidistant interpolation with polynomialsof high degree. This is known as Runge’s phenomenon, and the function f(x) is known as Runge’s function.

If the (n + 1) interpolation nodes are not chosen equally spaced, but rather placed near the ends of theinterval at the roots of the so called Chebyshev polynomial of degree (n + 1), the problem with Runge’sfunction disappears (see Fig. ??). The roots of the Chebyshev polynomial of degree (n + 1) are given by

xk = # cos"

k + 12

n + 1!

#, k = 0, 1, . . . , n.

Page 9: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 64

−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.2n = 4

−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.2n = 8

−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

1n = 12

−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

1n = 16

Figure 4.5: Chebyshev interpolation of Runge’s function.

4.5 The Newton Representation

The Lagrange form for the interpolating polynomial is not suitable for practical computations. The Newtonform of the interpolating polynomial proves to be much more convenient. Let us obtain a di"erent form ofthe lowest degree interpolating polynomial at the distinct interpolation nodes given by

x0 < x1 < x2 < · · · < xn!1

where f(xj) = fj , j = 0, 1, . . . , n# 1. Let the interpolating polynomial be

Pn(x) = c0 + c1(x# x0) + c2(x# x0)(x# x1) +c3(x # x0)(x # x1)(x# x2) + · · · +cn(x # x0)(x # x1) · · · (x # xn!1).

Using the n conditionsPn(xj) = fj, j = 0, 1, . . . , n# 1,

we can construct a system of equations in the unknown cj . For n = 3, for example, this yields a system oflinear equations of the form Lc = f , where L is given by,

L =

&

''(

1 0 0 01 (x1 # x0) 0 01 (x2 # x0) (x2 # x0)(x2 # x1) 01 (x3 # x0) (x3 # x0)(x3 # x1) (x3 # x0)(x3 # x1)(x3 # x2)

)

**+ .

Page 10: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 65

Note that the evaluation of L for n nodes requires O(n2) arithmetic operations. Assuming that the nodesare equidistant, i.e., xi+1 # xi = h, the system Lc = f is given by

&

''(

1 0 0 01 h 0 01 2h 2h2 01 3h 6h2 6h3

)

**+

&

''(

c0

c1

c2

c3

)

**+ =

&

''(

f0

f1

f2

f3

)

**+ .

Step 1.

c0 = f0

f (1)1 = (f1 # f0)/h

f (1)2 = (f2 # f0)/2h

f (1)3 = (f3 # f0)/3h.

Then we have the system order 3:&

(1 0 01 h 01 2h 2h2

)

+

&

(c1

c2

c3

)

+ =

&

'(f (1)1

f (1)2

f (1)3

)

*+ .

Step 2.

c1 = f (1)1

f (2)2 = (f (1)

2 # f (1)1 )/h

f (2)3 = (f (1)

3 # f (1)1 )/2h

Then we get the system of order 2:"

1 01 h

#"c2

c3

#=

8f (2)2

f (2)3

9.

Step 3.

c2 = f (2)2

f (3)3 = (f (2)

3 # f (2)2 )/h

Step 4.c3 = f (3)

3

MATLAB

function c = InterpolateNewton(x,f)% x: interpolating nodes% f: function values at x% c: coef. of Newton’s form of interpolating polynomial

n = length(x);for k = 1:n-1

f(k+1:n) = (f(k+1:n)-f(k))./(x(k+1:n)-x(k));endc = y;

Page 11: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 66

4.6 Spline Interpolation

Draftsmen used to draw smooth curves through data points by using splines. These are thin flexible strips ofplastic or wood which were laid on paper and held with weights so as to pass through the required data points(or nodes). The weights are constructed in such a way that the spline is free to slip. As a result, the flexiblespline straightens out as much as it can subject to passing over these points. Theory of elasticity suggests

x1 x2 x3 x4

∞ ∞

Figure 4.6: Spline interpolation.

that this mechanical spline is given by a cubic polynomial (degree 3 polynomial) in each subinterval [xi, xi+1],i = 1, 2, . . . , n# 1, with adjacent cubics joint continuously with continuous first and second derivatives. Let

s(x) = a0 + a1x + a2x2 + a3x

3,

be the form of each cubic spline. Since we have (n# 1) subintervals [xi, xi+1], 1 ' i ' n# 1, then we have4(n# 1) unknowns; (4 parameters for each subinterval: x0,a1,a2, and a3). Suppose si(x) denotes the cubicspline the ith interval. The conditions to be satisfied by these cubic splines are:

1. Continuity at each interior node:

si!1(xi) = si(xi), i = 2, 3, . . . , n# 1.

2. Continuity of first derivative at each interior node:

s%i!1(xi) = s%i(xi), i = 2, 3, . . . , n# 1.

3. Continuity of second derivative at each interior node:

s%%i!1(xi) = s%%i (xi), i = 2, 3, . . . , n# 1.

4. Interpolation of function at each node:

s(xj) = f(xj), j = 1, 2, . . . , n.

These provide 3(n# 2) + n = 4n# 6 conditions; however, in order to completely specify the cubic splines,we still need 2 additional conditions. These are conditions specified at the end points x1 and xn. For the“mechanical” or “natural” spline we set

s%%(x1) = s%%(xn) = 0.

Page 12: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 67

Let the nodes xj , j = 1, 2, . . . , n, be equidistant, i.e.,

xj+1 # xj = h

and let,

&j =16s%%(xj)

i.e.,s%%i!1(xi) = s%%i (xi) = 6&i

for all i satisfying condition ??. Since

s(x) = a0 + a1x + a2x2 + a3x

3,

we have

s%(x) = a1 + 2a2x + 3a3x2

s%%(x) = 2a2 + 6a3x,

i.e., s%%(x) is a straight line. Thus, s%%i (x) takes the following form (see Fig. ??):

s%%i (x) =xi+1 # x

h(6&i) +

(x# xi)h

(6&i+1), i = 1, 2, . . . , n# 1.

6σi+1

6σi

xi x xi+1

h

s''i x( )

Figure 4.7: Computing spline within an interval.

Integrating once, we have

s%i(x) =#6&i

h· (xi+1 # x)2

2+

6&i+1

h· (x # xi)2

2+ #1

and integrating once more, we have

si(x) =&i

h(xi+1 # x)3 +

&i+1

h(x# xi)3 + #1x + #2

where #1 and #2 are constants. Clearly we can write si(x) as follows,

si(x) =&i

h(xi+1 # x)3 +

&i+1

h(x# xi)3 + $1(x# xi) + $2(xi+1 # x).

Using conditions ?? and ??,

si(xi) = fi ) fi = &ih2 + $2hsi(xi+1) = fi+1 ) fi+1 = &i+1h2 + $1h

Page 13: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 68

Therefore,

$1 =fi+1

h# &i+1h,

$2 =fi

h# &ih,

and

si(x) =&i

h(xi+1 # x)3 +

&i+1

h(x# xi)3 +

"fi+1

h# &i+1h

#(x# xi)

+"

fi

h# &ih

#(xi+1 # x)

s%i(x) =#3&i

h(xi+1 # x)2 +

3&i+1

h(x# xi)2 +

"fi+1

h# &i+1h

#

#"

fi

h# &ih

#.

Using condition ??, i.e., s%i(xi) = s%i!1(xi), we get

#3&ih +"

fi+1 # fi

h

## h(&i+1 # &i) = 3&ih +

"fi # fi!1

h

## h(&i # &i!1)

or&i+1 + 4&i + &i!1 =

#i ##i!1

hi = 2, 3, . . . , n# 1,

where#i =

fi+1 # fi

h.

Using the additional conditions &1 = &n = 0, we have

4&2 + &3 = (#2 ##1)/h&i!1 + 4&i + &i+1 = (#i ##i!1)/h i = 3, 4, . . . , n# 2

&n!2 + 4&n!1 = (#n!1 ##n!2)/h.

Now, assigning

gj =#j ##j!1

h=

fj+1 # 2fj + fj!1

h2,

we have the linear system&

'''''(

4 11 4 1

. . . . . . . . .1 4 1

1 4

)

*****+

&

'''''(

&2

&3...

&n!2

&n!1

)

*****+=

&

'''''(

g2

g3...

gn!2

gn!1

)

*****+.

The tridiagonal system above, denoted by [1, 4, 1], may be factored as follows:&

'''''(

1'1 1

'2 1. . . . . .

'n!3 1

)

*****+

&

''''''(

µ1 1µ2 1

µ3. . .. . . 1

µn!2

)

******+

The following conditions must be satisfied:

µ1 = 4, 'iµi = 1, 'i + µi+1 = 4

The algorithm for computing $L and U is given below.

Page 14: Polynomial Interpolation - cs.purdue.edu · Chap. 4. Polynomial Interpolation CS414 Class Notes 58 The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero

Chap. 4. Polynomial Interpolation CS414 Class Notes 69

Triangular decomposition for system [1,4,1]

µ1 = 4for i = 1, 2, . . . , n# 3

'i = µ!1i

µi+1 = 4# 'i

end;

Once $L and U are obtained, the above system is solved as shown in Chapter ??.