Lec 2
Lec 2
What is interpolation?
Many times, data is given only at discrete points such as (x1, y1), (x2, y2),………. (xn, yn),
(xn+1, yn+1). So, how then does one find the value of y at any other value of x?
Well, a continuous function f(x) may be used to represent the n+1 data values with f(x)
passing through the n+1 point (Figure 2.1). Then we can find the value of y at any other
value of x. This is called interpolation.
Of course, if x falls outside the range of x for which the data is given, it is no longer
interpolation, but instead, is called extrapolation.
y
x3 , y3
x1, y1
f x
x2 , y2
x0 , y0
x
For n+1 data points, there is one and only one polynomial of order n that passes
through all the points. For example, there is only one straight line (that is, a
first-order polynomial) that connects two points. Similarly, only one parabola
connects a set of three points.
Polynomial Interpolation consists of determining the unique n th order polynomial that
fits n+1 data points. This polynomial then provides a formula to compute
intermediate values.
One of the methods used to find this polynomial is called the Lagrange method of
interpolation. Other methods include Newton’s divided difference polynomial method
and the direct method.
f(x) f(x)
f(x1)
f(x0) f(x0)
x0 x1 x x0 x1 x2 x
Figure 2.2 First and second order polynomial approximation.
I. Linear
By weighting the average of the two values used to produce the coordinates of the
line the formula:
x x2 x x1
f1 ( x) L1 f x1 L2 f x2 where: L1 L2
x1 x 2 x 2 x1
Example 2.1
Compute a 4-decimal place value of ln 9.2 from ln 9.0 = 2.1972, ln 9.5 = 2.2513 by
linear Lagrange interpolation and determine the error, using the exact value of ln 9.2
= 2.2192.
Solution:
x1 = 9.0 , x2 = 9.5 , f1 = ln 9.0= 2.1972 , f2 = ln 9.5= 2.2513 ; hence we get
x 9.5
L1 ( x) 2.0( x 9.5), L1 (9.2) 2.0(0.3) 0.6
0.5
x 9.0
L2 ( x) 2.0( x 9.0), L2 (9.2) 2 0.2 0.4
0.5
ln 9.2 p1 (9.2) = L1 (9.2)f1 + L2 (9.2)f2 = 0.6×2.1972 + 0.4×2.2513 = 2.2188
The absolute error is 2.2192 - 2.2188 = 0.0004
Example 2.3
Find the Lagrange interpolation polynomial that takes the values prescribed below
xk 0 1 2 4
f(xk) 1 1 2 5
Solution
3
P3(x) = L
k 0
3,k ( x ) f(xk)
Example 2.4
The following table gives the value of density of saturated water for various
temperatures of saturated stream.
Temp oC ( = T) 100 150 200 250
Density kg/m3 (= d) 958 917 865 799
1) Use third order Lagrange interpolating polynomials to correlate density as a
function of temperature.
2) Find the densities when the temperatures are 130oC .
Solution
(T 150)(T 200)(T 250)
L1 - 1.3333 10-6 T 3 + 4 10-3 T 2 - 0.1566T + 10
(100 150)(100 200)(100 250)
(T 100)(T 200)(T 250)
L2 4 10-6 T 3 - 2.2 10-3 T 2 0.38T - 20
(150 100)(150 200)(150 250)
(T 100)(T 150)(T 250)
L3 - 4 10-6 T 3 + 2 10-3 T 2 - 0.31T + 15
(200 100)(200 150)(200 250)
(T 100)(T 150)(T 200)
L4 1.3333 10-6 T 3 + 6 10-4 T 2 - 0.08666 - 4
(250 100)(250 150)(250 200)
f 4 (x) L1f (x1 ) L2f (x 2 ) L3f (x 3 ) L4f (x 4 ) - 4 10-6 T3 - 4 10-4 T 2 - 0.53T 1019
f 4 (130) 934.5520
Example 2.5
Use Lagrange global interpolation by one polynomial and piecewise polynomial
interpolation with quadratic for the following nodes.
xk 0 1 2 4 5
f(xk) 0 16 48 88 0
Solution
4
Global interpolation by one polynomial: P(x) = L
k 0
4 ,k ( x ) f(xk)
I. Linear Interpolation
Consider the diagram below in which a curve is modeled (poorly) by x1 x2 :
Using similar triangles the slopes are the same and hence:
f1 ( x) f ( x1 ) f ( x2 ) f ( x1 )
x x1 x2 x1
Example 2.6
Estimate the common logarithm of 10 using linear Newton’s interpolation.
(a) Interpolate between log 8 = 0.9030900 and log 12 = 1.0791812.
(b) Interpolate between log 9 = 0.9542425 and log 11 = 1.0413927.
For each of the interpolations, compute the percent relative error based on the true
value.
Solution
1.0791812 0.90309
a) f1 (10) 0.90309 (10 8) 0.991136
12 8
1 0.991136
t 100% 0.886%
1
1.0413927 0.9542425
b) f1 (10) 0.9542425 (10 9) 0.997818
11 9
1 0.997818
t 100% 0.218%
1
f ( x3 ) f ( x2 ) f ( x2 ) f ( x1 )
f ( x2 ) f ( x1 ) x3 x2 x2 x1
f 2 ( x) f ( x1 ) ( x x1 ) ( x x1 )( x x2 )
x2 x1 x3 x1
f n 1 ( x) b1 b2 ( x x1 ) b3 ( x x1 )( x x2 ) .... bn ( x x1 )( x x2 )...( x xn 1 )
b0
x0 f ( x0 ) b1
f [ x1 , x0 ] b2
x1 f ( x1 ) f [ x2 , x1 , x0 ] b3
f [ x2 , x1 ] f [ x3 , x2 , x1 , x0 ]
x2 f ( x2 ) f [ x3 , x2 , x1 ]
f [ x3 , x 2 ]
x3 f ( x3 )
f 3 ( x) f [ x0 ] f [ x1 , x0 ]( x x0 ) f [ x2 , x1 , x0 ]( x x0 )( x x1 )
f [ x3 , x2 , x1 , x0 ]( x x0 )( x x1 )( x x2 )
Example 2.8
The following table gives the value of density of saturated water for various temperatures of saturated
stream.
Tempo C ( = T) : 100 150 200 250 300
Density kg/m3 (= d) : 958 917 865 799 712
Using Newton divided difference interpolating find the densities when the temperatures are
130oC and 275oC respectively.
Solution
i T D f[xi+1,xi] f[xi+2,xi+1,xi] f[xi+3,xi+2,xi+1,xi] f[xi+4,xi+3,xi+2,xi+1,xi]
1 100 958
-0.8200
2 150 917 -0.0022
-1.0400 -4×10-6
3 200 865 -0.0028 -2.6667×10-8
-1.3200 -9.333×10-6
4 250 799 -0.0042
-1.7400
5 300 712
Numerical Analysis /Lec. 2 - 12 -
Third Class
P4 = 958 - 0.8200 (T - 100) - 0.0022 (T - 100) * (T - 150) - 4 10-6 (T - 100) * (T - 150) * (T - 200)
- 2.6667 10-8 (T - 100) * (T - 150) * (T - 200) * (T - 250)
Or by direct substitution
P4 (130) 934.6864 kg/m3
P(275)=958-0.82×(275-100)-0.0022×(275-100)×(275-150)-4×10-6×(275-100)
×(275-150) ×(275-200) -2.6667×10-8 ×(275-100)×(275-150)×(275-200) ×(275-250)
= 758.7188 kg/m3