chapter 3 interpolation and polynomial approximation if a function y = f(x) is too complicated for...

19
Chapter 3 Interpolation and Polynomial Approximation If a function y = f(x) is too complicated f or calculation or is even unknown, one way to approximate it is to first obtain its v alues y 0 = f(x 0 ), … y n = f(x n ) at a sequence o f points x 0 x n , and then construct a rela tively simple approximating function g(x) f(x). If g(x) satisfies that g(x i ) = f(x i ) for al l i = 0, … n, it is called the interpolating f unction of f(x). The most commonly used in terpolating functions are …? algebraic polynomials. x 0 x 1 x 2 x 3 x 4 x g(x) f(x) 1/1 9

Upload: jason-cook

Post on 13-Dec-2015

236 views

Category:

Documents


1 download

TRANSCRIPT

Chapter 3 Interpolation and Polynomial Approximation

If a function y = f(x) is too complicated for calculation or is even unknown, one way to approximate it is to first obtain its values y0 = f(x0), … yn = f(xn) at a sequence of points x0 … xn, and then construct a relatively simple approximating function g(x) f(x).

If g(x) satisfies that g(xi) = f(xi) for all i = 0, … n, it is called the interpolating function of f(x). The most commonly used interpolating functions are …?algebraic polynomials.

x0 x1 x2 x3 x4x

g(x) f(x)

1/19

3.1 Interpolation and the Lagrange Polynomial

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

Find a polynomial of degree n, Pn(x) = a0 + a1x + … + anxn, such that Pn(xi) = yi for all i = 0, …, n.Note: for any i j, we must have xi xj .

n = 1

P1(x) is the line function through the two given points ( x0 , y0 ) and ( x1, y1 ) .

)()( 001

0101 xx

xxyy

yxP

10

1

xxxx

01

0

xxxx

= y0 + y1

Given x0 , x1; y0 , y1 . Find P1(x) = a0 + a1x such that P1(x0) = y0 and P1(x1) = y1 . Lagrange Basis,

satisfying L1,i(xj)=ij /* Kronecker Delta */

L1,0(x) L1,1(x)

1

0)(

ii1, i yxL

2/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

The mathematician S. had to move to a new place. His wife didn't trust him very much, so when they stood down on the street with all their things, she asked him to watch their ten trunks, while she got a taxi. Some minutes later she returned. Said the husband: "I thought you said there were ten trunks, but I've only counted to nine!" The wife said: "No, they're TEN!" "But I have counted them: 0, 1, 2, ..."

n 1Find Ln,i(x) for i = 0, …, n such that Ln,i(xj)=ij . Then let

. Hence Pn(xi) = yi .

n

iin yxP

0

)( Ln,i(x)

Ln,i

(x)

Each Ln,i has n roots x0 … xi … xn

n

jij ji

jin xx

xxxL

0

, )(

)()(

n

iiinn yxLxP

0, )()(

n

jj i

jinii xxCxxxxxxC0

0 )())...()...((Ln,i(x)

j i ji

ii xxCx

)(11)(Ln,i

The n-th Lagrange interpolating polynomial

3/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

Theorem: If x0, x1, …, xn are n + 1 distinct numbers and f is a function whose values are given at these numbers, then the n-th Lagrange interpolating polynomial is unique.

Proof: If not…

Then there exists two polynomials Pn(x) and Qn(x) both satisfying the interpolating conditions.

D(x) = Pn(x) – Qn(x) is a polynomial of degree n

Yet D(x) has distinct roots x0, x1, …, xn .n + 1

Note: Note: The interpolating polynomial is NOT unique unless its degree is The interpolating polynomial is NOT unique unless its degree is constrained to be no greater than constrained to be no greater than nn..

A counterexample is where A counterexample is where pp((xx) )

can be a polynomial of any degree.can be a polynomial of any degree.

n

iin xxxpxLxP

0

)()()()(

4/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

Analyze the Remainder

Suppose

Consider the truncation error )()()( xPxfxR nn

bxxxa n 10 and f Cn + 1[a, b].

Rolle’s Theorem: If (x) is sufficiently smooth with (x0) = (x1) = 0,

then there exists (x0 , x1) such that ’() = 0.

In general, if (x0) = (x1) = (x2) = 0

),(),,( 211100 xxxx such that 0)()( 10 There exist

),( 10 0)( such thatThere exists

0)()( 0 nxx

),( ba 0)()( nsuch thatThere exists

Rn(x) has at least rootsn+1

n

iin xxxKxR

0

)()()(

Fix any x xi for all i = 0, …, n. Define the function g for t in [a, b] by

n

iixtxKtRn

0

)()()(g(t)

g(x) has n+2 distinct roots x0 … xn x ),(,0)()1( bag xxn

!)1()()()1( nxKR xn

n !)1)(()()( )1()1( nxKPf x

nnx

n

!)1()(

)()1(

nf

xK xn

n

ii

xn

n xxn

fxR

0

)1(

)(!)1()(

)(

5/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

Note: Note:

Since in most of the cases x cannot be determined, we obtain the upper bound of f (n+1) instead. That is, estimate an Mn+1 such

that for all x(a,b) and take

as the upper bound of the total error.

The interpolating polynomial is accurate for any polynomial function f with degree n since f (n+1)(x) 0.

1)1( )(

nn Mxf

n

ii

n xxnM

0

1 ||)!1(

Quiz: Given xi = i +1, i = 0, 1, 2, 3, 4, 5. Which is the graph of L5, 2(x)? y

0

-

-

- 1

0.5

-0.5

1 2 3 4 5 6 x

y

0

-

-

- 1

0.5

-0.5

1 2 3 4 5 6 x

y

0

-

-

- 1

0.5

-0.5

1 2 3 4 5 6 x

A B C

6/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

Example: Suppose a table is to be prepared for the function f(x) = ex for x in [0, 1]. Assume that each entry of the table is accurate up to 8 decimal places and the step size is h. What should h be for linear interpolation to give an absolute error of at most 10– 6 ?

Solution: Suppose that [0, 1] is partitioned into n equal-spaced subintervals [x0, x1], [x1, x2], …, [xn–1 , xn], and x is in the interval [xk, xk+1]. Then the error estimation gives

))((!2

)(|)()(| 1

)2(

1 kk xxxxf

xPxf

))1()((2

hkxkhxe

42

2he

62

108

eh

h 1.72 10–3

Simply take n = 1000 and h = 0.001.

7/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

Example: Given23

3sin,

21

4sin,

21

6sin

Use the linear and the quadratic Lagrange polynomial of sin x to compute sin 50 and then estimate the errors.

Solution: First use x0, x1 and x1, x2 to compute the linear interpolations.

0x 1x 2x

18

5500

4

,6 10

xx Use

2

1

6/4/

6/

2

1

4/6/

4/)(1

xx

xP

)185(50sin 1

0 P 0.77614

Here )3

,6

(,sin)(,sin)( )2( xxxfxxf

and )4

)(6

(!2

)()(,

23sin

21

)2(

1 xx

fxR x

x

00762.0)185(01319.0 1 R sin 50 = 0.7660444…

Error of extrapolation 0.01001

3,

4 21 xx Use sin 50 0.76008, 00660.0

185~

00538.0 1

R

Error of interpolation 0.00596

In general, interpolation is better than extrapolation.

8/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

2

3

))((

))((

2

1

))((

))((

2

1

))((

))(()(

4363

46

3464

36

3646

342

xxxxxxxP

Now use x0, x1 and x2 to compute the quadratic interpolation.

)185(50sin 2

0 P 0.76543

23cos

21;)

3)(

4)(

6(

!3cos

)(2

xx xxxxR

00077.018500044.0 2

R sin 50 = 0.7660444…

Error of the quadratic interpolation 0.00061

Interpolation with higher degree usually obtain better results.

The higher the better? Nooooooo….

9/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

When you start writing the program, you will find how easy it is to calculate

the Lagrange polynomial.

Oh yeah? What if I find the current interpolation

not accurate enough? Then you might want to take

more interpolating points into account.

Right. Then all

the Lagrange basis, Ln,i(x), will have to be re-calculated.

Excellent point !Let’s look at Neville’s Method…

10/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

Definition: Let f be a function defined at x0, x1, …, xn, and suppose that m1, …, mk are k distinct integers with 0 mi n for each i. The Lagrange polynomial that agrees with f(x) at the k points denoted by

kmm xx ,...,1

).(,...,1xP

kmm

Theorem: Let f be defined at x0, x1, …, xk, and let xi and xj be two distinct numbers in this set. Then

)(

)()()()()( ,...,1,1,...,1,0,...,1,1,...,1,0

ji

kiiikjjj

xx

xPxxxPxxxP

describes the k-th Lagrange polynomial that interpolates f at the k+1 points x0, x1, …, xk .

Proof: For any 0 r k and r i and j, the two interpolating polynomials on the numerator are equal to f(xr) at xr , so P(xr) = f(xr).

The first polynomials on the numerator equals f(xi) at xi , while the second term is zero, so P(xi) = f(xi). Similarly P(xj) = f(xj). The k-th Lagrange polynomial that interpolates f at the k+1 points x0, x1, …, xk is unique.

11/19

Chapter 3 Interpolation and Polynomial Approximation -- Interpolation and the Lagrange Polynomial

Neville’s Method

x0

x1

x2

x3

x4

P0

P1

P2

P3

P4

P0,1

P1,2

P2,3

P3,4

P0,1,2

P1,2,3

P2,3,4

P0,1,2,3

P1,2,3,4

P0,1,2,3,4

HW: p.119 #5; p.120 #17

12/19

Chapter 3 Interpolation and Polynomial Approximation -- Divided Differences

3.2 Divided Differences

),()()(

],[ jiji

jiji xxji

xx

xfxfxxf

The 1st divided difference of f w.r.t. xi and xj

)(],[],[

],,[ kixx

xxfxxfxxxf

ki

kjjikji

The 2nd divided difference of f w.r.t. xi , xj and xk

1

11010

10

111010

],,...,[],,...,[

],,...,[],...,,[],...,[

kk

kkkk

k

kkkk

xxxxxfxxxf

xxxxxfxxxf

xxf

The k+1st divided difference of f w.r.t. x0 … xk+1

13/19

k

i ik

ik x

xfxxf

0 10 )(

)(],...,[

As a matter of fact,

where ,)()(0

1

k

iik xxx

k

ijj

jiik xxx0

1 )()(

Warning: my head is exploding…What is the point of this formula?

The value of f [ x0, …, xk ] is independent of the order of the numbers x0, …, xk .

Chapter 3 Interpolation and Polynomial Approximation -- Divided Differences

14/19

Chapter 3 Interpolation and Polynomial Approximation -- Divided Differences

Newton’s Interpolation

))...((...))(()()( 10102010 nnn xxxxaxxxxaxxaaxN

],[)()()( 000 xxfxxxfxf ],,[)(],[],[ 101100 xxxfxxxxfxxf

],...,,[)(],...,[],...,,[ 0010 nnnn xxxfxxxxfxxxf

1

2

… … … …n1

1 + (x x0) 2 + … … + (x x0)…(x xn1) n1

...))(](,,[)](,[)()( 102100100 xxxxxxxfxxxxfxfxf

))...(](,...,[ 100 nn xxxxxxf

))()...(](,...,,[ 100 nnn xxxxxxxxxf

Nn(x)Rn(x)

ai = f [ x0, …, xi ]

15/19

Chapter 3 Interpolation and Polynomial Approximation -- Divided Differences

Note: Note:

Since the Since the nn-th interpolating polynomial is unique, -th interpolating polynomial is unique, NNnn((xx) ) PPnn((xx))..

They must have the same truncation error. That is,They must have the same truncation error. That is,

)(!)1()(

)(],...,,[ 1

)1(

10 xn

fxxxxf k

xn

kn

),(,!

)(],...,[ maxmin

)(

0 xxk

fxxf

k

k

The procedure is similar to Neville’s method.The procedure is similar to Neville’s method.

f f ((xx00))

f f ((xx11))

f f ((xx22))

……f f ((xxnn11))

f f ((xxnn))

f f [[xx00, , xx11]]

f f [[xx11, , xx22]]

… …… …… …… …

f f [[xxnn11, , xxnn]]

f f [[xx00, , xx1 1 , , xx22]]

… …… …… …… …

f f [[xxnn22, , xxnn11, , xxnn]] f f [[xx00, , ……, , xxnn]] f f ((xxnn+1+1)) f f [[xxnn, , xxnn+1+1]] f f [[xxnn11, , xxnn, , xxnn+1+1]] f f [[xx11, , ……, , xxnn+1+1] ] f f [[xx00, , ……, , xxnn+1+1]]

16/19

Chapter 3 Interpolation and Polynomial Approximation -- Divided Differences

Formulae with Equal Spacing

If the points are equally spaced: ),...,0(0 nihixxi

forward difference

iii fff 1

ik

ik

i

k

ik ffff 1

111

)(

backward difference

111

i

ki

ki

k fff

i1ii fff

centered difference

21

21

11

ik

ik

ik fff

其中 )( 221

hii xff

17/19

Chapter 3 Interpolation and Polynomial Approximation -- Divided Differences

Some important properties Linearity: gbfaxgbxfa ))()(( If f (x) is a polynomial of degree m , then is a

polynomial of degree m – k and

)0()( mkxfk )(0)( mkxfk

The values of the differences can be obtained from the function

n

jjkn

jk

n fj

nf

0

)1(

n

jnjk

jnk

n fj

nf

0)1(

!)1)...(1(

jjnnn

j

n

where /* binomial coefficients */

And vice-versa kj

n

jkn fj

nf

0

k

k

khk

fxxf

!],...,[ 0

0

kn

k

knnnhkf

xxxf!

],...,,[ 1

k

kk

hf

f 0)( )(

From Rn

18/19

Chapter 3 Interpolation and Polynomial Approximation -- Divided Differences

Newton’s formulae

))...(](,...,[...)](,[)()( 1000100 nnn xxxxxxfxxxxfxfxN

Newton’s forward-difference formula

Newton’s backward-difference formula

Reverse the order of the points

))...(](,...,[...)](,[)()( 101 xxxxxxfxxxxfxfxN nnnnnnn

Let htxx 0 , then )()()( 00

0 xfk

thtxNxN k

n

knn

),(,))...(1()!1(

)()( 0

1)1(

nn

n

n xxhntttn

fxR

Let htxx n , then )()1()()(0

nk

n

k

knnn xf

k

thtxNxN

HW: p.131 #5(a)(b);

p.132 #13

19/19