You are on page 1of 27

MTH2212 – Computational Methods and

Statistics

Curve Fitting and Interpolation

Lecture 5:
Polynomial Interpolation
Objectives

 Introduction
 Newton’s Divided Difference Method
i. Linear interpolation
ii. Quadratic interpolation
iii. General Form of Newton’s Interpolation
 Lagrange Interpolation

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 2


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.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 3


Linear Interpolation

Using similar triangles,

f1 ( x)  f ( x0 ) f ( x1 )  f ( x0 )

x  x0 x1  x0

And rearranging, we get (1)

f ( x1 )  f ( x0 )
f1 ( x)  f ( x0 )  ( x  x0 )
x1  x0

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 4


Linear Interpolation

f ( x1 )  f ( x0 )
f1 ( x)  f ( x0 )  ( x  x0 )
x1  x0

 f1(x) is a first order interpolating polynomial.

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


f ( x1 )  f ( x0 )
x1  x0
 The smaller the interval between data points, the better the
approximation.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 5


Example 1

Estimate the natural logarithm of 2 using linear interpolation:

1. Interpolate between ln1 and ln6

2. Use interval ln1 to ln4

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 6


Example1 - Solution

Linear interpolation
f ( x1 )  f ( x0 )
f1 ( x)  f ( x0 )  ( x  x0 )
x1  x0
1. Using ln1 and ln6

1.791759  0
f1 (2)  0  (2  1)  0.3583519  εt=48.3%
6 1

2. Using ln1 and ln4


1.386294  0
f1 (2)  0  (2  1)  0.4620981  εt=33.3%
4 1
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 7
Example 1 - Solution

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 8


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 = b 2

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 9


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  b0  f ( x0 )

f ( x1 )  f ( x0 )
 Evaluate f at x = x1  b1 
x1  x0
f ( x2 )  f ( x1 ) f ( x1 )  f ( x0 )

x2  x1 x1  x0
b2 
 Evaluate f at x = x2  x2  x0

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 10


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.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 11


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

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 12


Example 2 - Solution

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


b0  f ( x0 )  ln1  0

f ( x1 )  f ( x0 ) ln 4  ln 1 1.386294  0
b1     0.4620981
x1  x0 4 1 3

f ( x2 )  f ( x1 ) f ( x1 )  f ( x0 ) 1.791759  1.386294
  0.4620981
x2  x1 x1  x0 64
b2  
x2  x0 6 1
 0.0518731

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 13


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%

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 14


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.
f n 1 ( x)  b0  b1 ( x  x0 )  ...  bn 1 ( x  x0 )( x  x1 )...( x  xn  2 )

 The data points are used to evaluate the coefficients :


b0  f ( x0 )
b1  f [ x1 , x0 ]
b2  f [ x2 , x1 , x0 ]
.
.
bn 1  f [ xn 1 , xn  2 ,..., x1 , x0 ]

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 15


General Form of Newton’s Interpolation

 The bracketed function evaluations are finite divided differences


f ( xi )  f ( x j )
f [ xi , x j ] 
xi  x j
f [ xi , x j ]  f [ x j , xk ]
f [ xi , x j , xk ] 
xi  xk
f [ xn 1 , xn  2 ,..., x1 ]  f [ xn  2 , xn  3 ,..., x0 ]
f [ xn 1 , xn  2 ,..., x1 , x0 ] 
xn 1  x0
 The general form of Newton’s interpolating polynomial:
f n 1 ( x)  f  x0   ( x  x0 ) f  x1 , x0   ( x  x0 )( x  x1 ) f  x2 , x1 , x0 
 ...  ( x  x0 )( x  x1 )...( x  xn  2 ) f  xn 1 , xn  2 ,..., x1 , x0 

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 16


General Form of Newton’s Interpolation

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 17


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

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 18


Example 3 - Solution

 The third-order polynomial is


f 41 ( x)  b0  b1 ( x  x0 )  b2 ( x  x0 )( x  x1 )  b3 ( x  x0 )( x  x1 )( x  x 2 )

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.0078654
1 4 1.386294 f[x2,x1]= 0.2027325 f[x3,x2,x1]= -0.0204115
2 6 1.791759 f[x3,x2]= 0.182321
3 5 1.609438

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 19


Example 3 - Solution

 The values of the coefficients of the polynomial are:


b0  f ( x0 )  0
b1  f [ x1 , x0 ]  0.462098
b2  f [ x2 , x1 , x0 ]  0.051873
b2  f [ x3 , x2 , x1 , x0 ]  0.0078655
 Therefore, the third order polynomial is
f 3 ( x)  0  0.462098( x  x0 )  0.051873( x  x0 )( x  x1 )  0.0078655( x  x0 )( x  x1 )( x  x2 )

 Then
f 3 (2)  0.6287686  t  9.3%

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 20


Lagrange Interpolating Polynomials

 Lagrange interpolating polynomial is a reformulation of the


Newton polynomial without the computation of divided
differences.
n
f n ( x)   Li ( x) f ( xi )
i 0

where n x  xj
Li ( x)  
j 0 xi  x j
j i

Π represents “the product of”.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 21


Lagrange Interpolating Polynomials

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


x  x1 x  x0
f1 ( x )  f ( x0 )  f ( x1 )
x0  x1 x1  x0
 For n = 2 i.e. quadratic (2nd order) version:
( x  x1 )( x  x2 )
f 2 ( x)  f ( x0 )
( x0  x1 )( x0  x2 )
( x  x0 )( x  x2 )
 f ( x1 )
( x1  x0 )( x1  x2 )
( x  x0 )( x  x1 )
 f ( x2 )
( x2  x0 )( x2  x1 )

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


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

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 23


Example 4 - Solution

 Using first order Lagrange polynomial:


24 2 1
f1 ( x )  0 1.386294  0.4620981
1 4 4 1
 Using second order Lagrange polynomial:
(2  4)(2  6)
f 2 ( x)  0
(1  4)(1  6)
(2  1)(2  6)
 1.386294
(4  1)(4  6)
(2  1)(2  4)
 1.791759  0.5658444
(6  1)(6  4)
 The results are similar to those of Newton’s interpolation.
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 24
Quiz #2 (Section 1)

Given the data

x 1 2 3 5 6

f (x) 4.75 4 5.25 19.75 36

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


order 3.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 25


Quiz #5 (Section 2)

Given the data

x 1 2 3 5 6
f (x) 4.75 4 5.25 19.75 36

Calculate f (4) using


1- Newton’s interpolating polynomials of order 1 and 2.
2- The Lagrange polynomial of order 1 and 2.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 26


Assignment #3

 Computational Methods

 Statistics

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 27

You might also like