lecture 4
lecture 4
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
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
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
1.386294 − 0
𝑓1 2 = 0 + 2−1 𝜀𝑡 = 33.3%
4−1
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.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
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 𝒙 − 𝒙𝒋
𝒇𝒏 (𝒙) = 𝑳𝒊 𝒙 𝒇(𝒙𝒊 ) 𝑳𝒊 (𝒙) ෑ
𝒙𝒊 − 𝒙𝒋
𝒊=𝟎 𝒋=𝟎
𝒋≠𝒊
𝑓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 )
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
21