Numericalmethods Lecture 1
Numericalmethods Lecture 1
Chapter 1 - Lecture 1
Polynomial Interpolation
1.1 Introduction
𝑦 = 𝑓(𝑥), 𝑥1 ≤ 𝑥 ≤ 𝑥𝑁
Every value of x in the range 𝑥1 ≤ 𝑥 ≤ 𝑥𝑁 , there exists one or more values of y. Assuming that f(x)
is single – valued and continuous and known explicitly, then the values of f(x) corresponding to
certain given values of x can easily be computed and tabulated.
If the values of a function f (x) at a set of points x1, x2, ..., xN is known but the analytic expression of
the function is unknown that lets us calculate its value at an arbitrary point.
The task now is to estimate f(x) for arbitrary x by drawing a smooth curve through (and perhaps
beyond) the xi.
The procedure of estimating the value of f (x) for the desired x
If the value for points between the largest and smallest of the xi’s (𝑥 ∈ [𝑥1 , 𝑥𝑁 ]) is called
interpolation
If the value is for points outside that range (𝑥 ∉ [𝑥1 , 𝑥𝑁 ]) is called extrapolation.
For example, given the set of tabular values of a census of the population of the Us that is taken every
10 years
1
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
To know the population of the US in year 1965 or year 2010, have to fit a function through the given
data.
The form of the function (𝜙 (𝑥)) that approximates the set of points should be a convenient one and
should be applicable to a general class of problems. The most usual class of functions fitted through
data are polynomials.
1.2 Polynomial Interpolation
The general formula for an (n – 1) th-order polynomial can be written as
𝑓(𝑥) = 𝑎1 + 𝑎2 𝑥 + 𝑎3 𝑥 2 + ⋯ + 𝑎𝑛 𝑥 𝑛−1
For n data points, there is one and only one polynomial of order (n − 1) that passes through all the
points. For example, there is only one straight line (i.e., a first-order polynomial) that connects two
points (Fig. 1a). Similarly, only one parabola connects a set of three points (Fig. 1b).
Figure 1: examples of interpolating polynomials: (a) first-order (linear) connecting two points, (b) second-order
(quadratic or parabolic) connecting three points, and (c) third-order (cubic) connecting four points.
Polynomial interpolation consists of determining the unique (n − 1)th order polynomial that fits n
data points. Then this polynomial provides a formula to compute intermediate values.
2
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
Figure 2: linear-interpolation
In general, the smaller the interval between the data points, the better the approximation. This is due
to the fact that, as the interval decreases, a continuous function will be better approximated by a
straight line. This characteristic is demonstrated in the following example.
3
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
Example 1: Estimate the natural logarithm of 2 using linear interpolation during interval 1 to 6. Then,
repeat the procedure, but use a smaller interval from 1 to 4. Note that the true value of ln 2 is
0.6931472.
For interval [1, 6],
𝑓(𝑥1 ) = ln 1 = 0,
𝑓(𝑥2 ) = ln 6 = 1.791759
𝑓(𝑥2 ) − 𝑓(𝑥1 )
𝑓1 (𝑥) = 𝑓(𝑥1 ) + (𝑥 − 𝑥1 )
𝑥2 − 𝑥1
ln 6 − ln 1 1.791759 − 0
𝑓1 (2) = ln 1 + (2 − 1) → 𝑓1 (2) = 0 + = 0.3583519
6−1 5
which represents an error of εt = 48.3%
For interval [1, 4],
𝑓(𝑥1 ) = ln 1 = 0,
𝑓(𝑥2 ) = ln 4 = 1.386294
ln 4 − ln 1 1.386294 − 0
𝑓1 (2) = ln 1 + (2 − 1) → 𝑓1 (2) = 0 + = 0.4620981
4−1 5
Thus, using the shorter interval reduces the percent relative error to εt = 33.3%. Both
interpolations are shown in Figure 3, along with the true function.
4
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
which represents a relative error of εt = 18.4%. Thus, the curvature introduced by the quadratic
formula (Figure 4) improves the interpolation compared with the result obtained using straight lines
5
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
Figure 4: The use of quadratic interpolation to estimate ln 2. The linear interpolation from x = 1 to 4 is also included for
comparison.
6
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
These differences can be used to evaluate the coefficients, which can then be substituted into the
general form of Newton.s interpolating polynomial:
𝑓𝑛−1 (𝑥) = 𝑓(𝑥1 ) + (𝑥 − 𝑥1 )𝑓[𝑥2 , 𝑥1 ] + (𝑥 − 𝑥1 )(𝑥 − 𝑥2 )𝑓[𝑥3 , 𝑥2 , 𝑥1 ] + ⋯
+ (𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) ⋯ (𝑥 − 𝑥𝑛−1 )𝑓[𝑥𝑛 , 𝑥𝑛−1 , ⋯ , 𝑥3 , 𝑥2 , 𝑥1 ]
Example 3: Employ a third order Newton polynomial to estimate ln 2 with a parabola.
𝑥1 = 1 𝑓(𝑥1 ) = 0
𝑥2 = 4 𝑓(𝑥2 ) = 1.386294
𝑥3 = 6 𝑓(𝑥3 ) = 1.791759
𝑥4 = 5 𝑓(𝑥4 ) = 1.609438
1.386294 − 0
𝑓[𝑥2 , 𝑥1 ] = = 0.4620981
4−1
1.791759 − 1.386294
𝑓[𝑥3 , 𝑥2 ] = = 0.2027326
6−4
7
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
1.609438 − 1.791759
𝑓[𝑥4 , 𝑥3 ] = = 0.1823216
5−6
The second divided differences
0.2027326 − 0.4620981
𝑓[𝑥3 , 𝑥2 , 𝑥1 ] = = −0.05187311
6−1
0.1823216 − 0.2027326
𝑓[𝑥4 , 𝑥3 , 𝑥2 ] = = −0.02041100
5−4
The third divided differences
−0.02041100 − (−0.05187311)
𝑓[𝑥4 , 𝑥3 , 𝑥2 , , 𝑥1 ] = = 0.007865529
5−1
Thus, the divided difference table is
8
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
3. With Newton's interpolation, if you add new points you don't have to re-calculate all the
coefficients. For example, the interpolation polynomial in the points 𝑥0 , 𝑥1 ,..., 𝑥𝑛 with addition the
point 𝑥𝑛+1 then using Newton's method the polynomial in the points 𝑥0 , 𝑥1 ,..., 𝑥𝑛 can be used to find
the polynomial for the points 𝑥0 , 𝑥1 ,..., 𝑥𝑛 , 𝑥𝑛+1You don't have to find all the coefficients all over
again.
1.5 Lagrange Interpolating Polynomial
The Lagrange interpolating polynomial is simply a reformulation of the Newton polynomial that
avoids the computation of divided differences. It can be represented as
𝑛
where ∏ designates the “product of.” For example, the linear version (n = 2) is
𝑓1 (𝑥) = 𝐿1 𝑓(𝑥1 ) + 𝐿2 𝑓(𝑥2 )
𝑥 − 𝑥2 𝑥 − 𝑥1
𝐿1 = 𝑎𝑛𝑑 𝐿2 =
𝑥1 − 𝑥2 𝑥2 − 𝑥1
9
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
Example 4: Use a Lagrange interpolating polynomial of the first and second order to evaluate the
density of unused motor oil at T = 15 °C based on the following data:
𝑥1 = 0 𝑓(𝑥1 ) = 3.85
𝑥2 = 20 𝑓(𝑥2 ) = 0.8
𝑥3 = 40 𝑓(𝑥3 ) = 0.212
15 − 20 15 − 0
𝑓1 (𝑥) = 3.85 + 0.8 = 1.5625
0 − 20 20 − 0
In a similar fashion, the second-order polynomial is developed as
Example 5: Use a Lagrange interpolating polynomial of the first, second and third order to evaluate
ln 2
𝑥1 = 1 𝑓(𝑥1 ) = 0
𝑥2 = 4 𝑓(𝑥2 ) = 1.386294
𝑥3 = 6 𝑓(𝑥3 ) = 1.791759
𝑥4 = 5 𝑓(𝑥4 ) = 1.609438
(𝑥 − 𝑥2 ) (𝑥 − 𝑥1 )
𝑓1 (𝑥) = 𝑓(𝑥1 ) + 𝑓(𝑥2 )
(𝑥1 − 𝑥2 ) (𝑥2 − 𝑥1 )
(2 − 4) (2 − 1)
𝑓1 (𝑥) = (0) + (1.386294) = 0.462098
(1 − 4) (4 − 1)
10
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
Exercises:
1. Calculate 𝑓(3.4) using the following data using first Newton’s interpolating polynomial and
second Lagrange polynomial
𝒙 1 2 2.5 3 4 5
𝒇(𝒙) 0 5 6.5 7 3 1
2. The acceleration due to gravity at an altitude y above the surface of the earth is given by
Compute g at y = 55,000 m.
11
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
When the base point values are equally spaced so that 𝑥1 − 𝑥0 = 𝑥2 − 𝑥1 = ⋯ = 𝑥𝑛 − 𝑥𝑛−1 = ℎ,
then the interpolating polynomial will be developed in terms of the forward (∆), backward (∇) and
central (𝛿)difference opertors. Use these operators permits reduction in computation compare with
Newton or Lagrange forms
The forward difference operator is (∆). ∆𝑓(𝑥) is termed the first forward difference, ∆2 𝑓(𝑥) the
second forward difference, etc. the forward difference can be computed and saved in forward
difference table in much the same manner as shown earlier for the divided differences
12
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
𝛼(𝛼 − 1) 2
𝑓2 (𝑥) = 𝑓(𝑥0 ) + 𝛼 ∆𝑓(𝑥0 ) + ∆ 𝑓(𝑥0 )
2!
1.5(0.5)
𝑓2 (1.5) = −5 + 6 (1.5) + (2) = 4.75
2!
1.6.2 Backward differences (Newton-Gregory backward)
The backward difference operator is (∇). ∇𝑓(𝑥) is termed the first backward difference, ∇2 𝑓(𝑥) the
second backward difference, etc.
𝑥𝑖 𝑓(𝑥𝑖 ) ∆𝑓(𝑥) ∆2 𝑓(𝑥) ∆3 𝑓(𝑥) ∆4 𝑓(𝑥)
0 −5
6
1 1 2
8 6
2 9 8 𝟎
16 𝟔
3 25 𝟏𝟒
𝟑𝟎
4 𝟓𝟓
A parameter α is defined as the origin base point 𝑥𝑛 so that
𝑥 = 𝑥𝑛 + 𝛼ℎ, − 𝑛 ≤ 𝛼 ≤ 0
𝛼(𝛼 + 1) 2 𝛼(𝛼 + 1)(𝛼 + 2) ⋯ (𝛼 + 𝑛 − 1) 𝑛
𝑓(𝑥) = 𝑓(𝑥𝑛 ) + 𝛼 ∇𝑓(𝑥𝑛 ) + ∇ 𝑓(𝑥𝑛 ) + ⋯ + ∇ 𝑓(𝑥𝑛 )
2! 𝑛!
This equation is known as Newton backward formula. Since Newton backward formula uses
differences along the lower diagonal of the difference table, it is most useful for interpolation near
the end of a set of tabulated values.
Example 7: Find the interpolated value predicted by third degree NBF for 𝑥 = 3.5
𝑥 − 𝑥𝑛 3.5 − 4
𝛼= = = −0.5
ℎ 1
𝛼(𝛼 + 1) 2 𝛼(𝛼 + 1)(𝛼 + 2) 3
𝑓3 (𝑥) = 𝑓(𝑥𝑛 ) + 𝛼 ∇𝑓(𝑥𝑛 ) + ∇ 𝑓(𝑥𝑛 ) + ∇ 𝑓(𝑥𝑛 )
2! 3!
𝛼(𝛼 + 1) 𝛼(𝛼 + 1)(𝛼 + 2)
𝑓3 (𝑥) = 55 + 30 𝛼 + (14) + (6)
2! 3!
13
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
𝑓3 (𝑥) = 55 + 30 𝛼 + 7𝛼 2 + 7𝛼 + 𝛼 3 + 3𝛼 2 + 2𝛼
𝑓3 (𝑥) = 55 + 39 (𝑥 − 4) + 10(𝑥 − 4)2 + (𝑥 − 4)3
𝑓3 (𝑥) = 55 + 39 𝑥 − 156 + 10𝑥 2 − 80𝑥 + 160 + 𝑥 3 − 8𝑥 2 + 16𝑥 − 4𝑥 2 + 32𝑥 − 64
𝑓3 (𝑥) = 𝑥 3 − 2𝑥 2 + 7𝑥 − 5
(0.5)(−0.5) (−0.5)(0.5)(1.5)
𝑓3 (3.5) = 55 + (−0.5)(30) + (14) + (6) = 37.875
2! 3!
The central difference table (entires are identical with the forward and backward difference tables
except for subscripts of the base points) then takes the form central difference table.
If the solid lines is taken, the formulation is termed the Gass forward formula by
ℎ
ℎ 𝑓(𝑥 0 ) 𝑓 (𝑥0 + 2)
𝑓(𝑥) = 𝑓(𝑥0 ) + 𝛼𝛿𝑓 (𝑥0 + ) + 𝛼(𝛼 − 1)𝛿 2 + 𝛼(𝛼 − 1)(𝛼 − 2)𝛿 3
2 2! 3!
𝑓(𝑥0 )
+ 𝛼(𝛼 − 1)(𝛼 − 2)(𝛼 − 3)𝛿 4
4!
𝑥 − 𝑥0
𝛼=
ℎ
14
Chemical and Petroleum Refining Engineering
Numerical Methods / 3rd stage
Example 8: Use the gauss forward formula and central difference to compute the interpolant value
for inpoation argument 𝑥 = 2.5
𝑥 − 𝑥0 2.5 − 2
𝛼= = = 0.5
ℎ 1
(0.5)(−0.5) (0.5)(−0.5)(−1.5)
𝑓3 (2.5) = 9 + (0.5)(16) + (8) + (6) = 16.375
2! 3!
Exercises 2:
1. Use an appropriate interpolation formula to estimate 𝑓(16.4) and 𝑓(23.5) from following data
𝑥 16 18 20 22 24
𝑓𝑥) 261.3 293.7 330 372.2 422.3
𝑥 21 25 29 33 37
𝑦 18.4708 17.8144 17.1070 16.3432 15.5154
15