You are on page 1of 53

4.

1 POLYNOMIAL INTERPOLATING
4.1.1 NEWTON INTERPOLATION
4.1.2 LAGRANGE INTERPOLATION
4.1.3 INVERSE INTERPOLATION

4.2 SPLINES AND PIECEWISE INTERPOLATION


4.2.1 INTRODUCTION
4.2.2 LINEAR SPLINES
4.2.3 QUADRATIC SPLINES
2
LEARNING OUTCOMES

By the end of this lecture, students should be able to:


(1) Explain the Newton’s divided-difference table
(2) Solve curve fitting problem using Newton interpolation
method.

3
4.1 POLYNOMIAL INTERPOLATING
4.1.1 NEWTON INTERPOLATION
In the mathematical field of numerical analysis, interpolation is a
method of constructing new data points within the range of a
discrete set of known data points.

4
4.1.1 NEWTON INTERPOLATION

For example, suppose we have a table like this, which gives some
values of an unknown function f.
x f(x)
0 0
1 0.8415
2 0.9093
3 0.1411
4 -0.7568
5 -0.9589
6 -0.2794

Interpolation provides a means of estimating


the function at intermediate points, such as
x = 2.5.
5
4.1.1 NEWTON INTERPOLATION

LINEAR CURVILINEAR
INTERPOLATION INTERPOLATION

6
4.1.1 NEWTON INTERPOLATION

This is not

7
4.1.1 NEWTON INTERPOLATION

• The most common method is polynomial interpolation.


• Recall that the general formula for an nth-order polynomial is

f ( x)  a0  a1 x  a2 x    an x
2 n

• For n  1 data points?


• 3 methods:
• Newton Interpolation
• Lagrange Interpolation
• Inverse Interpolation

8
4.1.1 NEWTON INTERPOLATION

EXAMPLE
Estimate ln 2using:
(i) Linear interpolation
(ii) Quadratic interpolation

9
4.1.1 NEWTON INTERPOLATION

quadratic interpolation
2
true value

1
0.6931 linear interpolation

x
0 1 2 5
ln 2
10
4.1.1 NEWTON INTERPOLATION

General form of Newton’s interpolating polynomials:


Given n  1 data points, (x0 , y0 ),(x1, y1 ), ,(xn1, yn1),(xn , yn )

f n ( x)  f ( x0 )  ( x  x0 ) f [ x1 , x0 ]  ( x  x0 )( x  x1 ) f [ x2 , x1 , x0 ]
  ( x  x0 )( x  x1 ) ( x  xn 1 ) f [ xn , xn 1 , x0 ]
where
f  x0   f ( x0 ) 

f ( x1 )  f ( x0 ) 
f [ x1 , x0 ] 
x1  x0 

f [ x2 , x1 ]  f [ x1 , x0 ] 
f [ x2 , x1 , x0 ]   construct divided difference table
x2  x0 


f [ xn , xn 1 , x0 ] 


11
4.1.1 NEWTON INTERPOLATION

Table 1 : The Newton’s divided-difference table


x f ( xi ) First divided differences
x0 f [ x0 ] f [ x1 ]  f [ x0 ]
f [ x1 , x0 ] 
x1  x0
x1 f [ x1 ]
f [ x2 ]  f [ x1 ]
f [ x2 , x1 ] 
x2  x1
x2 f [ x2 ]
f [ x3 ]  f [ x2 ]
f [ x3 , x2 ] 
x3 f [ x3 ] x3  x2
f [ x4 ]  f [ x3 ]
f [ x4 , x3 ] 
x4 f [ x4 ] x4  x3
f [ x5 ]  f [ x4 ]
f [ x5 , x3 ] 
x5 f [ x5 ] x5  x4

12
4.1.1 NEWTON INTERPOLATION

Table 1 : The Newton’s divided-difference table (cont.)


f ( xi ) First divided differences Second divided differences
f [ x0 ] f [ x1 ]  f [ x0 ]
f [ x1 , x0 ] 
x1  x0 f [ x1 , x2 ]  f [ x0 , x1 ]
f [ x1 ] f [ x2 , x1 , x0 ] 
f [ x2 ]  f [ x1 ] x2  x0
f [ x2 , x1 ] 
x2  x1 f [ x2 , x3 ]  f [ x1 , x2 ]
f [ x2 ] f [ x3 , x2 , x1 ] 
f [ x3 ]  f [ x2 ] x3  x1
f [ x3 , x2 ] 
x3  x2 f [ x3 , x4 ]  f [ x2 , x3 ]
f [ x3 ] f [ x4 , x3 , x2 ] 
f [ x4 ]  f [ x3 ] x4  x2
f [ x4 , x3 ] 
x4  x3 f [ x4 , x5 ]  f [ x3 , x4 ]
f [ x4 ] f [ x5 , x4 , x3 ] 
f [ x5 ]  f [ x4 ] x5  x3
f [ x5 , x3 ] 
f [ x5 ] x5  x4
13
4.1.1 NEWTON INTERPOLATION

Table 1 : The Newton’s divided-difference table (cont.)


Second divided differences Third divided differences

f [ x1 , x2 ]  f [ x0 , x1 ]
f [ x2 , x1 , x0 ] 
x2  x0 f [ x3 , x2 , x1, x0 ]
f [ x2 , x3 ]  f [ x1 , x2 ]
f [ x3 , x2 , x1 ] 
x3  x1 f [ x4 , x3 , x2 , x1 ]
f [ x3 , x4 ]  f [ x2 , x3 ]
f [ x4 , x3 , x2 ] 
x4  x2
f [ x5 , x4 , x3 , x2 ]
f [ x4 , x5 ]  f [ x3 , x4 ]
f [ x5 , x4 , x3 ] 
x5  x3

14
4.1.1 NEWTON INTERPOLATION

EXAMPLE 1
Given the data below;
1 4 6 5
0 1.386294 1.791759 1.609438

Estimate ln 2 using third-order Newton’s interpolating


polynomial.

15
4.1.1 NEWTON INTERPOLATION

Solution:

f ( x1 )  f ( x0 )
1  f  x1 , x0 
x1  x0
 0.462098 f  x2 , x1 , x0 
4  -0.051873
f ( x2 )  f ( x1 )
f  x3 , x2 , x1 , x0 
x2  x1
 0.0078653
6  0.202733
f  x3 , x2 , x1 
f ( x3 )  f ( x2 )
x3  x2  -0.020412
5
 0.182321

f3  2   b0  b1  2  1  b2  2  1 2  4   b3  2  1 2  4  2  6 
ln  2   0  0.462098 1   -0.0518731 2   0.0078653 1 2  4 
 0.6287686
16
4.1.1 NEWTON INTERPOLATION

EXAMPLE 2
The upward velocity of a rocket is given as a function of time in
Table 1. Find the velocity at t = 16 seconds using the Newton
divided-difference method for cubic interpolation.
Table 1
t (s) v(t ) (m/s)
10 227.04
15 362.78
20 517.35
22.5 602.97

17
4.1.1 NEWTON INTERPOLATION

Solution: b0
t0  10 227.04 b1
27.148 b2
t1  15 362.78 0.37660 b3
30.914 5.4347103
t2  20 517.35 0.44453
34.248
t3  22.5 602.97
Hence
v(t )  b0  b1 (t  t0 )  b2 (t  t0 )(t  t1 )  b3 (t  t0 )(t  t1 )(t  t2 )
v (t )  b0  b1 (t  t 0 )  b2 (t  t 0 )( t  t1 )  b3 (t  t 0 )( t  t1 )(t  t 2 )
 227.04  27.148( t  10)  0.37660(t  10)(t  15)
 5.4347 * 10 3 (t  10)( t  15)( t  20)
At t  16,
v (16)  227.04  27.148(16  10)  0.37660(16  10)(16  15)
 5.4347 * 10 3 (16  10)(16  15)(16  20)
 392.06 m/s 18
4.1.1 NEWTON INTERPOLATION

Test your understanding….


EXERCISE 1 (use 8 decimal places)

Use Newton’s interpolatory divided-difference formula to


construct interpolating polynomials of degree 3 for the
following data. Hence, approximate the specified value.
f (0.6)  0.17694460 , f (0.7)  0.01375227 ,
f (0.8)  0.22363362 , f (1.0)  0.65809197
f (0.9)  ?

19
4.1.1 NEWTON INTERPOLATION

Test your understanding….


EXERCISE 2 (use 5 decimal places)

Use Newton’s interpolatory divided-difference formula to


construct interpolating polynomials of degree 3 for the
following data. Hence, approximate the specified value.

f (8.1)  16.94410 , f (8.3)  17.56492 ,


f (8.6)  18.50515 , f (8.7)  18.82091
f (8.4)  ?

answer :17.87714

20
LEARNING OUTCOMES

By the end of this lecture, students should be able to:


(1) Use Lagrange’s formula to solve curve fitting problem.
(2) Differentiate between interpolation and inverse interpolation.
(3) Solve curve fitting problem using inverse interpolation.

21
4.1 POLYNOMIAL INTERPOLATING
4.1.2 LAGRANGE INTERPOLATION
• The Lagrange interpolating polynomial is simply a
reformulation of the Newton’s polynomial that avoids the
computation of divided differences:
n
f n ( x)   Li ( x) f ( xi )
i 0 the “product of”
where;
n x  xj
Li ( x)  
j 0 xi  x j
j i
22
4.1.2 LAGRANGE INTERPOLATION

First-order Lagrange interpolating polynomial:

n 1 i  0,1 j  0,1

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

23
4.1.2 LAGRANGE INTERPOLATION

Second-order Lagrange interpolating polynomial:

n2 i  0,1, 2 j  0,1, 2

f 2 ( x) 
 x  x1  x  x2 
f ( x0 ) 
 x  x0  x  x2 
f ( x1 )
 x0  x1  x1  x 2   x1  x0  x1  x 2 

 x  x0  x  x1 
f ( x2 )
 x2  x0  x2  x 1 

24
4.1.2 LAGRANGE INTERPOLATION

EXAMPLE 1

Given the data below.

Estimate f(2) by using Lagrange interpolation polynomial.

25
4.1.2 LAGRANGE INTERPOLATION

Solution:
f (2)  f3 (2)  L0 f  x0   L1 f  x1   L2 f  x2   L3 f ( x3 )
 2  x1  2  x2  2  x3  f x   2  x0  2  x2  2  x3  f x
  0  1
 0 1  0 2  0 3 
x  x x  x x  x  1 0  1 2  1 3 
x  x x  x x  x


 2  x0  2  x1  2  x3 
f  x2  
 2  x0  2  x1  2  x2 
f  x3 
 x2  x0  x2  x1  x2  x3   x3  x0  x3  x1  x3  x1 
where

L1 
 2  4  2  5 2  6   0.4 L   2  1 2  5 2  6   2
1  4 1  51  6  2
 4  1 4  5 4  6 
L3 
 2  1 2  4  2  6 
 0.6 L4 
 2  1 2  4  2  5 
 2
 5  1 5  4  5  6   6  1 6  4  6  5 
 f  2   0.4  0   2 1.386294   0.6 1.791759   2 1.609438   0.628767

26
4.1.2 LAGRANGE INTERPOLATION

EXAMPLE 2
The upward velocity of a rocket is given as a function of time in
Table 1. Find the velocity at t =16 seconds using the Lagrange
method for quadratic interpolation.
Table 1
t (s) v(t ) (m/s)
10 227.04
15 362.78
20 517.35

27
4.1.2 LAGRANGE INTERPOLATION

Solution:
v2  t   L0 v(t0 )  L1v(t1 )  L2v (t2 )
 t  t1   t  t2   t  t0   t  t 2 
v2  t     
 0 
v t     v  t1 
t 
 0 1  0 2 
t t  t  1 0   t1  t2
t  t 
 t  t0   t  t1 
   v  t2 
t 
 2 0  2 1 
t t  t
where
 16  15   16  20 
L0 v(t0 )      227.04   18.1632
 10  15   10  20 
 16  10   16  20 
L1v(t1 )      362.78   348.2688
 15  10  15  20 
 16  10   16  15 
L2 v(t2 )      517.35   62.0820
 20  10   20  15 
 v 16   v2 (16)  18.1632  348.2688  62.0820  392.1876 m/s

28
4.1.2 LAGRANGE INTERPOLATION

Test your understanding….


EXERCISE
Use the portion of the given steam table for superheated H2O at 200
Mpa to find the corresponding entropy s for a specified volume v
of 0.108m3/kg using Lagrange Interpolating Polynomial of order 2.

vm3 / kg  skJ / kg.K 

0.10377 6.4147
0.11144 6.5453
0.1254 6.7664

29
4.1 POLYNOMIAL INTERPOLATING
4.1.3 INVERSE INTERPOLATION

 Interpolation general means finding some value f(x) for some x


that is between the given independent data points.

 Sometimes, it will be useful to find the value of x for which f(x)


is a certain value - this is inverse interpolation.

30
4.1.3 INVERSE INTERPOLATION
Lagrange interpolation:
n
Pn ( f )   Li ( f ) xi where Li ( f )  
n
f  f 
j

i 0 j 0
j i
f  f 
i j

ex:
P3 ( f )  L0 ( f ) x0  L1 ( f ) x1  L2 ( f ) x2  L3 ( f ) x3


 f  f1  f  f 2  f  f 3 
x0 
 f  f 0  f  f 2  f  f 3 
x1
 0 1  0 2  0 3 
f  f f  f f  f  1 0  1 2  1 3 
f  f f  f f  f


 f  f 0  f  f1  f  f3  x   f  f 0  f  f1  f  f 2  x
 f 2  f 0  f 2  f1  f 2  f3  2  f3  f 0   f3  f1  f3  f 2  3

Newton interpolation:

P3 ( f )  b0  b1  f  f 0   b2  f  f 0  f  f1   b3  f  f 0  f  f1  f  f 2 

31
4.1.3 INVERSE INTERPOLATION

i) Lagrange Interpolation
ii) Newton Interpolation

32
4.1.3 INVERSE INTERPOLATION

Solution:

i) Lagrange Interpolation
P3 ( f )  L0 ( f ) x0  L1 ( f ) x1  L2 ( f ) x2  L3 ( f ) x3


 f  f1  f  f 2  f  f 3 
x0 
 f  f 0  f  f 2  f  f 3 
x1
 f0  f1  f0  f 2  f 0  f3   f1  f 0  f1  f 2  f1  f3 

 f  f 0  f  f1  f  f 3 
x2 
 f  f 0  f  f1  f  f 2 
x3
 f 2  f0  f 2  f1  f 2  f3   f3  f0  f3  f1  f3  f 2 
P3 (0.3)  0.4900  3.7465  1.1831  0.2797  3.3331

33
4.1.3 INVERSE INTERPOLATION

ii) Newton Interpolation


P3 ( f )  b0  b1  f  f 0   b2  f  f 0  f  f1   b3  f  f 0  f  f1  f  f 2 
 3.2  10.8696  f  0.3125   40.3545  f  0.3125  f  0.2941
 119.3043  f  0.3125  f  0.2941 f  0.2778 
P3 (0.3)  3.2  0.1359  0.0030  0.0002  3.3331

34
LEARNING OUTCOMES

By the end of this lecture, students should be able to:


(1) Identify linear and quadratic splines.
(2) Solve curve fitting problem using splines.

35
4.2 SPLINES & PIECEWISE INTERPOLATION
4.2.1 INTRODUCTION

• An alternative approach to use a single (n-1)th order polynomial


to interpolate between n points is to apply lower-order
polynomials in a piecewise function to subsets of data points.

• These connecting polynomials are called spline functions.

• Splines minimize oscillations and reduce round-off error


due to their lower-order nature.

36
4.2.1 INTRODUCTION TO SPLINES

Splines eliminate oscillations by using small


subsets of points for each interval rather
than every point. This is especially useful
when there are jumps in the data:
a) 3rd order polynomial
b) 5th order polynomial
c) 7th order polynomial
d) Linear spline
• seven 1st order polynomials
generated by using pairs of points
at a time

37
4.2.1 INTRODUCTION TO SPLINES

Spline development:
• Spline function (si(x))coefficients are calculated for each
interval of a data set.
• The number of data points (fi) used for each spline function
depends on the order of the spline function.

38
4.2.1 INTRODUCTION TO SPLINES

a) First-order splines find


straight-line equations between
each pair of points that
• Go through the points

b) Second-order splines find


quadratic equations between
each pair of points that
• Go through the points
• Match first derivatives at
the interior points

39
4.2 SPLINES & PIECEWISE INTERPOLATION
4.2.2 LINEAR SPLINES
 The simplest connection between two points is a straight line.
 The linear or 1st order splines for a group of data points can be
defined as a set of linear functions.
f 2  f1
s1 ( x)  f ( x1 )  ( x  x1 ) x1  x  x2
x2  x1
f3  f 2
s2 ( x)  f ( x2 )  ( x  x2 ) x2  x  x3
x3  x2

fi 1  fi
si ( x)  f ( xi )  ( x  xi ) xi  x  xi 1
xi 1  xi
 For n given points, there are n-1 intervals.
40
4.2.2 LINEAR SPLINES

EXAMPLE 1

(a) Fit the data with first-order splines.


(b) Evaluate the function at x=5
x 3.0 4.5 7.0 9.0
f(x) 2.5 1.0 2.5 0.5

41
4.2.2 LINEAR SPLINES

Solution:

Since we have 4 data, so we can determine 3 splines function, where

f 2  f1 1.0  2.5
s1 ( x)  f1  ( x  x1 )  2.5  ( x  3.0) 3.0  x  4.5
x2  x1 4.5  3.0
f3  f 2 2.5  1.0
s2 ( x)  f 2  ( x  x2 )  1.0  ( x  4.5) 4.5  x  7.0
x3  x2 7.0  4.5
f 4  f3 0.5  2.5
s3  x   f3  ( x  x3 )  2.5  ( x  7.0) 7.0  x  9.0
x4  x3 9.0  7.0

42
4.2.2 LINEAR SPLINES

x=5 lies in the second interval, so we will use s2 to make the


prediction,

2.5  1.0
s2 (5)  1.0  (5  4.5)  1.3
7.0  4.5

43
4.2.2 LINEAR SPLINES

EXAMPLE 2

x 1.1 2.5 3.6 5.0 6.2


f(x) 3 7 10 16 6

Develop linear spline interpolation and predict f (3.0).

44
4.2 SPLINES & PIECEWISE INTERPOLATION
4.2.3 QUADRATIC SPLINES
si ( x)  ai  bi ( x  xi )  ci ( x  xi ) 2 xi  x  xi 1
For i  1, 2,..., n  1, find
hi  xi 1  xi ; fi  bi hi  ci hi 2  fi 1
bi  2ci hi  bi 1 ;
Also given,
c1  0
ai  fi

45
4.2.3 QUADRATIC SPLINES

EXAMPLE 1

(a) Fit the data with second-order splines.


(b) Evaluate the function at x=2.2 and x=3.8

x 1 2 2.5 3 4
f(x) 1 5 7 8 2

46
4.2.3 QUADRATIC SPLINES

x 1 2 2.5 3 4
f(x) 1 5 7 8 2

si ( x)  ai  bi ( x  xi )  ci ( x  xi ) 2
hi  xi 1  xi ; fi  bi hi  ci hi 2  fi 1
bi  2ci hi  bi 1 ; c1  0
thus
h1  1 a1  1
h2  0.5 a2  5
h3  0.5 a3  7
h4  1 a4  8

47
4.2.3 QUADRATIC SPLINES

1, 2 
when i  1
c1  0
f1  b1h1  c1h12  f 2
1  b1  0  5  b1  4
b1  2c1h1  b2  b1  b2  4

48
4.2.3 QUADRATIC SPLINES

 2, 2.5
when i  2
f 2  b2 h2  c2 h2  f 3
2

5  4  0.5   c2  0.5   7  c2  0
2

b2  2c2 h2  b3
4  0  b3  b3  4

49
4.2.3 QUADRATIC SPLINES

 2.5,3
when i  3
f3  b3h3  c3h32  f 4
7  4  0.5  c3  0.5   8  c3  4
2

b3  2c3h3  b4
4  2  4  0.5   b4  b4  0

50
4.2.3 QUADRATIC SPLINES

 3, 4 
when i  4
f 4  b4 h4  c4 h4  f5
2

8  0 1  c4 1  2  c4  6
2

51
4.2.3 QUADRATIC SPLINES

therefore
S1  1  4  x  1 , 1 x  2
S2  5  4  x  2  , 2  x  2.5
S3  7  4  x  2.5   4  x  2.5  , 2.5  x  3
2

S 4  8  6  x  3 , 3x  4
2

to estimate the value at x  2.2, we use S2 since x  2.2 lie in the interval (2, 2.5)
S2  5  4  2.2  2   5.8

and at x  3.8, we use S4 since x  3.8 lie in the interval (3, 4)


S4  8  6  3.8  3  4.16
2

52
4.2.3 QUADRATIC SPLINES

EXAMPLE 2

x 1.1 2.5 3.6 5.0 6.2


f(x) 3 7 10 16 6

Develop quadratic spline interpolation and predict f (4.3).

53

You might also like