Docsity

Interpolation: Approximating Functions using Polynomials - Prof. Luke Olson, Study notes of Computer Science

Partial preview of the text

Download Interpolation: Approximating Functions using Polynomials - Prof. Luke Olson and more Study notes Computer Science in PDF only on Docsity!

Lecture 13

Interpolation

L. Olson

Department of Computer Science

University of Illinois at Urbana-Champaign

October 11, 2006

Next Topics

(^1) Interpolation: Approximating a function f (x) by a polynomial p n(x).

(^2) Differentiation: Approximating the derivative of a function f (x).

(^3) Integration: Approximating an integral

b a f (x) dx

Interpolation: Introduction

How do we approximate f (x) by g(x)? In what sense?

(^1) Interpolation: g(x) must have the same values of f (x) at set of given

points.

(^2) Least-squares: g(x) must deviate as little as possible from f (x) in the

sense of a 2-norm: minimize

b a |f (t) โˆ’ g(t)|

2 dt

(^3) Chebyshev: g(x) must deviate as little as possible from f (x) in the sense

of the โˆž-norm: minimize maxtโˆˆ[a,b] |f (t) โˆ’ g(t)|.

Interpolation: Introduction

Given n + 1 distinct points x 0 ,... , xn, and values y 0 ,... , yn, fina polynomial

p(x) of degree n so that

p(xi) = yi i = 0 ,... , n

A polynomial of degree n has n + 1 degree-of-freedom:

p(x) = a 0 + a 1 + ยท ยท ยท + anx

n

n + 1 constraints determine the polynomial uniquely:

p(xi) = yi, i = 0 ,... , n

Monomial: The problem

1 x 1 x

2 1

... x

n 1 1 x 2 x

2 2

... x

n 2 . . .

1 xn x

2 n...^ x

n n

a 0

a 1

. . .

cn

y 1

y 2

. . .

yn

Questions

Is this a โ€œgoodโ€ system to solve?

Example

from Recktenwald

Consider Gas prices (in cents) for the following years:

x year 1986 1988 1990 1992 1994 1996

y price 133.5 132.2 138.7 141.5 137.6 144.

1 year =[1986 1988 1990 1992 1994 1996 ]โ€™;

2 price =[133.5 132.2 138.7 141.5 137.6 144.2] โ€™;

3

4 M = vander (year);

5 a = M\price;

6

7 x= linspace (1986 ,1996 ,200);

8 p= polyval (a,x);

9 plot(year ,price ,โ€™oโ€™,x,p,โ€™-โ€™);

Lagrange

What have we done? Weโ€™ve written p(x) as

p(x) =

x โˆ’ x 1

x 0 โˆ’ x 1

y 0 +

x โˆ’ x 0

x 1 โˆ’ x 0

y 1

the sum of two linear polynomials

the first is zero at x 1 and 1 at x 0

the second is zero at x 0 and 1 at x 1

these are the two linear Lagrange basis functions:

` 0 (x) =

x โˆ’ x 1

x 0 โˆ’ x 1

` 1 (x) =

x โˆ’ x 0

x 1 โˆ’ x 0

Lagrange

Example

Write the Lagrange basis functions for

x 1 3

1 4

y 2 -1 7

Directly

` 0 (x) =

(x โˆ’

1 4 )(x โˆ’ 1 )

1 3

1 4

1 3

` 1 (x) =

(x โˆ’

1 3

)(x โˆ’ 1 )

1 4

1 3

1 4

` 2 (x) =

(x โˆ’

1 3 )(x โˆ’

1 4

1 3

1 4

Example

Find the equation of the parabola passing through the points (1,6), (-1,0), and

(2,12)

x 0 = 1 , x 1 = โˆ’ 1 , x 2 = 2 ; y 0 = 6 , y 1 = 0 , y 2 = 12 ;

` 0 (x) =

(xโˆ’x 1 )(xโˆ’x 2 ) (x 0 โˆ’x 1 )(x 0 โˆ’x 2 )

(x+ 1 )(xโˆ’ 2 ) ( 2 )(โˆ’ 1 )

` 1 (x) =

(xโˆ’x 0 )(xโˆ’x 2 ) (x 1 โˆ’x 0 )(x 1 โˆ’x 2 )

(xโˆ’ 1 )(xโˆ’ 2 ) (โˆ’ 2 )(โˆ’ 3 )

` 2 (x) =

(xโˆ’x 0 )(xโˆ’x 1 ) (x 2 โˆ’x 0 )(x 2 โˆ’x 1 )

(xโˆ’ 1 )(x+ 1 ) ( 1 )( 3 )

p 2 (x) = y 0 0 (x) + y 1 1 (x) + y 2 ` 2 (x)

= โˆ’ 3 ร— (x + 1 )(x โˆ’ 2 ) + 0 ร—

(x โˆ’ 1 )(x โˆ’ 2 )

  • 4 ร— (x โˆ’ 1 )(x + 1 )

= (x + 1 )[ 4 (x โˆ’ 1 ) โˆ’ 3 (x โˆ’ 2 )]

= (x + 1 )(x + 2 )

Summary so far:

Monomials: p(x) = a 0 + a 1 x + ยท ยท ยท + anx n results in poor conditioning

Monomials: but evaluating the Monomial interpolant is cheap (nested

iteration)

Lagrange: p(x) = 0 (x)y 0 + ยท ยท ยท +n(x)yn is very well behaved.

Lagrange: but evaluating the Lagrange interpolant is expensive (each

basis function is of the same order and the interpolant is not easily

reduced to nested form)

Fixing Monomials, Fixing Lagrange

Back to the gas price example. Suppose we use a better basis like

(x โˆ’ ยฏx)

k

instead of

x

k

For example, ยฏx = average(xi), i = 0 ,... , n.

Newton Polynomials

Newton Polynomials are of the form

pn(x) = a 0 + a 1 (x โˆ’ x 0 ) + a 2 (x โˆ’ x 0 )(x โˆ’ x 1 ) + a 3 (x โˆ’ x 0 )(x โˆ’ x 1 )(x โˆ’ x 2 ) +...

The basis used is thus

function order

1 0

x โˆ’ x 0 1

(x โˆ’ x 0 )(x โˆ’ x 1 ) 2

(x โˆ’ x 0 )(x โˆ’ x 1 )(x โˆ’ x 2 ) 3

More stable that monomials

More computationally efficient (nested iteration) than using Lagrange and

shifted monomials

Newton Polynomials using Divided Differences

Or in matrix form:

๏ฃฎ

1 x 1 โˆ’ x 0 0

1 x 2 โˆ’ x 0 (x 2 โˆ’ x 0 )(x 2 โˆ’ x 1 )

a 0

a 1

a 2

y 0

y 1

y 2

โ‡’ lower triangular

โ‡’ only O(n

2 ) operations

Newton Polynomials using Divided Differences

Using Forward Substitution to solve this lower triangular system yeilds:

a 0 = y 0 = f (x 0 )

a 1 =

y 1 โˆ’ a 0

x 1 โˆ’ x 0

f (x 1 ) โˆ’ f (x 0 )

x 1 โˆ’ x 0

a 2 =

y 2 โˆ’ a 0 โˆ’ (x 2 โˆ’ x 0 )a 1

(x 2 โˆ’ x 1 )(x 2 โˆ’ x 0 )

f (x 2 ) โˆ’ f (x 0 ) โˆ’ (x 2 โˆ’ x 0 )

f (x 1 )โˆ’f (x 0 ) x 1 โˆ’x 0

(x 2 โˆ’ x 1 )(x 2 โˆ’ x 0 )

f (x 1 )โˆ’f (x 0 ) x 1 โˆ’x 0

f (x 2 )โˆ’f (x 1 ) x 2 โˆ’x 1

x 2 โˆ’ x 0