interpolation methods

47
Interpolation Mohammad Tawfik #WikiCourses http://WikiCourses.WikiSpaces.com Interpolation/Curve Fitting Mohammad Tawfik

Upload: mohammad-tawfik

Post on 15-Jul-2015

196 views

Category:

Education


3 download

TRANSCRIPT

Page 1: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Interpolation/Curve Fitting

Mohammad Tawfik

Page 2: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

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: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Measured Data

Page 4: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Polynomial Fit!

Page 5: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Line Fit!

Page 6: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Which is better?

Page 7: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

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 (Real life data), or the number of measured points is too large, regression would be the best choice.

Page 8: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Interpolation

Page 9: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

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: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Acquired Data

Page 11: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

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

data you have!

Page 12: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Equation of a Line: Revision

xaay 10 +=

If you have two points

1101 xaay +=

2102 xaay +=

=

2

1

1

0

2

1

11

yy

aa

xx

Page 13: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Solving for the constants!

12

121

12

21120 &

xxyya

xxyxyxa

−−

=−−

=

Page 14: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

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: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Third-Order Polynomial 3

32

210 xaxaxaay +++=For the four points

313

2121101 xaxaxaay +++=

323

2222102 xaxaxaay +++=

333

2323103 xaxaxaay +++=

343

2424104 xaxaxaay +++=

Page 16: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

In Matrix Form

=

4

3

2

1

3

2

1

0

34

224

33

223

32

222

31

211

1111

yyyy

aaaa

xxxxxxxxxxxx

Solve the above equation for the constants of the polynomial.

Page 17: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Example • Find a 3rd order

polynomial to interpolate the function described by the given points

Y x

1 -1

2 0

5 1

16 2

Page 18: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

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 19: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

In matrix form

=

−−

16521

8421111100011111

4

3

2

1

aaaa

=

1112

4

3

2

1

aaaa

( ) 322 xxxxf +++=

Page 20: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Newton's Interpolation Polynomial

Page 21: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

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 22: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

For the two points ( )110 xxbby −+=

( ) 0111101 byxxbby =⇒−+=

( )112

121 xx

xxyyyy −

−−

+=

( )⇒−+= 12102 xxbby

( ) ( )( )12

12112112 xx

yybxxbyy−−

=⇒−+=

Page 23: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Homework

• Show that the polynomial obtained by solving a set of equations is equivalent to that obtained by Newton method

Page 24: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

For the three points ( ) ( )

( )( )213

121

xxxxbxxbbxf

−−+−+=

10 yb =

12

121 xx

yyb−−

=

13

12

12

23

23

2 xxxxyy

xxyy

b−

−−

−−−

=

Page 25: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Using a table yi xi

y1 x1

y2 x2

y3 x3

13

12

12

23

23

xxxxyy

xxyy

−−−

−−−

12

12

xxyy

−−

23

23

xxyy

−−

Page 26: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

In General

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

( ) ( ) ( )( )( ) ( )nn xxxxb

xxxxbxxbbxf−−++

−−+−+=...... 1

212110

Page 27: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Example • Find a 3rd order

polynomial to interpolate the function described by the given points using Newton’s method

Y x

1 -1

2 0

5 1

16 2

Page 28: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Newton’s Method • Newton’s methods defines the polynomial in the

form:

( ) ( ) ( )( )( )( )( )3213

212110

xxxxxxbxxxxbxxbbxf−−−+

−−+−+=

( ) ( ) ( )( )( )( )( )11

11

3

210

−++++++=

xxxbxxbxbbxf

Page 29: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Newton’s Method Y x

1 1 1 1 -1

4 3 2 0

11 5 1

16 2

Page 30: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Newton’s Method • Finally:

( ) ( ) ( )( )( )( )( )11

111−++

++++=xxx

xxxxf

( ) ( ) ( ) ( )xxxxxxf −+++++= 3211

( ) 322 xxxxf +++=

Page 31: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Advantage of Newton’s Method

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

Page 32: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Interpolation

Lagrange Interpolation Polynomial

Page 33: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Lagrange Method

• First, we learned that a polynomial can pass by the points by using a simple polynomial with (n-1) terms.

• Then, we learned a way that “looks like” the Taylor expansion (Newton’s method)

Page 34: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Lagrange Method (cont’d)

• Now, we will use polynomials that are zero at all points except the one we are evaluating at, but, in an easier form!

Page 35: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

For the two points ( ) ( )2211 xxcxxcy −+−=

212

11

21

2 yxxxxy

xxxxy

−−

+

−−

=

( ) ( )2121111 xxcxxcy −+−=

( )21

12 xx

yc−

=

( ) ( )2221212 xxcxxcy −+−=

( )12

21 xx

yc−

=

Page 36: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Two lines added!

212

11

21

2 yxxxxy

xxxxy

−−

+

−−

=

Page 37: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Homework

• Show that the polynomial obtained by solving a set of equations is equivalent to that obtained by Lagrange method

Page 38: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

For the three points ( )( )

( )( )( )( )133

322

211

xxxxcxxxxc

xxxxcy

−−+−−+

−−=

( )( )( )( )( )( )11313

31212

211111

xxxxcxxxxc

xxxxcy

−−+−−+

−−=

( )( )312121 xxxxcy −−= ( )( )3121

12 xxxx

yc−−

=

Page 39: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Similarly

( )( )1323

31 xxxx

yc−−

=

( )( )3212

23 xxxx

yc−−

=

Page 40: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Finally

323

2

13

1

232

3

12

1

131

3

21

2

yxxxx

xxxx

yxxxx

xxxx

yxxxx

xxxxy

−−

−−

+

−−

−−

+

−−

−−

=

Page 41: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Three parabolas added!!!

323

2

13

1

232

3

12

1

131

3

21

2

yxxxx

xxxx

yxxxx

xxxx

yxxxx

xxxxy

−−

−−

+

−−

−−

+

−−

−−

=

Page 42: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Example • Find a 3rd order

polynomial to interpolate the function described by the given points using Lagrange’s method

Y x

1 -1

2 0

5 1

16 2

Page 43: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Solution

434

3

24

2

14

1

343

4

23

2

13

1

242

4

32

3

12

1

141

4

31

3

21

2

yxxxx

xxxx

xxxx

yxxxx

xxxx

xxxx

yxxxx

xxxx

xxxx

yxxxx

xxxx

xxxxy

−−

−−

−−

+

−−

−−

−−

+

−−

−−

−−

+

−−

−−

−−

=

Page 44: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Solution

4

3

2

1

121

020

121

212

010

111

202

101

101

212

111

010

yxxx

yxxx

yxxx

yxxxy

−−

−−

++

+

−−

−−

++

+

−−

−−

++

+

−−−

−−−

−−−

=

Page 45: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Solution ( )( )( )

( )( )( )

( )( )( )

( )( )( )4

3

2

1

611

221

2211

621

yxxx

yxxx

yxxx

yxxxy

−++

−−+

+

−−++

−−−

=

Page 46: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

Solution ( )( )( )

( )( )( )

( )( )( )

( )( )( )166

11

52

21

22

211

16

21

−++

−−+

+

−−++

−−−

=

xxx

xxx

xxx

xxxy

Page 47: Interpolation Methods

Interpolation Mohammad Tawfik

#WikiCourses http://WikiCourses.WikiSpaces.com

• I will leave it for you to simplify the relation and obtain the same previous polynomial!