E_LectureNumerical AnalysisNumerical Analysis BSC 3rd classLecturesLectures3) Lecture 2 Interpolation and Approximation (Curve Fitting)
E_LectureNumerical AnalysisNumerical Analysis BSC 3rd classLecturesLectures3) Lecture 2 Interpolation and Approximation (Curve Fitting)
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 points (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:
f1 ( x) L1 f x1 L2 f x2
is produced where:
x x2 x x1
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 error is 2.2192 – 2.2188 = 0.0004
Numerical Analysis /Lec. 2 - 19 -
Third Class
II. Quadratic
By weighting the average of the three points that produce the parabola we can derive
the formula:
f 2 ( x) L1 f x1 L2 f x2 L3 f x3
is produced where:
( x x2 )( x x3 ) ( x x1 )( x x3 ) ( x x1 )( x x2 )
L1 L2 L3
( x1 x2 )( x1 x3 ) ( x2 x1 )( x2 x3 ) ( x3 x1 )( x.3 x2 )
Example 2.2
Compute ln 9.2 from the data in the previous example 2.1 and the additional third
value ln 11.0 = 2.3979.
Solution:
( x 9.5)( x 11.0)
L1 ( x) x 2 20.5 x 104.5, L1 (9.2) 0.5400,
(9.0 9.5)(9.0 11.0)
( x 9.0)( x 11.0) 1
L2 ( x) ( x 2 20 x 99), L2 (9.2) 0.4800,
(9.5 9.0)(9.5 11.0) 0.75
( x 9.0)( x 9.5) 1
L3 ( x) ( x 2 18.5 x 85.5), L3 (9.2) 0.0200.
(11.0 9.0)(11.0 9.5) 3
ln 9.2 p2(9.2) = 0.5400 × 2.1972 + 0.4800 ×2.2513 0.0200×2.3979 = 2.2192.
Example 2.3
For the function f(x) = ln(x + 1), construct interpolation polynomials of degree one
and two to approximate f(0.45) from the given nodes. Find the error bound and the
actual error.
xk 0 0.6 0.9
ln(x + 1) 1 0.47000 0.64185
Solution
First degree polynomial
x 0.6 x0
P1(x) = (0) + (0.47) = 0.78334x
0 0.6 0.6 0
P1(0.45) = 0.3525
Actual error = |ln(1 + 0.45) P1(0.45)| = 0.0191
Second degree polynomial
( x 0.6)( x 0.9) ( x 0)( x 0.9) ( x 0)( x 0.6)
P2(x) = (0) + (0.47)+ (0.64185)
(0 0.6)(0 0.9) (0.6 0)(0.6 0.9) (0.9 0.6)(0.9 0.6)
P2(0.45) = 0.36829
Actual error = |ln(1 + 0.45) P2(0.45)| = 0.0033
Numerical Analysis /Lec. 2 - 20 -
Third Class
III. General Lagrange Interpolating Polynomial
In general, the Lagrange polynomial can be represented as:
n n x xj
f n1 ( x) Li ( x) f ( xi ) where Li ( x)
i 1 j 1 xi x j
j i
Example 2.4
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.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)
b)Quadratic
f 2 ( x)
x 1.5( x 3) sin 0 x 0( x 3)
1.5 x 0( x 1.5) 3
sin
sin
(0 1.5)(0 3) 2 (1.5 0)(1.5 3) 2 (3 0)(3 1.5) 2
f 2 0 0.303x( x 3) 0.222 x( x 1.5)
f 2 0.081x 2 0.576 x
c)Cubic
f 3 ( x)
x 1( x 2)( x 3) sin 0 x 0( x 2)( x 3) sin 1 x 0( x 1)( x 3) sin 2
(0 1)(0 2)(0 3) 2 (1 0)(1 2)(1 3) 2 (2 0)(2 1)(2 3) 2
x 0( x 1)( x 2) sin 3
(3 0)(3 1)(3 2) 2
f 3 0 0.240 x( x 2)( x 3) 0.421x( x 1)( x 3) 0.166 x( x 1)( x 2)
f 3 0.015 x 3 .014 x 2 0.509 x
d) Errors Now using x = 2.2:
.7304 .8912
f1(2.2) ≈ 0.7304 producing errorf 1 .180%
.8912
.8752 .8912
f2(2.2) ≈ 0.8752 producing errorf 2 .018%
.8912
.8923 .8912
f3(2.2) ≈ 0.8923 producing errorf 3 .0012%
.8912
Using similar triangles the slopes are the same and hence:
f1 ( x) f ( x1 ) f ( x2 ) f ( x1 )
x x1 x2 x1
And thus the coordinate on the curve at x1 can be approximated by rearranging the
above to become:
f ( x2 ) f ( x1 )
f1 ( x) f ( x1 ) ( x x1 )
x2 x1
Example 2.7
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.
f 2 ( x 2 ) f 2 ( x1 )
b2
x 2 x1
And again by substitution of b1 and b2 we derive that:
f 2 ( x 2 ) f 2 ( x1 )
f 2 ( x3 ) f 2 ( x1 ) ( x3 x1 ) b3 ( x3 x1 )( x3 x 2 )
x 2 x1
f 2 ( x3 ) f 2 ( x 2 ) f 2 ( x 2 ) f 2 ( x1 )
x3 x 2 x 2 x1
b3
x3 x1
f 2 ( x3 ) f 2 ( x2 ) f 2 ( x2 ) f 2 ( x1 )
f 2 ( x2 ) f 2 ( x1 ) x3 x2 x2 x1
f 2 ( x) f 2 ( x1 ) ( x x1 ) ( x x1 )( x x2 )
x2 x1 x3 x1
Example 2.9
Fit a third-order Newton’s interpolating polynomial to estimate log 10 using the data
from Problem 2.8
Solution:
First, order the points
x0 = 9 f(x0) = 0.9542425
x1 = 11 f(x1) = 1.0413927
x2 = 8 f(x2) = 0.9030900
x3 = 12 f(x3) = 1.0791812
The first divided differences can be computed as
1.0413927 0.9542425
f [ x1 , x0 ] 0.0435751
11 9
0.9030900 1.0413927
f [ x 2 , x1 ] 0.0461009
8 11
1.0791812 0.9030900
f [ x3 , x 2 ] 0.0440228
12 8
The second divided differences are
0.0461009 0.0435751
f [ x 2 , x1 , x0 ] 0.0025258
89
0.0440228 0.0461009
f [ x3 , x 2 , x1 ] 0.0020781
12 11
The third divided difference is
0.0020781 (0.0025258)
f [ x3 , x2 , x1 , x0 ] 0.00014924
12 9
Substituting the appropriate values into Eq. (18.7) gives
f 3 ( x) 0.9542425 0.0435751( x 9) 0.0025258( x 9)( x 11)
0.00014924( x 9)( x 11)( x 8)
which can be evaluated at x = 10 for
f 3 ( x) 0.9542425 0.0435751(10 9) 0.0025258(10 9)(10 11)
0.00014924(10 9)(10 11)(10 8) 1.0000449
b)Quadratic
0
b1 sin 0
2
1.5 0
sin sin
b2 f [ x2 , x1 ] 2 0.454
2
1.5 0
c)Cubic
0
b1 sin 0
2
1 0
sin sin
f [ x2 , x1 ] 2 0.479 which is b
2
1 0
2
0.362 0.479
f [ x3 , x2 , x1 ] 0.0585 which is b3
20
0.156 0.362
f [ x4 , x3 , x2 ] 0.103
3 1
0.103 (0.0585)
f [ x4 , x3 , x2 , x1 ] 0.015 which is b4
30
f 3 0.015( x 0)( x 1)( x 2) 0.0585( x 0)( x 1) 0.479( x 0) 0
f 3 0.015 x( x 1)( x 2) 0.0585 x( x 1) 0.479 x
Now using x = 2.2:
.7304 .8912
f1(2.2) ≈ 0.7304 producing errorf 1 .180
.8912
.8741 .8912
f2(2.2) ≈ 0.8741 producing errorf 2 .019
.8912
.8914 .8912
f3(2.2) ≈ 0.8914 producing errorf 2 .0002
.8912