22.07.2014 Views

1 - Computer Science Department - University of Kentucky

1 - Computer Science Department - University of Kentucky

1 - Computer Science Department - University of Kentucky

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CS537<br />

Introduction to Numerical<br />

Methods<br />

Lecture 2<br />

Interpolation and Numerical<br />

Differentiation<br />

Pr<strong>of</strong>essor Jun Zhang<br />

<strong>Department</strong> <strong>of</strong> <strong>Computer</strong> <strong>Science</strong><br />

<strong>University</strong> <strong>of</strong> <strong>Kentucky</strong><br />

Lexington, KY 40206‐0046<br />

September 12, 2013


Polynomial Interpolation<br />

Given a set <strong>of</strong> discrete values, how can we estimate other values<br />

between these data<br />

The method that we will use is called polynomial interpolation.<br />

We assume the data we had are from the evaluation <strong>of</strong> a smooth<br />

function. We may be able to use a polynomial p(x) to approximate this<br />

function, at least locally.<br />

A condition: the polynomial p(x) takes the given values at the given<br />

points (nodes), i.e., p(x i ) = y i with 0 ≤ i ≤ n. The polynomial is said to<br />

interpolate the table, since we do not know the function.<br />

2


Polynomial Interpolation<br />

Note that all the points are passed through by the curve<br />

3


Polynomial Interpolation<br />

We do not know the original function, the interpolation<br />

may not be accurate outside the set <strong>of</strong> data points<br />

4


Order <strong>of</strong> Interpolating Polynomial<br />

A polynomial <strong>of</strong> degree 0, a constant function, interpolates one set <strong>of</strong> data<br />

If we have two sets <strong>of</strong> data, we can have an interpolating polynomial <strong>of</strong><br />

degree 1, a linear function<br />

x x1<br />

x x0<br />

<br />

p(<br />

x)<br />

y0<br />

y1<br />

x0<br />

x1<br />

x1<br />

x0<br />

<br />

Review carefully if the condition is satisfied<br />

<br />

y<br />

0<br />

<br />

<br />

<br />

<br />

y<br />

x<br />

Interpolating polynomials can be written in several forms, the most well<br />

known ones are the Lagrange form and Newton form. Each has some<br />

advantages<br />

1<br />

1<br />

<br />

<br />

y<br />

x<br />

0<br />

0<br />

<br />

(<br />

x x<br />

<br />

0<br />

)<br />

5


Lagrange Form<br />

For a set <strong>of</strong> fixed nodes x 0 , x 1 ,…,x n , the cardinal functions, l 0 , l 1 ,…, l n ,<br />

are defined as<br />

0<br />

if i j<br />

li<br />

( x j ) ij <br />

1<br />

if i j<br />

We can interpolate any function f(x) by the Lagrange form <strong>of</strong> the<br />

interpolating polynomial <strong>of</strong> degree ≤ n<br />

p<br />

Note that l i (x) is <strong>of</strong> order n, so p n (x) is <strong>of</strong> order ≤ n, and<br />

p<br />

n<br />

( x<br />

j<br />

)<br />

<br />

n<br />

i1<br />

l<br />

i<br />

The (point exact) interpolation condition is satisfied<br />

n<br />

( x<br />

( x)<br />

j<br />

) f ( x<br />

<br />

n<br />

i0<br />

i<br />

)<br />

l<br />

<br />

i<br />

( x)<br />

f ( x<br />

l<br />

j<br />

( x<br />

j<br />

i<br />

)<br />

) f ( x<br />

j<br />

)<br />

<br />

f ( x<br />

j<br />

)<br />

6


Cardinal Functions<br />

7<br />

The cardinal function is<br />

What it looks like<br />

Note that<br />

and<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

n<br />

j<br />

i<br />

j<br />

j<br />

i<br />

j<br />

i<br />

n<br />

i<br />

x<br />

x<br />

x<br />

x<br />

x<br />

l<br />

0<br />

,<br />

)<br />

(0<br />

)<br />

(<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

n<br />

i<br />

n<br />

i<br />

i<br />

i<br />

i<br />

i<br />

i<br />

i<br />

i<br />

i<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

x<br />

l<br />

<br />

<br />

1<br />

1<br />

1<br />

1<br />

1<br />

1<br />

0<br />

0<br />

)<br />

(<br />

j<br />

i<br />

x<br />

l<br />

j<br />

i<br />

<br />

<br />

for<br />

0,<br />

)<br />

(<br />

1<br />

)<br />

( <br />

l i x i


Five Lagrange Basis Polynomials<br />

These are the 5 Lagrange basis polynomials for N=5<br />

8


Representation by Lagrange Polynomials<br />

Five weighted polynomials and their sum (red line) for a<br />

set <strong>of</strong> 5 random samples (red points)<br />

9


Step by Step Construction<br />

For any table <strong>of</strong> data, we can construct a Lagrange interpolating<br />

polynomial. Its evaluation is a little bit costly, but we can always do that.<br />

The existence <strong>of</strong> the interpolating polynomial is guaranteed<br />

Can we construct the interpolating polynomial step by step, or if we<br />

discover some new data, can we add those data to the existing<br />

interpolating polynomial to make the interpolation more accurate?<br />

We can use Newton form <strong>of</strong> the interpolating polynomial<br />

Let p k (x) be an interpolating polynomial for the date set {(x i ,y i )} with<br />

0 ≤ i ≤ k such that p k (x i ) = y i<br />

10


Newton Form ‐ Cont.<br />

We want to add another data (x k+1 , y k+1 ) to have a new interpolating<br />

polynomial p k+1 (x) such that p k+1 (x i ) = y i for 0 ≤ i ≤ (k + 1).<br />

Let<br />

p x)<br />

p ( x)<br />

c(<br />

x x )( x x ) (<br />

x x )<br />

where c is an undetermined constant<br />

Since<br />

p<br />

k1( k<br />

0 1<br />

k<br />

( x k 1)<br />

y 1,<br />

p ( x<br />

k 1 k <br />

k<br />

k1<br />

(<br />

x<br />

we have<br />

) c(<br />

x<br />

k1<br />

<br />

x<br />

k<br />

k1<br />

)<br />

<br />

We can solve this equation for c, with the condition that x 0 , x 1 , …, x k+1 are<br />

all distinct<br />

yk<br />

1<br />

pk<br />

( xk1)<br />

c <br />

( x x )( x x ) (<br />

x x )<br />

k 1<br />

0<br />

k1<br />

<br />

y<br />

x<br />

0<br />

k1<br />

1<br />

)( x<br />

k1<br />

<br />

k1<br />

x<br />

1<br />

)<br />

k<br />

11


Newton Polynomial Interpolation<br />

12


Uniqueness <strong>of</strong> Polynomial<br />

Is the interpolating polynomial unique?<br />

If p and q are interpolating polynomials for the data set {(x i ,y i )} for 0 ≤ i ≤ n<br />

such that p(x i ) = q(x i ) = y i<br />

Then the polynomial r(x) = p(x) – q(x) <strong>of</strong> degree at most n is zero at x 0 , x 1 ,<br />

…, x n . Note that a polynomial <strong>of</strong> degree n can have at most n roots, we<br />

must have r(x) = 0, or p – q = 0. Hence p = q<br />

The interpolating polynomial is unique<br />

It may be written in different forms<br />

13


An Example<br />

Find the interpolating polynomial for this table<br />

Lagrange form<br />

l<br />

l<br />

0<br />

1<br />

( x)<br />

( x)<br />

( x 1)( x 1)<br />

<br />

(0 1)(0 1)<br />

( x 0)( x 1)<br />

<br />

<br />

(1 0)(1 1)<br />

( x 0)( x 1)<br />

l2(<br />

x)<br />

<br />

<br />

( 1<br />

0)( 1<br />

1)<br />

The interpolating polynomial is<br />

(<br />

x 1)( x 1)<br />

1<br />

2<br />

x(<br />

x 1)<br />

1<br />

2<br />

x(<br />

x 1)<br />

3 15<br />

p2(<br />

x)<br />

5( x 1)( x 1) x(<br />

x 1) x(<br />

x 1)<br />

2 2<br />

14


Newton Form<br />

The zeroth order polynomial is<br />

p0(<br />

x)<br />

5<br />

Let the 1 st order interpolating polynomial be<br />

p<br />

( x)<br />

p0<br />

c(<br />

x x0<br />

)<br />

We want p 1 (x 1 ) = -3, hence -5 + c(1 – 0) = -3, we have c = 2, it follows that<br />

Let the 2 nd order interpolating polynomial be<br />

5<br />

c(<br />

x<br />

1 <br />

p<br />

p ( x)<br />

5<br />

2x<br />

1 <br />

( x)<br />

p1(<br />

x)<br />

c(<br />

x x0<br />

)( x 1)<br />

2 x<br />

Put p 2 (-1) = -15, i.e., -5+2(-1) + c(-1 – 0)(-1 – 1) = -15. We have c = -4.<br />

The Newton form <strong>of</strong> the interpolating polynomial is<br />

p2(<br />

x)<br />

5<br />

2x<br />

4x(<br />

x 1)<br />

0)<br />

15


Nested Form<br />

For easy programming and efficient computation, we can write Newton<br />

form <strong>of</strong> the interpolating polynomial in nested form<br />

p(<br />

x)<br />

a<br />

a<br />

a<br />

0<br />

3<br />

a1[(<br />

x x0<br />

)] a2[(<br />

x x0<br />

)( x <br />

[( x x0<br />

)( x x1)(<br />

x x2<br />

)] <br />

[( x x )( x x ) (<br />

x )]<br />

n 0 1 x n 1<br />

x<br />

1<br />

)]<br />

Or, using standard product notations as<br />

n i1<br />

p(<br />

x)<br />

a ai (<br />

x x j<br />

i1<br />

j1<br />

Using successive factorization, the nested form is<br />

p(<br />

x)<br />

a ( x x )( a ( x x )( a<br />

0<br />

( x x<br />

( ((<br />

a<br />

a<br />

n<br />

n2<br />

0 )<br />

0<br />

n1<br />

) a<br />

( x x<br />

1<br />

n<br />

n1<br />

) )(<br />

x x<br />

)) )<br />

) a<br />

0<br />

n1<br />

) a<br />

0<br />

1<br />

2<br />

<br />

<br />

<br />

)( x x<br />

<br />

n2<br />

)<br />

16


Computation Procedure<br />

To evaluate p(x) for a given x, we start from the innermost parentheses, forming<br />

successively some intermediate quantities<br />

v<br />

v<br />

v<br />

v<br />

v<br />

0<br />

1<br />

2<br />

i<br />

n<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

a<br />

v<br />

v<br />

v<br />

v<br />

n<br />

0<br />

1<br />

( x x<br />

( x x<br />

i1<br />

n1<br />

n1<br />

n2<br />

( x x<br />

( x x<br />

ni<br />

0<br />

) a<br />

) a<br />

) a<br />

n1<br />

n2<br />

) a<br />

0<br />

ni<br />

A pseudocode is<br />

real array ( ai<br />

) 0: n , ( xi<br />

) 0:<br />

integer i,<br />

n<br />

real x,<br />

v<br />

v an<br />

for i n 1 to 0 step -1do<br />

v <br />

v(<br />

x<br />

xi<br />

) ai<br />

end for<br />

n<br />

17


Divided Difference<br />

The coefficients a i in Newton form <strong>of</strong> the interpolating polynomial need to<br />

be computed. A notation is introduced to facilitate such computation<br />

a<br />

which is called the divided difference <strong>of</strong> order k for f<br />

k<br />

<br />

f[ x , x1,<br />

,<br />

x<br />

0 k<br />

]<br />

Newton form interpolating polynomial is<br />

p ( x)<br />

a<br />

Or written in a compact form<br />

with the convention<br />

n<br />

0<br />

a<br />

<br />

a<br />

p<br />

1<br />

( x x<br />

n<br />

n<br />

0<br />

( x x<br />

( x)<br />

<br />

1<br />

<br />

j0<br />

n<br />

0<br />

) a<br />

2<br />

( x x<br />

) (<br />

x x<br />

ai<br />

i0<br />

( x <br />

i1<br />

j0<br />

x j<br />

( x x<br />

) 1<br />

j<br />

0<br />

n1<br />

)<br />

)( x<br />

)<br />

<br />

x<br />

1<br />

)<br />

18


Computing Coefficients a i<br />

We want p n (x i ) = f(x i ). So we have<br />

f<br />

f<br />

f<br />

( x<br />

( x<br />

( x<br />

<br />

) a<br />

) a<br />

) a<br />

<br />

The solution <strong>of</strong> this system is<br />

0<br />

1<br />

2<br />

0<br />

0<br />

0<br />

<br />

<br />

a<br />

a<br />

1<br />

1<br />

( x<br />

1<br />

( x<br />

2<br />

x<br />

0<br />

x<br />

a<br />

0<br />

)<br />

) a<br />

0 x<br />

2<br />

(<br />

f ( 0 )<br />

x<br />

2<br />

<br />

x<br />

0<br />

)(<br />

x<br />

2<br />

<br />

x<br />

1<br />

)<br />

a<br />

1<br />

<br />

<br />

f ( x1)<br />

a0<br />

x1<br />

x0<br />

f ( x1)<br />

f ( x<br />

x x<br />

The divided difference <strong>of</strong> order 1 is<br />

f ( x1)<br />

f ( x0<br />

)<br />

f [ x0<br />

, x1]<br />

<br />

x1<br />

x0<br />

Note that f[x 0 , x 1 ,…, x k ] is the coefficient <strong>of</strong> x k in the polynomial p k <strong>of</strong><br />

degree ≤ k<br />

1<br />

0<br />

0<br />

)<br />

19


Computing Coefficients –Cont.<br />

f ( x2<br />

) a0<br />

a1(<br />

x2<br />

x0<br />

)<br />

a2<br />

<br />

( x2<br />

x0<br />

)( x2<br />

x1)<br />

f ( x2<br />

) f [ x0<br />

] f [ x0<br />

, x1](<br />

x2<br />

x<br />

<br />

( x2<br />

x0<br />

)( x2<br />

x1)<br />

f [ x0<br />

, x1,<br />

x2<br />

]<br />

In general, we have<br />

f [ x0<br />

, x1,<br />

,<br />

xk<br />

] <br />

k1<br />

f ( x ) f [ x , x , ,<br />

x ] <br />

Computational algorithm<br />

•Set f[x 0 ] = f(x 0 )<br />

i0<br />

•For k = 1, 2,…, n, compute<br />

f[x 0 , x 1 ,…, x k ] using the above equation<br />

k<br />

<br />

0<br />

k 1<br />

j 0<br />

1<br />

( x<br />

k<br />

<br />

x<br />

i<br />

j<br />

)<br />

0<br />

)<br />

i1 j0<br />

( x<br />

k<br />

<br />

x<br />

j<br />

)<br />

20


Recursive Formula<br />

The divided difference has a recursive formula<br />

f[x , x , ,<br />

x ] <br />

Pro<strong>of</strong>:<br />

0<br />

f[x<br />

1<br />

1<br />

, x<br />

2<br />

k<br />

, ,<br />

x<br />

k<br />

] f[x<br />

x x<br />

k<br />

f[x 0 , x 1 ,…, x k ] is the coefficient <strong>of</strong> x k in the polynomial p k <strong>of</strong> degree ≤ k,<br />

which interpolates f at x 0 , x 1 ,…, x k<br />

f[x 1 , x 2 ,…, x k ] is the coefficient <strong>of</strong> x k-1 in the polynomial q k-1 <strong>of</strong> degree ≤<br />

(k –1), which interpolates f at x 1 , x 2 ,…, x k<br />

f[x 0 , x 1 ,…, x k-1 ] is the coefficient <strong>of</strong> x k-1 in the polynomial p k-1 <strong>of</strong> degree ≤<br />

(k –1), which interpolates f at x 0 , x 1 ,…, x k-1<br />

0<br />

0<br />

, x<br />

1<br />

, ,<br />

x<br />

k1<br />

]<br />

21


Recursive Formula ‐ Pro<strong>of</strong><br />

We have<br />

x xk<br />

pk<br />

( x)<br />

qk1(<br />

x)<br />

[ qk1(<br />

x)<br />

pk1(<br />

x)]<br />

xk<br />

x0<br />

To prove this identity, it suffices to show that it holds at (k + 1) different<br />

points, since the left‐hand side and the right‐hand side are polynomials <strong>of</strong><br />

degree ≤ k. Note that the left‐hand side is p k (x i ) = f(x i ) for i = 0, 1,…, k<br />

Check the right‐hand side at point x 0<br />

q<br />

k1<br />

<br />

<br />

( x<br />

q<br />

p<br />

0<br />

k1<br />

k1<br />

) <br />

( x<br />

0<br />

( x<br />

x<br />

x<br />

0<br />

0<br />

k<br />

) [ q<br />

)<br />

<br />

<br />

<br />

x<br />

x<br />

k<br />

0<br />

[ q<br />

k 1<br />

f ( x<br />

( x<br />

0<br />

k1<br />

)<br />

0<br />

( x<br />

) <br />

0<br />

) <br />

p<br />

k1<br />

p<br />

k1<br />

( x<br />

0<br />

( x<br />

)]<br />

0<br />

)]<br />

22


Formula Pro<strong>of</strong> ‐ Cont.<br />

Check for points 1 ≤ i ≤ (k –1),<br />

xi<br />

x<br />

qk1(<br />

xi<br />

) <br />

x x<br />

<br />

f ( x<br />

i<br />

) <br />

k<br />

x<br />

x<br />

i<br />

k<br />

<br />

<br />

k<br />

0<br />

x<br />

x<br />

[ q<br />

k<br />

0<br />

k 1<br />

( x<br />

[ f ( x<br />

i<br />

i<br />

) <br />

) <br />

p<br />

k 1<br />

f ( x<br />

i<br />

( x<br />

i<br />

)] <br />

)]<br />

f<br />

( x<br />

i<br />

)<br />

Check the right‐hand side at point x k<br />

xk<br />

xk<br />

qk1(<br />

xk<br />

) [ q<br />

x x<br />

Hence the said identity holds<br />

k<br />

f ( x<br />

We take the coefficients <strong>of</strong> x k on both sides, which yields the desired<br />

recursive formula<br />

<br />

0<br />

q<br />

k 1<br />

k1<br />

( x<br />

( x<br />

k<br />

k<br />

)<br />

) <br />

<br />

p<br />

k1<br />

k<br />

( x<br />

)<br />

k<br />

)]<br />

23


Invariance Theorem<br />

The divided difference f[x 0 , x 1 ,…, x k ] is invariant under all permutations <strong>of</strong><br />

the arguments x 0 , x 1 ,…, x k<br />

This is because f[x 0 , x 1 ,…, x k ] is the coefficient <strong>of</strong> x k <strong>of</strong> the polynomial<br />

p k (x) <strong>of</strong> degree ≤ k that interpolates f at x 0 , x 1 ,…, x k . f[x 1 , x 0 ,…, x k ] is the<br />

coefficient <strong>of</strong> x k <strong>of</strong> the polynomial p k (x) <strong>of</strong> degree ≤ k that interpolates f at<br />

x 1 , x 0 ,…, x k . These two polynomials are the same<br />

The generic recursive formula is<br />

f [ x<br />

i<br />

, x<br />

i1<br />

, ,<br />

x<br />

j1<br />

,<br />

x<br />

j<br />

] <br />

f<br />

x<br />

, x , ,<br />

x <br />

f x<br />

, x , ,<br />

x <br />

i1<br />

i2<br />

x<br />

j<br />

j<br />

<br />

x<br />

i<br />

i<br />

i1<br />

j1<br />

24


Divided Difference Table<br />

We can construct a divided difference table for f to facilitate computation<br />

<strong>of</strong> the coefficients <strong>of</strong> the interpolating polynomial<br />

The coefficients along the top diagonal are the ones needed to form the<br />

Newton form <strong>of</strong> the interpolating polynomial<br />

20


Divided Difference Table<br />

20


Divided Difference Algorithm<br />

A pseudocode for computing divided difference is<br />

real array ( aij<br />

)<br />

integer i,<br />

j,<br />

n<br />

for i 0 to n do<br />

ai0<br />

f ( xi<br />

)<br />

end for<br />

for j 1 to n do<br />

for i 0 to n <br />

aij<br />

( ai1,<br />

j<br />

end for<br />

end for<br />

0: n0:<br />

n<br />

1<br />

j do<br />

a<br />

,<br />

i,<br />

j1<br />

( x<br />

i<br />

)<br />

) /( x<br />

0: n<br />

i<br />

j<br />

<br />

x<br />

i<br />

)<br />

This algorithm computes and stores all components <strong>of</strong> the divided<br />

difference. The coefficients <strong>of</strong> the Newton interpolating polynomial are<br />

stored in the first row <strong>of</strong> the array (a ij ) 0:n×0:n , i.e., in a(0 : n, 0)<br />

27


Computing the Coefficients only<br />

If we compute divided difference only for constructing Newton interpolating<br />

polynomial, there is no need to store the unnecessary divided difference<br />

terms. (But they will be computed, used, and discarded)<br />

real array<br />

integer i,<br />

j,<br />

n<br />

for i 0 to n<br />

a<br />

end<br />

for<br />

i<br />

f ( x )<br />

for<br />

j 1<br />

to n<br />

for i n to<br />

a<br />

( a<br />

end for<br />

end for<br />

i<br />

i<br />

( a )<br />

i<br />

i<br />

a<br />

0: n<br />

,<br />

do<br />

do<br />

j step 1<br />

do<br />

i1<br />

) /( x<br />

( x )<br />

i<br />

i<br />

The two algorithms assume the same computational cost<br />

0: n<br />

x<br />

i<br />

j<br />

)<br />

28


Memory Allocations<br />

Here we show how the memory is occupied and updated in computing<br />

coefficients <strong>of</strong> Newton interpolating polynomial<br />

Computation must be done backward to avoid erasing needed memory<br />

locations<br />

29


Divided Difference Table<br />

20


Newton Polynomial<br />

i 0 1 2 3 4<br />

0 1 2 3 4<br />

0 1 8 27 64<br />

20


Inverse Interpolation<br />

It is also possible to use a polynomial to approximate the inverse <strong>of</strong> a<br />

function y = f(x). Given a table<br />

An interpolation polynomial<br />

p(<br />

y)<br />

<br />

n<br />

i0<br />

c<br />

i1<br />

<br />

( y <br />

i y j<br />

j0<br />

)<br />

Can be constructed such that p(y i ) = x i . This interpolating polynomial is<br />

useful to find the approximate location <strong>of</strong> a root <strong>of</strong> a function f(x). E.g.,<br />

there is a root in [4.0,5.0] for this table<br />

32


Neville’s Algorithm<br />

Neville proposed a different scheme to construct interpolation polynomial<br />

step by step. Start with zero degree polynomials P i (x) = f(x i ), we<br />

construct higher degree interpolation polynomials by the recurrence<br />

relation<br />

x xi<br />

j <br />

Sij<br />

( x)<br />

<br />

Si,<br />

j1(<br />

x)<br />

xi<br />

x<br />

i<br />

j <br />

<br />

<br />

xi<br />

x<br />

<br />

xi<br />

x<br />

i1,<br />

j1<br />

( x)<br />

With S i0 (x) = P i (x) = f(x i ). The relation table can be written as<br />

i<br />

j<br />

<br />

<br />

S<br />

<br />

33


Interpolation Property<br />

Redefine constant polynomials as Pi<br />

( x)<br />

<br />

We can define higher order polynomial as<br />

P<br />

( j)<br />

i<br />

( x)<br />

<br />

<br />

<br />

x <br />

x<br />

i<br />

<br />

(0)<br />

x<br />

x<br />

i<br />

j<br />

i<br />

j<br />

<br />

<br />

P<br />

<br />

<br />

<br />

xi<br />

x<br />

<br />

xi<br />

x<br />

i<br />

j<br />

y<br />

i<br />

( j1)<br />

i<br />

<br />

<br />

P<br />

<br />

for 0 <br />

( x)<br />

( j1)<br />

i1<br />

( x)<br />

i<br />

<br />

n,<br />

The range <strong>of</strong> j is 1 ≤ j ≤ n and that <strong>of</strong> i is j ≤ i ≤ n<br />

The interpolation properties <strong>of</strong> these polynomials are:<br />

The polynomial P<br />

(j)<br />

i defined above interpolate as follows (see p. 153 for a<br />

pro<strong>of</strong>)<br />

P<br />

( j)<br />

i<br />

( x<br />

k<br />

) y<br />

k<br />

(0 i j k i n)<br />

34


Higher Dimensional Interpolation<br />

It is possible to define interpolation polynomials <strong>of</strong> several variables. The<br />

tensor‐product interpolation is used on rectangular domain [a,b] × [α,β].<br />

Select n nodes in [a,b] and define the Lagrange polynomials as<br />

l<br />

i<br />

( x)<br />

<br />

ji,<br />

j1<br />

x <br />

(1 i<br />

Select m nodes in [α,β] and define<br />

n<br />

y y<br />

j<br />

hi (y) <br />

( 1<br />

i m).<br />

y y<br />

n<br />

<br />

ji,<br />

j1<br />

i<br />

x<br />

i<br />

j<br />

<br />

x<br />

x<br />

j<br />

j<br />

n).<br />

Then function<br />

P(x, y)<br />

<br />

n<br />

<br />

i1<br />

m<br />

j1<br />

f (x<br />

i<br />

, y<br />

j)li(x)h<br />

j(y)<br />

Interpolates a two dimensional table with data<br />

x , y , f ( x , y ))<br />

( i j i j<br />

35


2D Interpolation<br />

20


Errors <strong>of</strong> Interpolation I<br />

If p is the polynomial <strong>of</strong> degree at most n that interpolates f at the n+1<br />

distinct nodes , ,…, belonging to an interval [a,b] and if is<br />

continuous for each x in [a,b], there is a in (a, b) for which<br />

f<br />

( x)<br />

<br />

p(<br />

x)<br />

<br />

( n<br />

1<br />

1)!<br />

f<br />

( n1)<br />

( z)<br />

n<br />

<br />

i0<br />

( x<br />

<br />

x<br />

i<br />

)<br />

What kind <strong>of</strong> function may have a small interpolation error?<br />

37


Errors <strong>of</strong> Interpolation II<br />

Let f be a function such that is continuous on [a,b] and satisfies<br />

.<br />

Let p be the polynomial <strong>of</strong> degree at most n that interpolates f at the n+1<br />

equally spaced nodes , ,…, in [a,b]. Then on [a,b],<br />

|<br />

f<br />

( x)<br />

<br />

p(<br />

x)<br />

| <br />

1<br />

4( n 1)<br />

n<br />

Mh<br />

1<br />

Where h=(b‐a)/n is the spacing between nodes.<br />

38


Computing First Derivative<br />

The first derivative can be approximated as<br />

1<br />

f '(<br />

x)<br />

[ f ( x h)<br />

f ( x)]<br />

(1)<br />

h<br />

For accurate approximation, h should be small. Thus f(x + h) and f(x) are<br />

close to each other. This may cause loss <strong>of</strong> significant digits in finite<br />

precision computation<br />

Using Taylor’s theorem, we have<br />

1 2<br />

f ( x h)<br />

f ( x)<br />

hf '( x)<br />

h f "( )<br />

2<br />

For ξ between x and x + h. It follows that<br />

1<br />

1<br />

f '(<br />

x)<br />

[ f ( x h)<br />

f ( x)]<br />

hf "( )<br />

h<br />

2<br />

1<br />

The approximation error <strong>of</strong> (1) is<br />

hf "( ),<br />

2 or <strong>of</strong> order O(h). This is a<br />

first order (or sided) approximation <strong>of</strong> first derivative. The error goes to 0<br />

as fast as h → 0<br />

39


Higher Order Approximation<br />

It is desirable to have some higher order (faster) approximation schemes<br />

1 2<br />

f ( x h)<br />

f ( x)<br />

hf '( x)<br />

h f "( x)<br />

2!<br />

1 3 1 4 (4)<br />

h f '''( x)<br />

h f ( x)<br />

<br />

3!<br />

4!<br />

1 2<br />

f ( x h)<br />

f ( x)<br />

hf '( x)<br />

h f "( x)<br />

2!<br />

1 3 1 4 (4)<br />

h f '''( x)<br />

h f ( x)<br />

<br />

3!<br />

4!<br />

Subtracting these two equations, we have<br />

f ( x h)<br />

<br />

<br />

2<br />

3!<br />

h<br />

3<br />

f ( x h)<br />

f '''( x)<br />

<br />

<br />

2<br />

5!<br />

2hf<br />

'( x)<br />

h<br />

5<br />

f<br />

(5)<br />

( x)<br />

<br />

40


It follows that<br />

2 nd Order Approximation<br />

f '( x)<br />

2<br />

<br />

1<br />

[ f ( x h)<br />

<br />

2h<br />

f ( x h)]<br />

h h (5)<br />

f '''( x)<br />

f ( x)<br />

<br />

3! 5!<br />

After dropping the higher order terms, we have a second order<br />

approximation formula as<br />

f<br />

'(<br />

x)<br />

1<br />

[ f ( x h)<br />

<br />

2h<br />

4<br />

f ( x h)]<br />

2<br />

The leading truncated terms <strong>of</strong> this approximation scheme is f '''( x).<br />

Hence the approximation is <strong>of</strong> O(h 2 6<br />

). The approximation error goes to 0 as<br />

fast as h 2 → 0. The exact truncation error is<br />

h<br />

<br />

h<br />

6<br />

f '''( 1)<br />

<br />

2<br />

f '''( 2 ) <br />

<br />

<br />

<br />

1 2 <br />

2<br />

<br />

<br />

1<br />

h<br />

6<br />

f '''( )<br />

41


2 nd Order Approximation<br />

20


Richardson Extrapolation (I)<br />

First derivative can be approximated as<br />

1<br />

f '( x)<br />

[ f ( x h)<br />

<br />

In which the constants a 2 ,a 4 ,… depend on the higher order derivatives <strong>of</strong> f<br />

and the value <strong>of</strong> x, (but) not on h. When such information is available, it is<br />

possible to construct much more accurate approximation schemes<br />

Define a function<br />

a<br />

2<br />

h<br />

2<br />

( h)<br />

<br />

2h<br />

a<br />

1<br />

2<br />

h<br />

4<br />

h<br />

4<br />

a<br />

f ( x h)]<br />

<br />

Which is an approximation to f’(x) with error <strong>of</strong> order O(h 2 ). This<br />

approximation becomes accurate as h → 0. So we can study the quantity<br />

lim h → 0 ψ(h)<br />

6<br />

h<br />

6<br />

[ f ( x h)<br />

<br />

f ( x h)]<br />

43


Richardson Extrapolation (II)<br />

Richardson extrapolation estimates the value <strong>of</strong> ψ(0) from some computed<br />

values <strong>of</strong> ψ(h) near 0<br />

Multiply the 2 nd equation by 4 and subtract it from the 1 st equation<br />

Hence<br />

( h)<br />

h<br />

<br />

2 <br />

<br />

<br />

f '( x)<br />

a<br />

f '( x)<br />

a<br />

a<br />

h<br />

<br />

2 <br />

a<br />

h <br />

3 4 15<br />

( h)<br />

4<br />

3<br />

f '( x)<br />

a4h<br />

a6h<br />

2 <br />

4 16<br />

h<br />

<br />

2<br />

<br />

<br />

<br />

1 <br />

<br />

<br />

3 <br />

f’(x) can be computed as accurate as O(h 4 )<br />

2<br />

2<br />

h<br />

2<br />

h <br />

<br />

( h)<br />

2<br />

<br />

<br />

2<br />

4<br />

h<br />

4<br />

4<br />

6<br />

a<br />

6<br />

4<br />

h<br />

<br />

2 <br />

<br />

h<br />

6<br />

<br />

a<br />

6<br />

6<br />

h<br />

<br />

2 <br />

<br />

5<br />

<br />

16<br />

4 4<br />

6<br />

f '( x)<br />

h a6h<br />

a<br />

4<br />

<br />

44


General Approach<br />

A general Richardson extrapolation form<br />

( h )<br />

<br />

L <br />

<br />

k1<br />

a<br />

2k<br />

2k h<br />

Where we assume that ψ(h) is computable for any h > 0 and we want to<br />

approximate L as accurately as possible<br />

h<br />

Choose a special sequence define<br />

2<br />

n<br />

h <br />

D( n,0)<br />

( n 0)<br />

n<br />

2 <br />

Then, we have<br />

h <br />

D( n,0)<br />

L A(<br />

k,0)<br />

<br />

n<br />

<br />

k 1<br />

2 <br />

With A(k,0) = -a 2k . D(n,0) is a rough approximate <strong>of</strong> L = lim x→0 ψ(x)<br />

2k<br />

45


The extrapolation formula is<br />

Richardson Theorem<br />

4<br />

D(<br />

n,<br />

m)<br />

D(<br />

n,<br />

m 1) <br />

m<br />

4 1<br />

1<br />

D(<br />

n 1, m 1)<br />

m<br />

4 1<br />

Richardson Extrapolation Theorem:<br />

For 0 ≤ m ≤ n<br />

D(<br />

n,<br />

m)<br />

m<br />

<br />

L <br />

<br />

k m1<br />

<br />

A(<br />

k,<br />

m)<br />

<br />

2<br />

(1 m<br />

h<br />

n<br />

<br />

<br />

<br />

2k<br />

<br />

n)<br />

The pro<strong>of</strong> <strong>of</strong> this theorem is based on induction on m, see p. 175 <strong>of</strong> the<br />

Book. Pro<strong>of</strong> will not be given in class<br />

Not that D(n,m) approximates L at the order <strong>of</strong> O(h 2m ). The convergence<br />

rate is fast<br />

46


Computational Procedure<br />

Richardson extrapolation computational procedure:<br />

1.) write a procedure to compute ψ(h)<br />

2.) decide on suitable values for n and h<br />

3.) for i = 0, 1,…, n, compute<br />

D(<br />

i,0)<br />

( h / 2<br />

i<br />

)<br />

4.) for 0 ≤ i ≤ j ≤ n, compute<br />

D(<br />

i,<br />

j)<br />

<br />

D(<br />

i,<br />

j<br />

1) <br />

(4<br />

j<br />

1)<br />

1<br />

[ D(<br />

i,<br />

j<br />

1) <br />

D(<br />

i<br />

1,<br />

j<br />

1)]<br />

47


Using Interpolation Polynomial<br />

We can approximate the function f(x) by a polynomial p n (x) <strong>of</strong> order n,<br />

such that p n (x) ≈ f(x)<br />

To compute f’(x), we use the approximation f’(x) ≈ p’ n (x)<br />

Higher order polynomials are avoided because <strong>of</strong> oscillation<br />

Let p interpolates f at two points, x 0 and x 1<br />

The first derivative <strong>of</strong> p 1 (x) is<br />

p<br />

( x)<br />

f ( x0)<br />

f [ x0,<br />

x1](<br />

x <br />

0)<br />

1<br />

x<br />

f ( x1)<br />

f ( x0<br />

)<br />

p'<br />

1 ( x)<br />

f [ x0<br />

, x1]<br />

<br />

f '( x)<br />

x x<br />

1<br />

0<br />

48


1 st and 2 nd Order Approx.<br />

Let x 0 = x and x 1 = x + h, we have<br />

1<br />

f '(<br />

x)<br />

[ f ( x h)<br />

f ( x)]<br />

h<br />

This is just the O(h) order sided approximation formula<br />

Put x 0 = x – h and x 1 = x + h, we have the O(h 2 ) approximation scheme<br />

1<br />

f '(<br />

x)<br />

[ f ( x h)<br />

f ( x h)]<br />

2h<br />

A three point polynomial interpolation is<br />

f ( x<br />

) <br />

f [ x<br />

We have corrected approximation<br />

p<br />

2<br />

( x)<br />

<br />

<br />

0<br />

0<br />

f [ x<br />

, x<br />

1<br />

0<br />

, x<br />

, x<br />

2<br />

1<br />

]( x x<br />

]( x x<br />

0<br />

0<br />

)<br />

)( x x<br />

p' 2 ( x)<br />

f [ x0<br />

, x1]<br />

f [ x0<br />

, x1,<br />

x2<br />

](2x<br />

x0<br />

x1)<br />

1<br />

)<br />

49


Second Derivative<br />

If we have first derivative, we can use<br />

1<br />

f "(<br />

x)<br />

[ f '( x h)<br />

f '( x h)]<br />

2h<br />

To approximate the second derivative to O(h 2 )<br />

A direct approximation would be using Taylor expansion<br />

f ( x h)<br />

f ( x h)<br />

Hence, we have<br />

1<br />

f "( x)<br />

<br />

h<br />

This approximation is <strong>of</strong> O(h 2 ) accuracy<br />

<br />

2 f ( x)<br />

h<br />

2<br />

2<br />

1<br />

f "( x)<br />

2<br />

4!<br />

h<br />

[ f ( x h)<br />

2 f ( x)<br />

<br />

4<br />

f<br />

(4)<br />

<br />

( x)<br />

<br />

<br />

<br />

f ( x h)]<br />

50

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!