lecture05 - polynomial interpolation

27
Curve Fitting and Interpolation Lecture 5: Polynomial Interpolation MTH2212 – Computational Methods and Statistics

Upload: na2ry

Post on 10-Apr-2015

359 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Lecture05 - Polynomial Interpolation

Curve Fitting and Interpolation

Lecture 5:Polynomial Interpolation

MTH2212 – Computational Methods and Statistics

Page 2: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 22

Objectives

Introduction Newton’s Divided Difference Method

i. Linear interpolation

ii. Quadratic interpolation

iii. General Form of Newton’s Interpolation

Lagrange Interpolation

Page 3: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 33

Introduction

Techniques to fit curves to discrete values of data to obtain intermediate estimates.

- Regression (imprecise data)- Interpolation (precise data)

Curve fitting is widely used in engineering

- Trend analysis: extrapolation and interpolation- Hypothesis testing: compare a mathematical

model with measured data.

Page 4: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 44

Using similar triangles,

And rearranging, we get

01

01

0

01 )()()()(

xx

xfxf

xx

xfxf

)()()(

)()( 001

0101 xx

xx

xfxfxfxf

(1)

Linear Interpolation

Page 5: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 55

Linear Interpolation

f1(x) is a first order interpolating polynomial.

f1(x) represents the slope of the line connecting the points.

The smaller the interval between data points, the

better the approximation.

01

01 )()(

xx

xfxf

)()()(

)()( 001

0101 xx

xx

xfxfxfxf

Page 6: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 66

Example 1

Estimate the natural logarithm of 2 using linear

interpolation:

1. Interpolate between ln1 and ln6

2. Use interval ln1 to ln4

Page 7: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 77

Example1 - Solution

Linear interpolation

1. Using ln1 and ln6

εt=48.3%

2. Using ln1 and ln4

εt=33.3%

0.3583519 )12(16

0791759.10)2(1

f

0.4620981 )12(14

0386294.10)2(1

f

)()()(

)()( 001

0101 xx

xx

xfxfxfxf

Page 8: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 88

Example 1 - Solution

Page 9: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 99

Quadratic Interpolation

This is a mean of improving an estimate by introducing a curvature into the line connecting the points.

Using three data points, a second-order polynomial or quadratic polynomial or parabola is used to carry out the estimate:

f2(x) = b0 + b1(x-x0) + b2(x-x0)(x-x1) = b0 + b1x - b1x0 + b2x2 - b2x0x - b2xx1 + b2x0x1

= a0 + a1x + a2x2

Where a0 = b0 - b1x0 + b2x0x1

a1 = b1 - b2x0 - b2x1

a2 = b2

Page 10: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1010

Quadratic Interpolation

f (x) = b0 + b1(x-x0) + b2(x-x0)(x-x1)

The values of coefficients b0 , b1 and b2 are computed as follow: Evaluate f at x = x0

Evaluate f at x = x1

Evaluate f at x = x2

)( 00 xfb

01

011

)()(

xx

xfxfb

02

01

01

12

12

2

)()()()(

xx

xxxfxf

xxxfxf

b

Page 11: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1111

Quadratic Interpolation

The first two terms in equation (2) are equivalent to linear interpolation from x0 to x1.

b1 represents the slope of the line connecting points x0 and x1.

b2(x-x0)(x-x1) introduces the second-order curvature into the formula.

Page 12: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1212

Example 2

Fit a second-order polynomial to the three points used to evaluate the natural logarithm of 2 i.e.

x0 = 1 f (x0) = 0

x1 = 4 f (x1) = 1.386294

x2 = 6 f (x2) = 1.791759

Page 13: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1313

Example 2 - Solution

First, let’s compute the coefficients b0 , b1 and b2:

4620981.03

0386294.1

14

1ln4ln)()(

01

011

xx

xfxfb

0518731.0

16

4620981.046

386294.1791759.1)()()()(

02

01

01

12

12

2

xx

xxxfxf

xxxfxf

b

0ln1)( 00 xfb

Page 14: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1414

Example 2 - Solution

The quadratic polynomial is then: f2(x) = 0 + 0.4620981(x-1) – 0.0518731(x-1)(x-4)

Let’s now evaluate f2(x) at x=2

f2(x) = 0.5658444

and the relative error εt = 18.4%

Page 15: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1515

General Form of Newton’s Interpolation

The analysis used in linear and quadratic interpolation can be generalized to fit an (n-1)th order polynomial to n data points.

The data points are used to evaluate the coefficients :

))...()((...)()( 21010101 nnn xxxxxxbxxbbxf

],,...,,[

.

.

],,[

],[

)(

01211

0122

011

00

xxxxfb

xxxfb

xxfb

xfb

nnn

Page 16: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1616

General Form of Newton’s Interpolation

The bracketed function evaluations are finite divided differences

The general form of Newton’s interpolating polynomial:

01

0321210121

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

],[],[],,[

)()(],[

xx

xxxfxxxfxxxxf

xx

xxfxxfxxxf

xx

xfxfxxf

n

nnnnnn

ki

kjjikji

ji

jiji

0121210

0121001001

,,...,,))...()((...

,,))((,)()(

xxxxfxxxxxx

xxxfxxxxxxfxxxfxf

nnn

n

Page 17: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1717

General Form of Newton’s Interpolation

Page 18: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1818

Example 3

Fit a third-order Newton’s interpolating polynomial to the four points used to evaluate the natural logarithm of 2

i.e.

x0 = 1 f (x0) = 0

x1 = 4 f (x1) = 1.386294

x2 = 6 f (x2) = 1.791759

x3 = 5 f (x3) = 1.609438

Page 19: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 1919

Example 3 - Solution

The third-order polynomial is))()(())(()()( 210310201014 xxxxxxbxxxxbxxbbxf

i xi f(xi) First Second Third

0 1 0 f[x1,x0]= 0.462098 f[x2,x1,x0]= -0.0518731 f[x3,x2,x1,x0]= 0.00786541 4 1.386294 f[x2,x1]= 0.2027325 f[x3,x2,x1]= -0.02041152 6 1.791759 f[x3,x2]= 0.1823213 5 1.609438

Page 20: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 2020

Example 3 - Solution

The values of the coefficients of the polynomial are:

Therefore, the third order polynomial is

Then

0078655.0],,,[

051873.0],,[

462098.0],[

0)(

01232

0122

011

00

xxxxfb

xxxfb

xxfb

xfb

))()((0078655.0))((051873.0)(462098.00)( 2101003 xxxxxxxxxxxxxf

%3.9 6287686.0)2(3 tf

Page 21: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 2121

Lagrange Interpolating Polynomials

Lagrange interpolating polynomial is a reformulation of the Newton polynomial without the computation of divided differences.

where

Π represents “the product of”.

)()()(0

i

n

iin xfxLxf

n

ijj ji

ji xx

xxxL

0

)(

Page 22: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 2222

Lagrange Interpolating Polynomials

For n = 1 i.e. linear (1st order) version:

For n = 2 i.e. quadratic (2nd order) version:

)()()( 101

00

10

11 xf

xx

xxxf

xx

xxxf

)())((

))((

)())((

))((

)())((

))(()(

21202

10

12101

20

02010

212

xfxxxx

xxxx

xfxxxx

xxxx

xfxxxx

xxxxxf

Page 23: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 2323

Example 4

Use a Lagrange interpolating polynomial of the first and second order to evaluate ln2 given the following data:

x0 = 1 f (x0) = 0

x1 = 4 f (x1) = 1.386294

x2 = 6 f (x2) = 1.791759

Page 24: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 2424

Example 4 - Solution

Using first order Lagrange polynomial:

Using second order Lagrange polynomial:

The results are similar to those of Newton’s interpolation.

4620981.0386294.114

120

41

42)(1

xf

5658444.0791759.1)46)(16(

)42)(12(

386294.1)64)(14(

)62)(12(

0)61)(41(

)62)(42()(2

xf

Page 25: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 2525

Quiz #2 (Section 1)

Given the data

Calculate f (4) using Newton’s interpolating polynomials of order 3.

x 1 2 3 5 6

f (x) 4.75 4 5.25 19.75 36

Page 26: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 2626

Quiz #5 (Section 2)

Given the data

Calculate f (4) using 1- Newton’s interpolating polynomials of order 1 and 2.2- The Lagrange polynomial of order 1 and 2.

x 1 2 3 5 6

f (x) 4.75 4 5.25 19.75 36

Page 27: Lecture05 - Polynomial Interpolation

Dr. M. HrairiDr. M. Hrairi MTH2212 - Computational Methods and StatisticsMTH2212 - Computational Methods and Statistics 2727

Assignment #3

Computational Methods

Statistics