You are on page 1of 12

============================================================

===========================Chapter 5=========================
====================Curve Fitting and Interpolation==============
=====================================================================

Experimental data is given only in the form of discrete points such as x0 , y0 , x1 , y1  , ......,
xn 1, yn 1  , xn , yn  which means that there are only fixed data we are able to know.
Consequently, if someone wants to know the value of y at any x, it could not be possible
unless a continuous function f x  is used to represent the data values. This is called
interpolation, if x falls inside the range of x for which the data is given. But, if x falls
outside the range of x for which the data is given, it is no longer interpolation, instead, it is
extrapolation.

A polynomial is a common choice for an interpolating function because polynomials are


easy to evaluate, differentiate, and integrate relative to other choices such as a
trigonometric and exponential series. Polynomial interpolation involves finding a
polynomial of order n that passes through the n  1 points. See fig.1.

Some of the methods of interpolation are direct method, Newton’s divided difference
polynomial method, Lagrangian interpolation method, and spline interpolation.

y
x3 , y 3 

x1 , y1 

x2 , y 2 ) f x 

 x0 , y 0 
x

Figure 1 Interpolation of discrete data.

Direct Method
The direct method of interpolation is based on the following premise. Given n  1 data
points, we can fit a polynomial of order n as given as

y  a0  a1 x  ...............  an x n (1)

1
through the data, where a0 , a1 ,..., an are real constants found by solving the n  1
simultaneous linear equations determined by the n+1 data points. To find the value of y at
a given value of x , simply substitute the value of x in Equation1. However, it may not be
necessary to use all the data points, and the selection of appropriate data points to be used
relays on the order of the polynomial required and actual value of x used to find y.

Example 1
A manufacturer of thermistors makes several observations with a thermistor, which are
given in Table 1.

R ohm  T C

1101.0 25.113
911.3 30.131
636.0 40.120
451.1 50.128

Table 1 Temperature as a function of resistance.

Determine the temperature corresponding to 754.8 ohms using the direct method of
interpolation and
(a) First order polynomial approximation.
(b) Second order polynomial.
(c) Third order polynomial

Solution
(a) For first order polynomial interpolation (also called linear interpolation), we choose the
temperature given by

T R   a0  a1 R

x1 , y1 

f1 x 

 x0 , y 0 
x
Figure 3 linear interpolation.
2
Since we want to find the temperature at R  754.8 , and we are using a first order
polynomial, we need to choose the two data points that are closest to R  754.8 that also
bracket R  754.8 to evaluate it. The two points are R0  911.3 and R1  636.0 .
Then
T R0   T 911.3  a0  a1 911.3  30.131
T R1   T 636.0  a0  a1 636.0  40.120

Writing the equations in matrix form, we have

1 911.3 a0   30.131


1 636.0  a   40.120
  1   

Solving the above two equations gives

a0  63.197 , a1  0.036284

Hence
T R   a0  a1 R
 63.197  0.036284R, 636.0  R  911.3

At R  754.8 ,
T 754.8  63.197  0.036284754.8
 35.809 C

(b) For second order polynomial interpolation (also called quadratic interpolation), we
choose the temperature given by

T R   a0  a1 R  a2 R 2
y

x1 , y1 
x2 , y2 

f 2 x 

x0 , y 0 
x
Figure 4 Quadratic interpolation.

3
Since we want to find the temperature at R  754.8 and we are using a second order
polynomial, we need to choose the three data points that are closest to R  754.8 that also
bracket R  754.8 to evaluate it. The three points are R0  911.3 , R1  636.0 and R2  451.1 .
Then
T 911.3  a0  a1 911.3  a2 911.3  30.131
2

T 636.0  a0  a1 636.0  a2 636.0  40.120


2

T 451.1  a0  a1 451.1  a2 451.1  50.128


2

Writing the three equations in matrix form, we have

1 911.3 8.3047  10 5  a0   30.131


 5    
1 636.0 4.0450  10   a1   40.120
1 451.1 2.0349  10 5  a 2  50.128
 

Solving the above three equations gives

a0  85.668
a1  0.096275
a 2  3.8771  10 5

Hence
T R  85.668  0.096275R  3.8771 10 5 R 2 , 451.1  R  911.3

At R  754.8 ,
T 754.8  85.668  0.096275754.8  3.8771 10 5 754.8
2

 35.089 C
The absolute relative approximate error a obtained between the results from the first
and second order polynomial is

35.089  35.809
a   100%
35.089
 2.0543%

(c) For third order polynomial interpolation (also called cubic interpolation), we choose
the temperature given by

T R   a0  a1 R  a2 R 2  a3 R 3

4
y
x 3 , y 3 
x1 , y1  f 3 x 

x0 , y 0  x2 , y 2 
x
Figure 5 Cubic interpolation.

Since we want to find the temperature at R  754.8 , and we are using a third order
polynomial, we need to choose the four data points closest to R  754.8 that also bracket
R  754.8 to evaluate it. The four points are R0  1101.0 , R1  91.3 , R2  636.0 and
R3  451.1 .
Then
T 1101.0  a0  a1 1101.0  a2 1101.0  a3 1101.0  25.113
2 3

T 911.3  a0  a1 911.3  a2 911.3  a3 911.3  30.131


2 3

T 636.0  a0  a1 636.0  a2 636.0  a3 636.0  40.120


2 3

T 451.1  a0  a1 451.1  a2 451.1  a3 451.1  50.128


2 3

Writing the four equations in matrix form, we have

1 1101.0 1.2122  10 6 1.3346  10 9  a 0   25.113


    
1 911.3 8.3047  10 5 7.5681  10 8   a1   30.131

1 636.0 4.0450  10 5 2.5726  10 8  a 2  40.120
    
1 451.1 2.0349  10 5 9.1795  10 7   a 3  50.128

Solving the above four equations gives

a0  92.759
a1  0.13093
a2  9.2975  10 5
a3  2.7124  10 8
Hence

T R   92.759  0.13093R  9.2975  10 5 R 2  2.7124  10 8 R 3 , 451.1  R  1101.0

T 754.8  35.242 C

5
The absolute relative approximate error a for the results from the second and third
order polynomial is
35.242  35.089
a   100  0.43458%
35.242

Newton’s Divided Difference Polynomial


The general form of the Newton’s divided difference polynomial for n  1 data points,
x0 , y0 , x1 , y1 ,......, xn1 , yn1 , xn , yn , is written as

f n ( x)  b0  b1 ( x  x0 )  ....  bn ( x  x0 )( x  x1 )...( x  xn1 )

where
b0  f [ x0 ]
b1  f [ x1 , x0 ]
b2  f [ x2 , x1 , x0 ]

bn  f [ xn , xn1 ,...., x0 ]

and the n th divided difference is defined as

f [ xn ,........, x1 ]  f [ xn1 ,........, x0 ]


bn 
x n  x0

From the above definition, it can be seen that the divided differences are calculated
recursively. A clear understanding of Newton’s divided difference could be made using
examples.

Example 2

a) Using the data given under example 1, determine the temperature corresponding to
754.8 ohms using Newton’s divided difference method of interpolation and a third
order polynomial.
b) Find the absolute relative true error, if the actual measured value of the resistor is
35.285 C

Solution

a) For cubic interpolation, the temperature is given by

T ( R)  b0  b1 ( R  R0 )  b2 ( R  R0 )( R  R1 )  b3 ( R  R0 )( R  R1 )( R  R2 )

6
Since we want to find the temperature at R  754.8, we need to choose the four data points
that are closest to R  754.8 that also bracket R  754.8 to evaluate it. The four data points
are R0  1101.0, R1  911.3, R2  636.0 and R3  451.1 .

Then

b0  T [ R0 ]  T ( R0 )  25.113

T ( R1 )  T ( R0 ) 30.131  25.113
b1  T [ R1 , R0 ]    0.026452
R1  R0 911.3  1101.0

T [ R2 , R1 ]  T [ R1 , R0 ]
b2  T [ R2 , R1 , R0 ] 
R2  R0

T ( R2 )  T ( R1 )
T [ R2 , R1 ]   0.036284
R2  R1

T [ R1 , R0 ]  0.026452

T [ R2 , R1 ]  T [ R1 , R0 ]  0.036284  0.026452
b2    2.1144  10 5
R2  R0 636.0  1101.0

T [ R3 , R2 , R1 ]  T [ R2 , R1 , R0 ]
b3  T [ R3 , R2 , R1 , R0 ] 
R3  R0
T [ R3 , R2 ]  T [ R2 , R1 ]
T [ R3 , R2 , R1 ] 
R3  R1

T ( R3 )  T ( R2 ) 50.128  40.120
T [ R3 , R2 ]    0.054127
R3  R2 451.1  636.0

T [ R2 , R1 ]  0.036284

T [ R3 , R2 ]  T [ R2 , R1 ]  0.054127  0.036284
T [ R3 , R2 , R1 ]    3.8771  10 5
R3  R1 451.1  911.3

T [ R2 , R1 , R0 ]  2.1144  10 5

7
T [ R3 , R2 , R1 ]  T [ R2 , R1 , R0 ] 3.8771  10 5  2.1144  10 5
b3    2.7124  10 8
R3  R0 451.1  1101.0

Hence
T ( R)  b0  b1 ( R  R0 )  b2 ( R  R0 )( R  R1 )  b3 ( R  R0 )( R  R1 )( R  R2 )
 25.113  0.026452( R  1101.0)  2.1144  10 5 ( R  1101.0)( R  911.3)
 2.7124  10 8 ( R  1101.0)( R  911.3)( R  636.0), 451.1  R  1101.0

If we expand the above result, we get

T R   92.759  0.13093R  9.2975  10 5 R 2  2.7124  10 8 R 3 , 451.1  R  1101.0

This is the same expression that was obtained with the direct method.

At R  754.8,
T (754.8)  35.242 C

b) The absolute relative true error t obtained between the results from the second
and third order polynomial is

35.242  35.285
t   100
35.242
 0.122%

Lagrange Method

The Lagrangian interpolating polynomial is given by


n
f n ( x)   Li ( x) f ( xi )
i 0

where n in f n (x) stands for the n order polynomial that approximates the function
th

y  f (x) given at n  1 data points as x0 , y0 , x1 , y1 ,......, xn1 , y n1 , xn , y n  , and
n x  xj
Li ( x)  
j  0 xi  x j
j i

Li (x) is a weighting function that includes a product of n  1 terms with terms of j  i


omitted. The application of Lagrangian interpolation will be clarified using an example.

8
Example 3

Use data from example 1 to determine second order Lagrangian interpolating polynomial
and find the temperature for a resistor value of 754.8 0hm.

Solution

For second order Lagrange polynomial interpolation, the temperature is given by

2
T ( R)   Li ( R)T ( Ri )
i 0

 L0 ( R)T ( R0 )  L1 ( R)T ( R1 )  L2 ( R)T ( R2 )

Since we want to find the temperature at R  754.8, we need to choose the three data
points that are closest to R  754.8 that also bracket R  754.8 to evaluate it. The three
points are R0  911.3, R1  636.0 and R2  451.1 .

Then
R0  911.3, T ( R0 )  30.131
R1  636.0, T ( R1 )  40.120
R2  451.1, T ( R2 )  50.128
gives
2 R  Rj
L0 ( R)  
j 0 R0  R j
j 0

 R  R1  R  R2 
   
 R0  R1  R0  R2 
2 RR
L1 ( R)  
j

j  0 R1  R j
j 1

 R  R0  R  R2 
   
 1
R  R 0  R1  R2 
2 R  Rj
L2 ( R)  
j  0 R2  R j
j 2

 R  R0  R  R1 
   
 R2  R0  R2  R1 
Hence

9
 R  R1  R  R2   R  R0  R  R2 
T ( R)    T ( R0 )    T ( R1 )
 R0  R1  R0  R2   R1  R0  R1  R2 
 R  R0  R  R1 
   T ( R2 ), R0  R  R2
 R2  R0  R2  R1 

(754.8  636.0)(754.8  451.1)


T (754.8)  (30.131)
(911.3  636.0)(911.3  451.1)
(754.8  911.3)(754.8  451.1)
 (40.120)
(636.0  911.3)(636.0  451.1)
(754.8  911.3)(754.8  636.0)
 (50.128)
(451.1  911.3)(451.1  636.0)
 (0.28478)(30.131)  (0.93372)(40.120)  (0.21850)(50.128)
 35.089 C

Spline Interpolation

(1) Linear Spline

This simply involves forming straight lines through the consecutive data.
y

(x3, y3)

(x1, y1)

(x2, y2)
(x0, y0)
x
Figure 6 Linear splines.

So if the above data is given in an ascending order, the linear splines are given by:

f ( x1 )  f ( x0 )
f ( x)  f ( x0 )  ( x  x0 ), x0  x  x1
x1  x0
f ( x2 )  f ( x1 )
 f ( x1 )  ( x  x1 ), x1  x  x2
x2  x1
.
.
.
f ( xn )  f ( xn1 )
 f ( xn1 )  ( x  xn1 ), xn1  x  xn
xn  xn1

10
Note the terms of
f ( xi )  f ( xi 1 )
xi  xi 1
in the above function are simply slopes between xi 1 and xi .

(2)Quadratic Splines
One of the drawbacks of linear spline is the abrupt change of slope at the interior points of
the data that makes the first derivative to be discontinuous at these points. This can be
improved by using quadratic splines.
So given x0 , y0 , x1 , y1 ,......, xn1 , y n1 , xn , y n  , we can fit quadratic polynomials between
two consecutive points determined by:

f ( x)  a1 x 2  b1 x  c1 , x0  x  x1
 a2 x 2  b2 x  c2 , x1  x  x2
.
.
.
 an x 2  bn x  cn , xn1  x  xn

Determining Coefficients:

There are 3n such coefficients


ai , i  1,2,....., n
bi , i  1,2,....., n
ci , i  1,2,....., n
To find 3n unknowns, one needs to set up 3n equations and then simultaneously solve
them. These 3n equations are found as follows.
1. Each quadratic spline goes through two consecutive data points
a1 x0  b1 x0  c1  f ( x0 )
2

a1 x1  b1 x1  c1  f ( x1 )
2

.
.
.
an xn1  bn xn1  cn  f ( xn1 )
2

an xn  bn xn  cn  f ( xn )
2

This condition gives 2n equations as there are n quadratic splines going through two
consecutive data points.
2. The first derivatives of two quadratic splines are continuous at the interior points. For
example, the derivative of the first spline

11
a1 x 2  b1 x  c1
is
2a1 x  b1
The derivative of the second spline
a2 x 2  b2 x  c2
is
2a2 x  b2
and the two are equal at x  x1 giving
2a1 x1  b1  2a2 x1  b2
2a1 x1  b1  2a2 x1  b2  0
Similarly at the other interior points,
2a2 x2  b2  2a3 x2  b3  0
.
.
.
2ai xi  bi  2ai 1 xi  bi 1  0
.
.
.
2an1 xn1  bn1  2an xn1  bn  0

Since there are (n  1) interior points, we have (n  1) such equations. So far, the total
number of equations is (2n)  (n  1)  (3n  1) equations. We still then need one more
equation.
We can assume that the first spline is linear, that is
a1  0
This gives us 3n equations and 3n unknowns. These can be solved by a number of
techniques used to solve simultaneous linear equations.

Exercise 1

Use data from example 1 to determine the temperature corresponding to 754.8 ohms using
linear and quadratic splines and compare the results.

12

You might also like