what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · numerical...

26
Numerical Analysis, lecture 7: Interpolation (textbook sections 5.1–4) what is interpolation existence, uniqueness, error formula Newton’s polynomial & divided differences f x

Upload: hatruc

Post on 23-May-2018

217 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7: Interpolation

(textbook sections 5.1–4)

• what is interpolation

• existence, uniqueness, error formula

• Newton’s polynomial & divided differences

f

x

Page 2: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide !

P(xi ) = fi ! P(x)" f (x)

2

Interpolation fits a real function to discrete data (p. 99-100)

f

x

• P may be polynomial, trigonometric, piecewise,…• used in many numerical computations:! - special functions! - zero-finding (inverse interpolation)! - integration, differentiation, optimization,…• for noisy data, use approximation (chapter 9)

x0 f0x1 f1! !xn fn

Page 3: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 3

There is a unique polynomial of degree ≤ n interpolating data at n+1 distinct points (p. 101-102)

P(xi ) = fi (i = 0,1,…n) !

x0n x0

n"1 ! x0 1

x1n x1

n"1 ! x1 1" " " "

xnn xn

n"1 ! xn 1

#

$

%%%%%

&

'

(((((

V# $%%%% &%%%%

anan"1"

a0

#

$

%%%%%

&

'

(((((

=

f0f1"

fn

#

$

%%%%%

&

'

(((((

coefficients are determined by Vandermonde’s linear equation system

P(x) = anxn + an!1x

n!1 +!a1x + a0

if P and Q are degree ! n and interpolate f at n +1 distinct pointsthen P "Q is degree ! n and has n +1 distinct zerosso P "Q # 0

uniqueness

Va = f has at most 1 solution! V is nonsingular

existence

Page 4: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 4

Computing the interpolating polynomial in Matlab

>> x = [1.1; 1.2; 1.3];>> f = [0.8912; 0.9320; 0.9636];>> V = vander(x)

V = 1.2100 1.1000 1.0000 1.4400 1.2000 1.0000 1.6900 1.3000 1.0000

>> a = V\f

a = -0.4600 1.4660 -0.1648

>> polyval(a,1.15)

ans = 0.91275

Example (p. 100)

x f (x)1.1 0.89121.2 0.93201.3 0.9636

nested form

p(x) = !0.4600x2 +1.4660x ! 0.1648

= ((!0.4600)x +1.4660)x ! 0.1648

>> ans - sin(1.15)

ans = -1.3940e-05

Page 5: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 5

The error formula for polynomial interpolation (p. 102-103)

“truncation” error

f (x̂) ! P(x̂) = 1

(n +1)!(x̂ ! x0 )(x̂ ! x1)!(x̂ ! xn ) f

(n+1)(")

proof:

For x̂ ! xi , let A =f (x̂) " P(x̂)

(x̂ " x0 )(x̂ " x1)!(x̂ " xn )Then# (x) = f (x) " P(x) " A(x " x0 )(x " x1)!(x " xn )

has at least n + 2 distinct zeros, so

0 =# (n+1)($) = f (n+1)($) " A(n +1)!

Page 6: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 6

Interpolating sin(x) on [a,b] is uniformly convergent (p. 103)

b ! a = 0.2, n = 2 : f (x̂) ! P(x̂) " 0.23

3!= 0.0013

in particular

f (x̂) ! P(x̂) = 1

(n +1)!(x̂ ! x0 )(x̂ ! x1)!(x̂ ! xn ) f

(n+1)(")

compare slide 4: P(1.15) ! f (1.15) = 2.336 "10!5

f = sin ! f (n+1)(") # 1

x̂, xi $[a,b] ! x̂ % xi # b % a

&'(

)(! f (x̂) % P(x̂) #

b % a n+1

(n +1)!* 0

Page 7: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 7

Linear interpolation

P(x) = 1! x ! x0x1 ! x0

"#$

%&'f0 +

x ! x0x1 ! x0

f1

f (x) ! P(x) " 18x1 ! x0

2 maxx0 "#"x1

$$f (#)

f

x1x0

Example

x f (x)1.1 0.89121.2 ?1.3 0.9636

P(x) = 1! x !1.10.2

"#$

%&'0.8912 + x !1.1

0.2"#$

%&'0.9636

P(1.2) = 0.9274

Page 8: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 8

Newton’s form of the interpolating polynomial is incremental (p. 100-102)

Pk(x) interpolates at x0, x

1, ..., xk

P0(x) = c0P1(x) = P0(x) + c1(x ! x0 )P2(x) = P1(x) + c2(x ! x0 )(x ! x1)! = !

Pn (x) = Pn!1(x) + cn (x ! x0 )"(x ! xn!1)

coefficients can be found by forward substitution

11 x1 ! x01 x2 ! x0 (x2 ! x0 )(x2 ! x1)! ! ! "

1 xn ! x0 (xn ! x0 )(xn ! x1) # (xn ! xi )i=0

n!1

"

#

$

%%%%%%%%

&

'

((((((((

c0c1c2!

cn

#

$

%%%%%%%%

&

'

((((((((

=

f0f1f2!

fn

#

$

%%%%%%%%

&

'

((((((((

interpolates at x0

interpolates at x0 and x1

…at x0, x1 and x2

…at x0, x1 … and xn

Page 9: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 9

Divided differences are a convenient way to compute the Newton form (p. 107-110)

lemma

P(x) = 6! 5(x +1)+ 2(x +1)x

+ 13 (x +1)x(x ! 2)

Example (p. 109-110)

x f f [i,i] f [i,i,i] f [i,i,i,i]!1 60 1 !52 3 1 25 66 21 4 1 3

P0,1,…,k (x) = P0,1,…,k!1(x) +x ! x0xk ! x0

P1,…,k (x) ! P0,1,…,k!1(x)( )

theorem f x0[ ] = f0

f x0, x1,…, xk[ ] = f x1, x2,…, xk[ ]! f x0, x1,…, xk!1[ ]

xk ! x0

The coefficient of xk in P0,1…k is denoted f x0, x1,…, xk[ ]notation we called it ck on previous slide

Page 10: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 10

Here are Matlab functions for Newton-form interpolation (p. 110-111)

>> x = [-1,0,2,5]; >> f = [6,1,3,66];>> c = intpolc(x,f) c = 6 -5 2 0.33333

function f = intpolc(x,f)m = length(x);for k = 2:m f(k:m) = (f(k:m) - f(k-1:m-1)) ./ ... (x(k:m) - x(1:m+1-k));end

function p = intpval(x,c,t)m = length(x);p = c(m) * ones(size(t));for k = m-1:-1:1 p = p.*(t-x(k)) + c(k);end

nested multiplication

−1 0 1 2 3 4 5−20

0

20

40

60

80

>> t = -1:.05:5; >> p = intpval(x,c,t);>> plot(x,f,'o',t,p,'r-')

Page 11: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 11

Divided differences have some interesting properties (p.109, 112)

mean value theorem f [x0, x1,…, xk ] =f (k)(!)k!

permutation of points f [x0, x1,…, xk ] = f [xr0, xr1

,…, xrk]

d.d. of polynomial deg p < n ! p[x0, x1,…, xn ] = 0

rule of thumb: error ≈ next term

f (x) ! Pk-1(x) " ck (x ! x0 )(x ! x1)!(x ! xk!1)

Page 12: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 12

what happened, what’s next

• data at n+1 distinct points determine a unique interpolating poly. of degree ≤ n

• compute it with Vandermonde matrix or with divided differences (Newton polynomial)

• error formula

Next lecture: more interpolation (§5.5-8)

Page 13: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8: Interpolation II

(textbook sections 5.5–8)

• Neville’s method

• Runge’s phenomenon

• Hermite’s interpolation

0

1

2

0

1

2

−1 0 1

0

1

2

Page 14: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 2

Recall that the interpolation polynomial P(x) agrees with f(x) at the points x0, x1, …, xn

P(x) = f [x0 ]+ f [x0, x1](x ! x0 )+ f [x0, x1, x2 ](x ! x0 )(x ! x1) +…+ f [x0, x1,…, xn ](x ! x0 )!(x ! xn!1)

Newton form’s coefficients

f x0[ ] = f0

f x0,…, xk[ ] = f x1,…, xk[ ]! f x0,…, xk!1[ ]

xk ! x0

x0n x0

n!1 ! x0 1

x1n x1

n!1 ! x1 1" " " "

xnn xn

n!1 ! xn 1

"

#

$$$$$

%

&

'''''

anan!1"

a0

"

#

$$$$$

%

&

'''''

=

f0f1"

fn

"

#

$$$$$

%

&

'''''

standard form’s coefficients

P(x) = anxn + an!1x

n!1 +!a1x + a0

f

x

Page 15: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 3

Neville’s method evaluates the interpolantwithout finding the coefficients (p. 113-115)

lemmaP0,1,…,k (x) = P0,1,…,k!1(x) +

x ! x0xk ! x0

P1,…,k (x) ! P0,1,…,k!1(x)( )

=(x ! x0 )P1,…,k (x) ! (x ! xk )P0,1,…,k!1(x)

xk ! x0

1! xi xi fi = Pi Pi,i+1 Pi…i+2 Pi…i+32 !1 6

1 0 1 2 "1!1 "60 +1

= !4

!1 2 3 1 " 3! (!1) "12 ! 0

= 2 2 "2 ! (!1) " (!4)2 +1

= 0

!4 5 66 !1 "66 ! (!4) " 35 ! 2

= !18 1 " (!18) ! (!4) "25 ! 0

= !2 2 " (!2) ! (!4) "05 +1

= !23

example (p. 115): find P(1)

!P(1) = "23

Page 16: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 4

The Neville formula is easily computed in Matlab

function p = neville(x,f,t)m = length(x);p = f(:) .* ones(1,length(t(:)));for k = 2:m for j = m:-1:k p(j,:) = ((t(:).'-x(j-k+1)).*p(j,:) ... - (t(:).'-x(j)).*p(j-1,:)) ... / (x(j)-x(j-k+1)); endendp = reshape(p(m,:),size(t));

>> neville([-1 0 2 5],[6 1 3 66],1)

ans =

-0.6667

Page 17: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 5

Runge’s example shows that adding data can worsen the approximation (p. 118-119)

Moral: interpolation with high degree polynomials is risky

f = @(x) 1./(1+25*x.^2);t = -1:.01:1;for n=[4,6,10] x=-1+2*(0:n)/n; plot(x,f(x),'o',t,f(t),... t,neville(x,f(x),t))end

0

1

2

0

1

2

−1 0 1

0

1

2

Page 18: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 7, slide ! 6

Linear interpolation is stableto perturbations in data (p. 104-106)

f

x

!

!

P(x) = 1! x ! x0x1 ! x0

"#$

%&'f0 +

x ! x0x1 ! x0

f1

f

x1x0

Example (p. 106)

If data has 4 correct decimals then

P(x) ! P(x) " 0.5 #10!4 for linear interpolation.

If P interpolates f at {x0, x1} and P interpolates f at {x0, x1}

and f ! f " # then P(x) ! P(x) " #.Theorem

Proof: P(x) = (1! u) " f0 + u " f1 where u = (x ! x0 ) / (x1 ! x0 )

then P ! P = (1! u) " ( f0 ! f0 ) + u " ( f1 ! f1)

# (1! u) " f0 ! f0# $!"# $#

+ u " f1 ! f1# $!"$

Page 19: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 7

The Hermite interpolation polynomial agrees with f(x) and with f′(x) at the nodes (p. 116-117)

x0 f0 !f0x1 f1 !f1! ! !xn fn !fn

interpolation conditionsP(xi ) = fi , !P (xi ) = !fi (i = 0,1,…n)

uniquenessif P and Q are degree ! 2n +1 and interpolate f and "f at n +1 distinct pointsthen P #Q is degree ! 2n +1 and has n +1 distinct zerosof multiplicity $ 2, so P #Q % 0

Page 20: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide !

Hermite polynomial can be found by solving Vandermonde-type equations

8

u F !F0 0.8912 0.090721 0.9636 0.05350

example (p. 117)

P(u) = !0.00058 "u3 ! 0.01774 "u2 + 0.09072 "u + 0.8912

P(u) = a3u3 + a2u

2 + a1u + a0

!P (u) = 3a3u2 + 2a2u + a1

P(0) = a0 = 0.8912, P(1) = a3 + a2 + a1 + a0 = 0.9636

!P (0) = a1 = 0.09072, !P (1) = 3a3 + 2a2 + a1 = 0.05350

0 0 0 11 1 1 10 0 1 03 2 1 0

!

"

####

$

%

&&&&

a3a2a1a0

!

"

####

$

%

&&&&

=

0.89120.96360.090720.05350

!

"

####

$

%

&&&&

' a3 = (0.00058, a2 = (0.01774, a1 = 0.09072, a0 = 0.8912

Page 21: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 9

The Hermite interpolation polynomial is easily computed in Matlab

function p = osculate(x,f,dfdx)n = length(x);x = x(:);v = ones(n,1);V(1:2*n,2*n) = [v;zeros(n,1)];for j = 1:2*n-1 V(n+1:end,2*n-j) = j*v; v = x.*v; V(1:n,2*n-j) = v;endp = (V\[f(:);dfdx(:)]).';

u F !F0 0.8912 0.090721 0.9636 0.05350

>> osculate([0,1],[0.8912,0.9636],[0.09072,0.05350])

ans =

-5.8000e-04 -1.7740e-02 9.0720e-02 8.9120e-01

example (p. 117)

P(u) = !0.00058 "u3 ! 0.01774 "u2 + 0.09072 "u + 0.8912

Page 22: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 10

The Hermite interpolation error formula (p. 117)

“truncation” error

f (x̂) ! P(x̂) = 1

(2n + 2)!(x̂ ! x0 )

2 (x̂ ! x1)2!(x̂ ! xn )

2 f (2n+2)(")

for 2 points: f (x̂) ! P(x̂) " 1

384(x1 ! x0 )

4 maxx0 "x"x1

f (4)(x)

proof:

For x̂ ! xi , let A =f (x̂) " P(x̂)

(x̂ " x0 )2 (x̂ " x1)2!(x̂ " xn )2

Then

# (x) = f (x) " P(x) " A(x " x0 )2 (x " x1)2!(x " xn )2

has at least n + 2 distinct zeros, so $# has n +1 distinct zerosin addition to the n +1 zeros at x0,…, xn , thus

0 =# (2n+2)(%) = f (2n+2)(%) " A(2n + 2)!

Page 23: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 11

Cardinal functions for 2-pointHermite interpolation (p. 116)

= A0 (x) ! f0 + A1(x) ! f1 + B0 (x) ! "f0 + B1(x) ! "f1

P(x0 ) = f0, P(x0 + h) = f1, !P (x0 ) = !f0, !P (x0 + h) = !f1

interpolation conditions

P(x) = f0 + h !f0 "x # x0h

$%&

'()+ 3( f1 # f0 ) # h(2 !f0 + !f1)( ) x # x0

h$%&

'()2

+ 2( f0 # f1) + h( !f0 + !f1)( ) x # x0h

$%&

'()3

formulas1

1

L3(x)

L1(x)

x3

x1

x0x1

A0

x0x1

B0

x0x1

A1

x0x1

B11

1

L3(x)

L1(x)

x3

x1

x0x1

A0

x0x1

B0

x0x1

A1

x0x1

B1

Page 24: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 12

2-point cubic Hermite interpolation is stableto perturbations in data (p. 117)

TheoremIf P interpolates f & !f at {x0, x1}, P interpolates f & !f at {x0, x1},

f " f # E and !f " !f # F, then P(x) " P(x) # E + 14 x1 " x0 F

example (p. 117)

x f !f1.1 0.8912 0.45361.3 0.9636 0.2675

If data in table is correct to 4 decimals

then P(x) ! P(x) " 0.5 #10!4 1+ 0.24

$%&

'()

Truncation error is f (x) ! P(x) "0.24

384* 0.5 #10!5

proof: P ! P = A0( f0 ! f0 ) + A1( f1 ! f1) + B0( "f0 ! "f0 ) + B1( "f1 ! "f1)

# A0 f0 ! f0 + A1 f1 ! f1 + B0 "f0 ! "f0 ! B1 "f1 ! "f1# (A0 + A1) $E + (B0 ! B1) $F

Page 25: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 13

cubic Hermitemax error(m)

US Patent 6424890: Method and apparatus for satellite orbit interpolation using piecewise Hermite interpolating polynomials

Page 26: what is interpolation existence, uniqueness, error …piche/numa/lecture0708.pdf · Numerical Analysis, lecture 7, slide !3 There is a unique polynomial of degree ≤ n interpolating

Numerical Analysis, lecture 8, slide ! 14

what happened, what’s next

• Neville’s method combines Newton polynomial construction and evaluation

• Runge’s example shows the dangers of high-degree polynomial interpolation

• Hermite interpolates f and f′• piecewise linear and cubic-Hermite

interpolation are stable

Next lecture: Integration (§7.1-3, 5)