CHE 358
Numerical Methods for
Chemical Engineers
M. MENSAH
Department of Chemical Engineering
KNUST
1
COURSE OUTLINE
• Modelling, Computers & Error Analysis.
• Linear Algebraic & Non-linear Equations.
• Finite difference methods and interpolation.
• Numerical differentiation and integration.
• Numerical solution of ordinary differential equations.
• Numerical solution of partial differential equations.
2
Learning objective
At the end of the lecture, students must be able to
estimate intermediate values between precise data
points using the Newton divided interpolating
method and the Lagrange interpolating method.
3
Interpolation
Numerical interpolation refers to the process of estimating the value of a
function at intermediate points between precise/known data points. 2 methods
will be discussed in this class:
1. Newton's divided difference method
2. Lagrange interpolating method
4
1. Newton's divided difference method
Linear interpolation
This is the simplest form of interpolation. It connects 2
data points with a straight line. This can be depicted
using similar triangles.
𝑓1 𝑥 − 𝑓(𝑥0 ) 𝑓 𝑥1 − 𝑓(𝑥0 )
=
𝑥 − 𝑥0 𝑥1 − 𝑥0
𝑓 𝑥1 − 𝑓 𝑥0
𝑓1 𝑥 = 𝑓 𝑥0 + 𝑥 − 𝑥0
𝑥1 − 𝑥0
𝑓1 𝑥 designates that this is a first order interpolating
polynomial.
5
Example:
Estimate In(2) using Newton's linear interpolation between
a. In(1)= 0 and ln(6)=1.791759
b. ln(1)=0 and ln(4)= 1.386294
Compare these values to the true value of In(2)=0.6931472
6
Soution:
Using
𝑓 𝑥1 − 𝑓 𝑥0
𝑓1 𝑥 = 𝑓 𝑥0 + 𝑥 − 𝑥0
𝑥1 − 𝑥0
a. 𝑥0 = 1; In(1)= 0 and 𝑥1 = 6; ln(6)=1.791759
1.791759 − 0
𝑓1 2 = 0 + 2 − 1 = 0.358352 𝜀𝑡 = 48.3%
6−1
b. 𝑥0 = 1; ln(1)=0 and 𝑥1 = 4; ln(4)= 1.386294
1.386294 − 0
𝑓1 2 = 0 + 2−1 𝜀𝑡 = 33.3%
4−1
Using a shorter interval reduces the percentage relative true error
7
Soution:
8
Quadratic interpolation
A strategy for improving the estimate is to introduce some curvature
into the line connecting the points. This can be accomplished with 3
data points to give:
𝒇𝟐 𝒙 = 𝒃𝟎 + 𝒃𝟏 𝒙 − 𝒙𝟎 +𝒃𝟐 𝒙 − 𝒙𝟎 𝒙 − 𝒙𝟏
A simple procedure can be used to evaluate the coefficients
When 𝑥 = 𝑥0 𝑏0 = 𝑓 𝑥0
𝑓 𝑥1 −𝑓 𝑥0
𝑥 = 𝑥1 𝑏1 =
𝑥1 −𝑥0
𝑓 𝑥2 −𝑓 𝑥1 𝑓 𝑥1 −𝑓 𝑥0
−
𝑥2 −𝑥1 𝑥1 −𝑥0
𝑥 = 𝑥2 𝑏2 =
𝑥2 −𝑥0 9
Example
By using Newton’s second order polynomial
interpolation, find the value of ln(2)
x f(x)=In(x)
1 0
4 1.386294
6 1.791759
10
Solution
𝑏0 = 0
1.386294 − 0
𝑏1 = = 0.462098
4−1
1.791759 − 1.386294 − 0.462098
𝑏2 = 6−4 = −0.0518731
6−1
𝑓2 ( 2 )=0 + 0.4620981 (2 − 1)− 0.051873 ( 2 − 1) (2 − 4)
𝑓2 ( 2 )= 0.565844
𝜀𝑡 = 18.4%
11
General form of Newton's interpolating polynomials
The preceding analysis can be generalized to fit the nth order
polynomial to n+1 data points. The nth –order polynomial is given by:
𝑓𝑛 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + ⋯ +𝑏𝑛 𝑥 − 𝑥0 𝑥 − 𝑥1 ⋯ 𝑥 − 𝑥𝑛−1
𝑏0 = 𝑓 𝑥0
𝑏1 = 𝑓[𝑥1 , 𝑥0 ]
𝑏2 = 𝑓[𝑥2 , 𝑥1 , 𝑥0 ]
⋮
𝑏𝑛 = 𝑓[𝑥𝑛 , 𝑥𝑛−1 … , 𝑥1 𝑥0 ]
12
Newton's interpolating polynomials
Graphical depiction of the recursive nature of finite divided differences
13
Example
By using a second order polynomial interpolation to the
following points, find the value of ln(2)
x f(x)=In(x)
1 0
4 1.386294
6 1.791759
5 1.609438
14
Solution
x f(x) first second third
1 0 0.462098 -0.05187 0.007865
4 1.386294 0.202733 -0.02041
6 1.791759 0.182321
5 1.609438
𝒇𝟑 𝒙 = 𝒃𝟎 + 𝒃𝟏 𝒙 − 𝒙𝟎 +𝒃𝟐 𝒙 − 𝒙𝟎 𝒙 − 𝒙𝟏 + 𝒃𝟑 𝒙 − 𝒙𝟎 𝒙 − 𝒙𝟏 𝒙 − 𝒙𝟐
The first row in the table gives the values of the constants bo, b1, b2 and b3 . Substitute
and complete the solution
15
Lagrange Interpolating Polynomials
The Lagrange interpolating polynomial is simply a reformulation of the
Newton’s polynomial that avoids the computation of divided differences:
𝒏
𝒏
where 𝒙 − 𝒙𝒋
𝒇𝒏 (𝒙) = 𝑳𝒊 𝒙 𝒇(𝒙𝒊 ) 𝑳𝒊 (𝒙) ෑ
𝒙𝒊 − 𝒙𝒋
𝒊=𝟎 𝒋=𝟎
𝒋≠𝒊
For Linear or first order interpolation, n=1
𝑓1(x)= 𝐿0𝑓(𝑥0) +𝐿1𝑓(𝑥1) 𝐿0 =
𝑥 − 𝑥1
𝐿1 =
𝑥 − 𝑥0
𝑥0 − 𝑥1 𝑥1 − 𝑥0
𝑥 − 𝑥1 𝑥 − 𝑥0
𝑓1(x)= 𝑓(𝑥0) + 𝑓(𝑥1)
𝑥0 − 𝑥1 𝑥1 − 𝑥0 16
Lagrange Interpolating Polynomials
• For 2nd order interpolation:
𝑓2 𝑥 = 𝐿0𝑓(𝑥0) +𝐿1𝑓(𝑥1)+𝐿2𝑓(𝑥2)
𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥0 𝑥 − 𝑥2 𝑥 − 𝑥0 𝑥 − 𝑥1
𝑓2 (𝑥) = 𝑓 𝑥0 + 𝑓 𝑥1 + 𝑓 𝑥2
(𝑥0 −𝑥1 )(𝑥0 −𝑥2 ) (𝑥1 −𝑥0 )(𝑥1 −𝑥2 ) (𝑥2 −𝑥0 )(𝑥2 −𝑥1 )
17
Example
Use Lagrange interpolating polynomial of the first and
second order to evaluate ln(2)
i x f(x)
0 1 0
1 4 1.386294
2 6 1.791759
18
Solution
• First order interpolating polynomial
𝑥 − 𝑥1 𝑥 − 𝑥0
𝑓1(x)= 𝑓(𝑥0) + 𝑓(𝑥1)
𝑥0 − 𝑥1 𝑥1 − 𝑥0
2−4 2−1
𝑓1(2)= 0+ 1.386294=0.462098
1−4 4−1
19
Solution
• Second order interpolating polynomial
𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥0 𝑥 − 𝑥2 𝑥 − 𝑥0 𝑥 − 𝑥1
𝑓2 (𝑥) = 𝑓 𝑥0 + 𝑓 𝑥1 + 𝑓 𝑥2
(𝑥0 −𝑥1 )(𝑥0 −𝑥2 ) (𝑥1 −𝑥0 )(𝑥1 −𝑥2 ) (𝑥2 −𝑥0 )(𝑥2 −𝑥1 )
2−4 2−4 2−1 2−6 2−1 2−4
𝑓2 2 = 0+ 1.386294 + 1.791760 = 0.565844
1−4 1−6 4−1 4−6 6−1 6−4
20
Try:
A batch reactor was charged with reactant A, at Time(t, min) Concentration
time t=0 at a concentration of 1.0mol/L. as the (CA, mol/L)
assumed first order reaction evolved, the
concentration were recorded over time. 0 1
The Dynamic balance for this system can be
shown to be 5 0.84
𝑑𝐶𝐴 (𝑡) 10 0.72
= −𝑘𝐶𝐴 (𝑡)
𝑑𝑡 30 0.47
Use a 2nd order Lagrange polynomial to 45 0.37
approximate CA(t) at time=20 mins 60 0.3
21