31
ENEM602 Spring 2007 Dr. Eng. Mohammad Tawfik Interpolation/Curve Fitting

09 numerical differentiation

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Interpolation/Curve Fitting

Page 2: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Objectives

• Understanding the difference between regression and interpolation

• Knowing how to “best fit” a polynomial into a set of data

• Knowing how to use a polynomial to interpolate data

Page 3: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Measured Data

Page 4: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Polynomial Fit!

Page 5: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Line Fit!

Page 6: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Which is better?

Page 7: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Curve Fitting

• If the data measured is of high accuracy and it is required to estimate the values of the function between the given points, then, polynomial interpolation is the best choice.

• If the measurements are expected to be of low accuracy, or the number of measured points is too large, regression would be the best choice.

Page 8: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Interpolation

Page 9: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Why Interpolation?

• When the accuracy of your measurements are ensured

• When you have discrete values for a function (numerical solutions, digital systems, etc …)

Page 10: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Acquired Data

Page 11: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

But, how to get the equation of a function that passes by all the

data you have!

Page 12: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Equation of a Line: Revision

xaay 21 If you have two points

1211 xaay

2212 xaay

2

1

2

1

2

1

1

1

y

y

a

a

x

x

Page 13: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Solving for the constants!

12

122

12

21121 &

xx

yya

xx

yxyxa

Page 14: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

What if I have more than two points?

• We may fit a polynomial of order one less that the number of points we have. i.e. four points give third order polynomial.

Page 15: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Third-Order Polynomial

34

2321 xaxaxaay

For the four points

314

2131211 xaxaxaay

324

2232212 xaxaxaay

334

2333213 xaxaxaay

344

2434214 xaxaxaay

Page 16: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

In Matrix Form

4

3

2

1

4

3

2

1

34

224

33

223

32

222

31

211

1

1

1

1

y

y

y

y

a

a

a

a

xxx

xxx

xxx

xxx

Solve the above equation for the constants of the polynomial.

Page 17: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Newton's Interpolation Polynomial

Page 18: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Newton’s Method

• In the previous procedure, we needed to solve a system of linear equations for the unknown constants.

• This method suggests that we may just proceed with the values of x & y we have to get the constants without setting a set of equations

• The method is similar to Taylor’s expansion without differentiation!

Page 19: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Equation of a Line: Revision

xaay 21 If you have two points

1211 xaay

2212 xaay

2

1

2

1

2

1

1

1

y

y

a

a

x

x

Page 20: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

For the two points

12

12

1

1

xx

yy

xx

yy

12

12

1

1

xx

yy

xx

yxf

112

121 xx

xx

yyyxf

Page 21: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

For the three points

213

121

xxxxa

xxaaxf

11 ya

12

122 xx

yya

13

12

12

23

23

3 xx

xxyy

xxyy

a

Page 22: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Using a table

xiyi

x1y1

x2y2

x3y3

13

12

12

23

23

xx

xxyy

xx

yy

12

12

xx

yy

23

23

xx

yy

Page 23: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

In General

• Newton’s Interpolation is performed for an nth order polynomial as follows

nn xxxxa

xxxxaxxaaxf

...... 11

213121

Page 24: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Example

• Find a 3rd order polynomial to interpolate the function described by the given points

xY

-11

02

15

216

Page 25: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Solution: System of equations

• A third order polynomial is given by:

34

2321 xaxaxaaxf

11 4321 aaaaf

20 1 af

51 4321 aaaaf

168422 4321 aaaaf

Page 26: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

In matrix form

16

5

2

1

8421

1111

0001

1111

4

3

2

1

a

a

a

a

1

1

1

2

4

3

2

1

a

a

a

a

322 xxxxf

Page 27: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Newton’s Method

• Newton’s methods defines the polynomial in the form:

3214

213121

xxxxxxa

xxxxaxxaaxf

11

11

4

321

xxxa

xxaxaaxf

Page 28: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Newton’s Method

xY

-11111

0234

1511

216

Page 29: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Newton’s Method

• Finally:

11

111

xxx

xxxxf

xxxxxxf 3211

322 xxxxf

Page 30: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Advantage of Newton’s Method

• The main advantage of Newton’s method is that you do not need to invert a matrix!

Page 31: 09 numerical differentiation

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Homework #6

• Chapter 18, pp. 505-506, numbers:18.1, 18.2, 18.3, 18.5.