CH 5 Interpolation, Approximation and Curve Fitting
CH 5 Interpolation, Approximation and Curve Fitting
===========================Chapter 5=========================
====================Curve Fitting and Interpolation==============
=====================================================================
x ,y , ( x1 , y1) ,
Experimental data is given only in the form of discrete points such as ( 0 0 )
.. . .. . , ( x n−1 , y n−1) , ( x n , y n ) 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.
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 , y2 ) f x
x0 , y 0
x
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
n
y=a0 +a1 x+. . .. .. . .. .. . .. .+an x (1)
1
through the data, where 0 1 a ,a ,...,a
n 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 T
( ohm ) ( °C )
1101.0 25.113
911.3 30.131
636.0 40.120
451.1 50.128
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
2
Figure 3 linear interpolation.
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 ( R 0 ) =T ( 911. 3 )=a0 + a1 ( 911 . 3 )=30 . 131
T ( R1 )=T ( 636 .0 )=a 0 +a 1 ( 636. 0 )=40 . 120
1 911. 3 a 0 30 .131
[ =][ ] [
1 636 . 0 a1 40 .120 ]
Solving the above two equations gives
Hence
T ( R )=a0 +a1 R
=63 .197−0 .036284 R , 636 .0≤R≤911.3
At R=754 . 8 ,
T ( 754 .8 )=63.197−0.036284 ( 754 .8 )
=35.809 °C
x1 , y1 x2 , y 2
f 2 x
x0 , y0
x
3
Figure 4 Quadratic interpolation.
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 )2 =30 .131
2
T ( 636 . 0 )=a0 +a1 ( 636 . 0 )+a2 ( 636 . 0 ) =40 . 120
T ( 451 . 1 )=a0 +a1 ( 451. 1 ) +a2 ( 451. 1 )2 =50. 128
1 911 . 3 8 .3047×105 a0
[ 5
1 636 . 0 4 . 0450×10 a1 =
][ ] [ ]
30. 131
40. 120
1 451 .1 2. 0349×10 a2 50. 128
5
a0 =85 . 668
a1 =−0 . 096275
a2 =3 . 8771×10−5
Hence
−5 2
T ( R )=85. 668−0 .096275 R+3 . 8771×10 R , 451. 1≤R≤911. 3
At R=754 . 8 ,
2
T ( 754. 8 )=85.668−0.096275 ( 754 . 8 ) +3. 8771×10−5 ( 754. 8 )
=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
4
2 3
T ( R )=a0 + a1 R+a 2 R +a 3 R
y
x3 , y3
f 3 x
x1 , y1
x0 , y 0 x2 , y2
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
2 3
T ( 1101. 0 )=a 0 +a1 ( 1101. 0 )+a2 ( 1101. 0 ) +a 3 ( 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 ) +a 3 ( 451 .1 ) =50 .128
[ 1
1
1
911 . 3
636 . 0
451 .1
8. 3047×105
4 . 0450×105
2. 0349×105
7 .5681×108
2. 5726×108
9 .1795×107
][ ] [ ]
a1
a2
= 30 . 131
40 . 120
a 3 50 . 128
a0 =92. 759
a1 =−0 . 13093
a2 =9 . 2975×10−5
−8
a3 =−2 . 7124×10
Hence
−5 2 −8 3
T ( R )=92. 759−0. 13093 R+9 .2975×10 R −2 . 7124×10 R , 451 .1≤R≤1101. 0
5
T ( 754 .8 )=35 .242 ° C
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
f n ( x )=b0 +b1 ( x−x 0 )+. .. .+bn ( x−x 0 )( x−x 1 ).. .( x−x n−1 )
where
b0 =f [ x0 ]
b1 =f [ x 1 , x 0 ]
b2 =f [ x 2 , x 1 , x 0 ]
bn =f [ xn , x n−1 ,. ... , x 0 ]
th
and the n divided difference is defined as
f [ x n , .. . .. .. . , x 1 ]−f [ x n−1 ,. .. . .. .. , x 0 ]
bn ==
x n −x 0
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
6
T ( R )=b 0 +b 1 ( R−R 0 )+b2 (R−R0 )( R−R1 )+b3 ( R−R0 )( R−R 1 )( R−R2 )
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
T [ R2 , R1 ]−T [ R1 , R0 ]
b2 =T [ R 2 , R1 , R 0 ]=
R2 −R0
T ( R2 )−T ( R1 )
T [ R2 , R1 ]= =−0 . 036284
R 2−R1
T [ R1 , R0 ]=−0 . 026452
T [ R3 , R 2 , R1 ]−T [ R 2 , R 1 , R 0 ]
b3 =T [ R 3 , R 2 , R 1 , R 0 ]==
R3 −R0
T [ R3 , R2 ]−T [ R2 , R1 ]
T [ R3 , R2 , R1 ]=
R3 −R1
T [ R2 , R1 ]=−0 . 036284
−5
T [ R2 , R1 , R0 ]=2 .1144×10
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 )=b 0 +b 1 ( R−R 0 )+b2 (R−R0 )( R−R1 )+b3 ( R−R0 )( R−R 1 )( R−R2 )
−5
=25 . 113−0 .026452( R−1101.0 )+2. 1144×10 ( R−1101. 0 )( R−911. 3 )
−8
−2. 7124×10 ( R−1101. 0 )( R−911. 3)( R−636 . 0), 451 .1≤R≤1101. 0
−5 2 −8 3
T ( R )=92. 759−0. 13093 R+9 .2975×10 R −2 . 7124×10 R , 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
35.242−35.285
|∈t|=| |×100
35.242
=0 . 122 %
Lagrange Method
¿ j≠i ¿¿¿ ¿
n
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
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 ( R 0 )=30 .131
R1 =636 .0 , T ( R1 )=40 .120
R2 =451 .1 , T ( R 2 )=50. 128
gives
¿ j≠0 ¿ ¿ ¿ ¿
2
R−R1 R−R 2
=
( R 0 −R 1 )( R0 −R 2 )
¿ j≠1 ¿¿¿ ¿
2
R−R0 R−R 2
=
( R 1−R 0 )( R1 −R2 )
¿ j≠2 ¿ ¿¿ ¿
2
R−R0 R−R 1
=
( R 2−R 0 )( R2 −R1 )
9
Hence
R−R 0 R−R1
+
( R2 −R0 )( R 2−R 1 )
T ( R2 ) , R 0 ≤R≤R 2
Spline Interpolation
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 ( x 1 )−f ( x 0 )
f (x )=f (x 0 )+ ( x−x 0 ),
x1 −x 0 x 0≤ x≤x1
f (x 2 )−f ( x 1 )
=f ( x 1 )+ ( x−x 1 ),
x 2−x 1 x 1≤x≤x 2
.
.
.
10
f ( x n )−f ( x n−1 )
=f ( x n−1 )+ ( x−x n−1 ),
x n −x n−1 x n−1 ≤x≤x n
Note the terms of
f ( x i )−f ( x i−1 )
x i −xi−1
in the above function are simply slopes between
x i−1 and x i .
(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.
x , y , x , y ,. .. . .. , ( x n−1 , y n−1 ) , ( x n , y n )
So given ( 0 0 ) ( 1 1 ) , we can fit quadratic polynomials between
two consecutive points determined by:
f (x )=a1 x 2 + b1 x+ c 1 , x 0≤ x≤x1
=a 2 x 2 +b2 x +c 2 , x 1≤x≤x 2
.
.
.
2
=a n x +b n x+ c n , x n−1 ≤x≤x n
Determining Coefficients:
11
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
2
a1 x + b1 x+ c 1
is
2 a1 x+b1
The derivative of the second spline
2
a2 x + b2 x+ c 2
is
2 a2 x+b2
and the two are equal at x=x 1 giving
2 a1 x 1 +b1 =2 a2 x 1 +b 2
2 a1 x 1 +b1 −2 a2 x 1 −b2 =0
Similarly at the other interior points,
2 a2 x 2 +b 2−2 a3 x2 −b 3=0
.
.
.
2 ai xi +bi −2 ai+1 x i−bi+1 =0
.
.
.
2 an−1 x n−1+b n−1 −2 an x n−1 −b n=0
Since there are (n−1) interior points, we have (n−1) such equations. So far, the total
number of equations is (2 n)+( n−1)=(3 n−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