0% found this document useful (0 votes)
8 views

E_LectureNumerical AnalysisNumerical Analysis BSC 3rd classLecturesLectures3) Lecture 2 Interpolation and Approximation (Curve Fitting)

The document explains interpolation and approximation methods, particularly focusing on polynomial interpolation using techniques like the Lagrange method. It details how to compute interpolated values at given points and provides examples for linear, quadratic, and cubic interpolations. Additionally, it discusses the concept of extrapolation and the uniqueness of polynomial fitting for a set of data points.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

E_LectureNumerical AnalysisNumerical Analysis BSC 3rd classLecturesLectures3) Lecture 2 Interpolation and Approximation (Curve Fitting)

The document explains interpolation and approximation methods, particularly focusing on polynomial interpolation using techniques like the Lagrange method. It details how to compute interpolated values at given points and provides examples for linear, quadratic, and cubic interpolations. Additionally, it discusses the concept of extrapolation and the uniqueness of polynomial fitting for a set of data points.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

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

Figure 2.1 Interpolation of discrete data

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.

Numerical Analysis /Lec. 2 - 18 -


Third Class
2.1 Lagrange Interpolating Polynomial
Consider a function f(x) that passes through the two distinct points (x0, f(x0)) and (x1,
f(x1)) as shown in Figure 2.2. The first order polynomial that approximates the
function between these two points can be expressed as
f(x) = a + bx
Where a and b are constants. f(x) can also be written in Lagrangian form as
f(x) = c0(x  x1) + c1(x  x0)
f(x1) f(x2)

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 x0
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 n1 ( 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)

( x  1)( x  2)( x  4) ( x  0)( x  2)( x  4)


P3(x) = (1) + (1)
(0  1)(0  2)(0  4) (1  0)(1  2)(1  4)
( x  0)( x  1)( x  4) ( x  0)( x  1)( x  2)
+ (2) + (5)
(2  0)( 2  1)( 2  4) (4  0)( 4  1)( 4  2)
When working with grids having large numbers of intervals one typically assigns a
set of low degree (n = 1, 2, or 3) basis functions to each adjacent set of n+1 = 2, 3, or
4 nodes.

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)

( x  1)( x  2)( x  4)( x  5) ( x  0)( x  2)( x  4)( x  5)


P4(x) = (0) + (16)
(0  1)(0  2)(0  4)(0  5) (1  0)(1  2)(1  4)(1  5)
( x  0)( x  1)( x  4)( x  5) ( x  0)( x  1)( x  2)( x  5)
+ (48) + (88) + 0
(2  0)( 2  1)( 2  4)( 2  5) (4  0)( 4  1)( 4  3)( 4  5)
Piecewise polynomial interpolation with quadratic
( x  1)( x  2) ( x  0)( x  2) ( x  0)( x  1)
P2(x) = (0) + (16) + (48); 0x2
(0  1)(0  2) (1  0)(1  2) (2  0)( 2  1)
( x  4)( x  5) ( x  2)( x  5) ( x  2)( x  4)
P2(x) = (48) + (88) + (0); 2x5
(2  4)( 2  5) (4  2)( 4  5) (5  2)(5  4)

Numerical Analysis /Lec. 2 - 21 -


Third Class
Example 2.6
Consider the function f ( x)  sin  over [0, 3].
x
2
a. Create a linear Lagrange Interpolating Polynomial to model f over [0,3]
b. Create a quadratic Lagrange Interpolating Polynomial to model f over [0,3]
with x1 = 0, x2 = 1.5, and x3 = 3.
c. Create a cubic Lagrange Interpolating Polynomial to model f over [0,3] with x1
= 0, x2 = 1, x3 = 2, and x4 = 3.
d. Use each polynomial to approximate f(2.2) and compute the error between
each numerical method and the true approximation f(2.2) ≈ 0.8912.
Solutions
a)Linear
0
x  sin  
x3 0  2  sin  3 
f1 ( x)  sin     
03 2 30 2
 f1  0.332 x

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

Numerical Analysis /Lec. 2 - 22 -


Third Class
2.1 Newton Interpolating
The Lagrangian interpolation polynomials are useful in discussions on numerical
integration. An alternative in interpolation is ‘Newton’s Divided Difference
Interpolation’. It involves fewer arithmetical operations.
Another advantage of Newton’s rests with the following scenario. Suppose we need to
improve the accuracy and increase the number of grid points. From the forms of
Lagrange interpolation polynomials, all the terms have to be evaluated once again,
and this is a huge amount of work if the number of points is large. Newton’s does not
suffer from this drawback, and just one additional term needs to be computed.
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
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.

Numerical Analysis /Lec. 2 - 23 -


Third Class
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

II. Quadratic Interpolation


To reduce the error, a quadratic interpolation that introduces some curvature into the
interpolation is used. The form:
f 2 ( x)  b1  b2 ( x  x1 )  b3 ( x  x1 )( x  x2 )
Let x = x1 to produce:
f 2 ( x1 )  b1
Let x = x2 and use the previous identity to produce:
f 2 ( x 2 )  f 2 ( x1 )  b2 ( x 2  x1 )  b3 ( x  x1 )( x  x 2 )

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

Numerical Analysis /Lec. 2 - 24 -


Third Class
Example 2.8
Fit a second-order Newton’s Interpolating polynomial to estimate log 10 using the
data from Example 2.7 at x = 8, 9, and 11. Compute the true percent relative error.
Solution
First, order the points
x1 = 9 f(x1) = 0.9542425
x2 = 11 f(x2) = 1.0413927
x3 = 8 f(x3) = 0.9030900
b1 = 0.9542425
1.0413927  0.9542425
b2   0.0435751
11  9
0.9030900  1.0413927
 0.0435751
8  11 0.0461009  0.0435751
b3    0.0025258
89 89
Substituting these values yields the quadratic formula
f 2 ( x)  0.9542425  0.0435751( x  9)  0.0025258( x  9)( x  11)
which can be evaluated at x = 10 for
f 2 (10)  0.9542425  0.0435751(10  9)  0.0025258(10  9)(10  11)  1.0003434
1  1.0003434
t   100%  0.03434%
1

III. General Newton Interpolating Polynomial


In general, if we find the finite differences defined as:
f ( xi )  f ( x j )
f [ xi , x j ] 
xi  x j
f [ xi , x j ]  f [ x j , xk ]
f [ xi , x j , xk ] 
xi  xk

f [ xn , xn1 ,..., x2 ]  f [ xn1 , xn2 ,..., x1 ]
f [ xn , xn1 ,..., x1 ] 
xn  x1
Then the general Newton Interpolating Polynomial of order n – 1with n data points is
defined as:

f n1 ( x)  b1  b2 ( x  x1 )  b2 ( x  x1 )( x  x2 )  ....  bn ( x  x1 )( x  x2 )...( x  xn )

Numerical Analysis /Lec. 2 - 25 -


Third Class
b1  f ( x1 )
b2  f [ x 2 , x1 ]
Where b3  f [ x3 , x 2 , x1 ]

bn  f [ x n , x n 1 ,..., 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
89
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

Numerical Analysis /Lec. 2 - 26 -


Third Class
Example 2.10
Consider the function f ( x)  sin  over [0, 3].
x
2
a. Create a linear Newton Interpolating Polynomial to model f over [0,3]
b. Create a quadratic Newton Interpolating Polynomial to model f over [0,3] with
x1 = 0, x2 = 1.5, and x3 = 3.
c. Create a cubic Newton Interpolating Polynomial to model f over [0,3] with x 1
= 0, x2 = 1, x3 = 2, and x4 = 3.
e. Use each polynomial to approximate f(2.2) and compute the error between
each numerical method and the true approximation f(2.2) ≈ 0.8912.
Solutions
a)Linear
0 3
sin    sin  
0
f1  sin       2  ( x  0)
2
2 03
 f1  0.332 x

b)Quadratic
0
b1  sin    0
2
 1.5  0
sin    sin  
b2  f [ x2 , x1 ]     2   0.454
2
1.5  0

3  1.5   1.5  0


sin    sin   sin    sin  
2  2   2  2
3  1.5 1.5  0 0.211  0.454
b3  f [ x3 , x2 , x1 ]    0.081
30 3
so f 2  0  0.454( x  0)  0.081( x  0)( x  1.5)
 f 2  0.081x( x  1.5)  0.454 x

c)Cubic
0
b1  sin    0
2
1 0
sin    sin  
f [ x2 , x1 ]     2   0.479  which is b
2
1 0
2

Numerical Analysis /Lec. 2 - 27 -


Third Class
2 1
sin    sin  
f [ x3 , x2 ]     2   0.362
2
2 1
3 2
sin    sin  
f [ x4 , x3 ]     2   0.156
2
3 2

0.362  0.479
f [ x3 , x2 , x1 ]   0.0585  which is b3
20
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
30
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

Numerical Analysis /Lec. 2 - 28 -


Third Class

You might also like