lecture #01...finite difference-based numerical methods in chemical engineering . recommended books:...

152
1 Lecture #01 Finite Difference-based Numerical Methods in Chemical Engineering Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application (Ferziger) 3) Linear Algebra (Strang) Objective: Learn a few basic numerical techniques (Finite Difference) to solve simple ODEs/PDEs/algebraic equations derived from a variety of heat and mass transfer related conservation equations. Analytical methods yield exact solutions, often in infinite series; use mathematical functions. Numerical methods yield approximate solutions; use numbers, computations; results are dependent on the method accuracies and limited by computers machine errors. Course focuses on Algebra (Matrix Operation) Methods (Finite Difference) Requires knowledge of Computer Programming (because large # of iterations) (there are engineering software, e.g., Matlab, NAG, IMSL, Polymath) No numerical analysis in this course! Examples: (Applications in chemical engineering) 1. Distillation: 1 1 2 −1 +1 Trays +1 Assume: Constant molar flowrates of vapor & liquid. Binary components: A, B (more volatile) Species balance on plate:

Upload: others

Post on 26-Mar-2021

24 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #01

Finite Difference-based Numerical Methods in Chemical Engineering

Recommended Books:

1) Numerical Methods for Engineers (SKG)

2) Numerical Methods for Engineering Application (Ferziger)

3) Linear Algebra (Strang)

Objective: Learn a few basic numerical techniques (Finite Difference) to solve simple

ODEs/PDEs/algebraic equations derived from a variety of heat and mass transfer related

conservation equations.

Analytical methods yield exact solutions, often in infinite series; use mathematical functions.

Numerical methods yield approximate solutions; use numbers, computations; results are dependent

on the method accuracies and limited by computers machine errors.

Course focuses on

Algebra (Matrix Operation)

Methods (Finite Difference)

Requires knowledge of

Computer Programming (because large # of iterations)

(there are engineering software, e.g., Matlab, NAG, IMSL, Polymath)

No numerical analysis in this course!

Examples: (Applications in chemical engineering)

1. Distillation:

𝑉1 𝐿𝑜

1

2

𝑖 − 1 𝑒𝑞𝑢𝑖𝑙𝑖𝑏𝑟𝑖𝑢𝑚 𝑖 𝑖 𝑖 𝑖 + 1

𝑁

Trays 𝑉𝑁+1 𝐿𝑁

Assume: Constant molar flowrates of vapor & liquid.

Binary components: A, B

(more volatile)

Species balance on 𝒊𝒕𝒉 plate:

Page 2: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

𝐿𝑖 = 𝑥𝑖 𝐿 𝑉𝑖 = 𝑦𝑖 𝑉 𝑦𝑖 = 𝑘𝑖𝑥𝑖 (𝑒𝑞𝑢𝑖𝑙𝑖𝑏𝑟𝑖𝑢𝑚)

Therefore, 𝑉𝑖 = (𝑦𝑖

𝑥𝑖) (

𝑉

𝐿)𝐿𝑖

or 𝑉𝑖 = 𝐴𝑖′𝐿𝑖

And, 𝑉𝑖 + 𝐿𝑖 = 𝑉𝑖+1 + 𝐿𝑖−1 (𝑖𝑛 = 𝑜𝑢𝑡)

𝑉𝑖 ↓ 𝑙𝑖−1

𝑉𝑖+1 ↓ 𝑙𝑖 ⋯ 𝑖𝑡ℎ 𝑝𝑙𝑎𝑡𝑒

𝑉𝑖 + 𝑉𝑖 𝐴𝑖′⁄ −

𝑉𝑖−1

𝐴𝑖−1′ − 𝑉𝑖+1 = 0

Re-arrange 𝐴𝑖−1𝑉𝑖−1 + (1 − 𝐴𝑖)𝑉𝑖 − 𝑉𝑖+1 = 0

𝑖 = 1,𝑁

Thus, there are ‘N’ equations and (N+2) variables (𝑉𝑜 ⋯⋯𝑉𝑁+1)

However, 𝑉𝑁+1 𝑎𝑛𝑑 𝐿𝑜 are known (inlet or boundary conditions)

Re-arrange for all trays 𝑖 = 1,𝑁

(1 − 𝐴1)𝑉1 − 𝑉2 = −𝐴𝑜𝑉𝑜(= 𝐿𝑜) (𝑘𝑛𝑜𝑤𝑛)

𝐴1𝑉1 + ( 1 − 𝐴2)𝑉2 − 𝑉3 = 0 (1)

𝐴𝑁−1𝑉𝑁−1 + ( 1 − 𝐴𝑁+1)𝑉𝑁 = 𝑉𝑁+1 (𝑘𝑛𝑜𝑤𝑛) (𝑁)

We have a set of algebraic equations (linear/non-linear) represented as

𝐴�� = ��

coefficient matrix column vectors or (𝑁 × 1) 𝑚𝑎𝑡𝑟𝑖𝑥

rows column

𝐴 =

[ ( 1 − 𝐴1) −1 0 0 0 0

𝐴1 ( 1 − 𝐴2) −1 0 0 00 𝐴2 (1 − 𝐴3) −1 0 00 0 0 0 𝐴𝑁−1 (1 − 𝐴𝑁+1)]

𝑁×𝑁

rows columns

Page 3: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

�� = {

𝑉1

𝑉2

⋮𝑉𝑁

} , �� = {

𝐿0

⋮⋮

𝑉𝑁+1

} (Known)

column vectors

Alternatively*,

[ ( 1 − 𝐴1) −1 0 0 0 0( 1 − 𝐴1) −1 0 0 0 0

𝐴1 ( 1 − 𝐴2) −1 0 0 0⋮ ⋮ ⋮ ⋮ ⋮ ⋮0 0 0 0 𝐴𝑁−1 (1 − 𝐴𝑁+1)]

𝑁×𝑁

[

𝑉1

𝑉2

⋮𝑉𝑁

]

𝑁×1

= [

𝐿𝑜

⋮𝑉𝑁+1

]

𝑁×1

∗ represented as matrix multiplication

Note:

o Most of the finite difference methods lead to the discretization of ODEs/PDEs and a set

of algebraic equations.

o You have to solve a set of algebraic equations using Gauss Elimination, G-Jordan etc.

Example 2: Particle settling

(𝑑𝑝, 𝜌𝑝 , 𝑣𝑝, 𝐴𝑝, 𝑚𝑝)

𝑔

𝐻 𝑙𝑖𝑞𝑢𝑖𝑑/𝑔𝑎𝑠

𝑡 =?

(𝜌𝑓 , 𝑣𝑓)

Force balance on the particle:

𝑚𝑝𝑑𝑣

𝑑𝑡= 𝑚𝑝𝑔 − 𝑣𝑝𝜌𝑓𝑔 − 𝐶𝐷 (

1

2𝜌𝑓𝑣

2)𝐴𝑝

𝑤𝑒𝑖𝑔ℎ𝑡 𝑏𝑢𝑜𝑦𝑎𝑛𝑐𝑦 𝑑𝑟𝑎𝑔

𝑑𝑣

𝑑𝑡= 𝑔 −

𝜌𝑓

𝜌𝑝𝑔 − 𝐶𝐷 (

1

2𝜌𝑓𝑣

2) (𝜋𝑑𝑝2

4)

Page 4: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

𝑑𝑣

𝑑𝑡= 𝐴 − 𝐵𝐶𝐷(𝑣)𝑣2 𝐶𝐷 24 𝑅𝑒 ,⁄ 𝑝

= 𝐴 − 𝐵Φ(𝑣) 0.44

𝑡 = 0, 𝑣 = 0 𝑅𝑒 , 𝑝

Therefore, you have to solve an initial value problem (ODE)

Solution: linear or non-linear

𝑣𝑡 homogeneous or non-homogeneous

or a set of ODEs.

v Methods: RK-4, Euler Forward, etc.

0 t

Example 3: Heating or cooling of a moving particle (𝛁𝑻(𝒓) = 𝟎)

𝑡 = 0 𝑣𝑝 = 0

𝑇 𝑇𝑓 𝑇 = 𝑇𝑜 > 𝑇𝑓(𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡)

𝑟𝑝 ℎ𝑓 (𝑓𝑙𝑢𝑖𝑑 𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒)

𝑇(𝑡) =? (𝑐𝑜𝑛𝑣𝑒𝑐𝑡𝑖𝑣𝑒 ℎ𝑒𝑎𝑡 𝑡𝑟𝑎𝑛𝑠𝑓𝑒𝑟 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡)

Assume/ Apply lump body approach (𝑩𝒊 → 𝟎)

1. Energy balance over entire particle ℎ𝑑𝑝

𝑘𝑝→ 0 , 𝑘𝑝 >> ℎ𝑑𝑝

𝑚𝐶𝑝𝑑𝑇

𝑑𝑡= −ℎ𝐴𝑠(𝑇 − 𝑇𝑓)

(𝐴𝑠 = 𝜋𝑑𝑝2)

(𝑁𝑜 𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒 𝑔𝑟𝑎𝑑𝑖𝑒𝑛𝑡 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑝𝑎𝑟𝑡𝑖𝑐𝑙𝑒)

ℎ = ℎ(𝑁𝑢) ⇒ ℎ𝑑𝑝

𝑘𝑓= 𝑓(𝑅𝑒,𝑝,𝑃𝑟)

𝑜𝑟 ℎ = ℎ (𝑣𝑝 ); 𝑅𝑒 = 𝑣1𝑑𝑝𝜌𝑓

𝜇𝑓, 𝑃𝑟 = (

𝐶𝑝𝜇

𝑘)𝑓

2 Time-dependence of velocity (see previous example) and energy balance equation can be

written as

Page 5: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

𝑑𝑣𝑝

𝑑𝑡= 𝐴 − 𝐵Φ(𝑣𝑝)

𝑑𝑇𝑑𝑡

= 𝐶 𝐷(𝑣𝑝) − 𝐸} 𝑡 = 0 𝑣𝑝 = 0, 𝑇 = 𝑇𝑜Type equation here.

In this example, two ODEs are to be solved; first y1 and then y2.

𝑑𝑦1

𝑑𝑡= 𝑓(𝑦1)

𝑑𝑦2

𝑑𝑡= Φ(𝑦1, 𝑦2)

} 𝑇𝑤𝑜 𝑂𝐷𝐸𝑠

Example 4: Heating or cooling of a stationary solid (𝛁𝑻 ≠ 𝟎) in a moving fluid

𝑡 = 0 𝑇 = 𝑇𝑜 > 𝑇𝑓(𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡)

𝑇𝑜 𝑓𝑙𝑢𝑖𝑑 𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒

𝑟

𝑇(𝑡, 𝑟) =? 𝑟𝑝 𝑇𝑓

ℎ𝑓(𝑐𝑜𝑛𝑣𝑒𝑐𝑡𝑖𝑣𝑒 ℎ𝑒𝑎𝑡 𝑡𝑟𝑎𝑛𝑠𝑓𝑒𝑟 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡)

Assume ∇𝑇(𝑟) = 0, 𝑖. 𝑒. , 𝑡ℎ𝑒𝑟𝑒 𝑖𝑠 𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒 𝑔𝑟𝑎𝑑𝑖𝑒𝑛𝑡 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑝𝑎𝑟𝑡𝑖𝑐𝑙𝑒

Energy balance within the particle:

𝜌𝐶𝑝𝜕𝑇

𝜕𝑡=

𝑘

𝑟2

𝜕

𝜕𝑟(𝑟2 𝜕𝑇

𝜕𝑟)

𝑡 = 0 𝑇 = 𝑇𝑜 𝑟𝑝 ≥ 𝑟 ≥ 0 (𝐼𝑛𝑖𝑡𝑖𝑎𝑙 𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛)

= 0+ 𝑟 = 0 𝜕𝑇

𝜕𝑟= 0 (𝐵𝑜𝑢𝑛𝑑𝑎𝑟𝑦 𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛𝑠)

𝑟 = 𝑟𝑝, − 𝑘𝜕𝑇

𝜕𝑟= ℎ(𝑇 − 𝑇𝑓)

Now, we have to solve a PDE equation (unsteady – state 1D on space-problem)

Under the steady-state condition with/without a source term, the equation will be

reduced to a 2nd order ODE or a boundary value problem.

Page 6: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

Example 5: Mass transfer in a tubular liquid flow (steady- state)

𝐶𝐴 = 𝐶𝑖𝑛 𝑅

𝑟 (𝑤𝑎𝑡𝑒𝑟 − 𝑓𝑙𝑜𝑤) 𝑣𝑧(𝑟)

𝑡 = 0 z

tube length = L

For 𝑅𝑒 < 2100

𝑣𝑧(𝑟) = 2𝑣𝑜(1 −𝑟2

𝑅2)

𝑐(𝑡, 𝑧, 𝑟) =?

Species (A) balance in the CV (2𝜋𝑟 ∆𝑧 ∆𝑟)

CV

𝜕𝐶𝐴

𝜕𝑡+ 𝑣𝑧. ∇𝐶𝐴 = 𝐷∇2𝐶𝐴 + 𝑟(= 0)

(no reaction)

𝜕𝐶𝐴

𝜕𝑡+ 2𝑣𝑜 (1 −

𝑟2

𝑅2)𝜕𝐶𝐴

𝜕𝑧+ 𝑣𝑟

𝜕𝐶𝐴

𝜕𝑟= 𝐷 (

𝜕𝐶𝐴

𝜕𝑧2+

1

𝑟

𝜕

𝜕𝑟(𝑟

𝜕𝐶𝐴

𝜕𝑟))

𝑡 = 0 , 𝐶𝐴 = 0 𝑒𝑣𝑒𝑟𝑦𝑤ℎ𝑒𝑟𝑒

0+ 𝑧 = 0 𝐶𝐴 = 𝐶𝑖𝑛

𝑧 = 𝐿 𝜕𝐶𝐴

𝜕𝑧= 0 (𝑙𝑜𝑛𝑔 𝑡𝑢𝑏𝑒 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛)

𝑟 = 0 , 𝜕𝐶𝐴

𝜕𝑟= 0 (𝑠𝑦𝑚𝑚𝑒𝑡𝑟𝑖𝑐)

= 𝑅 − 𝜕𝐶𝐴

𝜕𝑟= 0 (𝑛𝑜𝑛 − 𝑟𝑒𝑎𝑐𝑡𝑖𝑣𝑒 𝑤𝑎𝑙𝑙)

In this example, we have a transient/unsteady-state 2D (space) problem or a PDE to solve.

Under the steady-state condition with/without a source term, the equation will be

reduced to an elliptic PDE or 2nd order (in both z and r) PDE.

Page 7: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #02

Linear Algebraic Equations

𝑓1(𝑋1, 𝑋2, ⋯⋯𝑋𝑛) = 0𝑓2(𝑋1, 𝑋2, ⋯⋯𝑋𝑛) = 0⋮

𝑓𝑛(𝑋1, 𝑋2,⋯⋯𝑋𝑛) = 0

} system of 𝑛 linear algebraic equations

or

𝑎11𝑋1 + 𝑎12𝑋2 +⋯⋯+ 𝑎1𝑛𝑋𝑛 = 𝑏1

𝑟𝑜𝑤 𝑐𝑜𝑙𝑢𝑚𝑛 𝑎21𝑋1 + 𝑎22𝑋2 +⋯⋯+ 𝑎2𝑛𝑋𝑛 = 𝑏2⋮

𝑎𝑛1𝑋1 + 𝑎𝑛2𝑋2 +⋯⋯+ 𝑎𝑛𝑛𝑋𝑛 = 𝑏𝑛 }

𝑛 # 𝑜𝑓 𝑖𝑛𝑑𝑒𝑝𝑒𝑛𝑑𝑒𝑛𝑡 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛𝑠 𝑡𝑜 𝑠𝑜𝑙𝑣𝑒 𝑛 # 𝑜𝑓𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠

or 𝐴𝑋 = 𝑏 𝐴�� = ��

𝑤ℎ𝑒𝑟𝑒 𝐴 = 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡 𝑚𝑎𝑡𝑟𝑖𝑥

= [

𝑎11 𝑎12 ⋯ 𝑎1𝑛𝑎21 𝑎22 ⋯ 𝑎2𝑛⋮ ⋮ ⋮ ⋮𝑎𝑛1 𝑎𝑛2 ⋯ 𝑎𝑛𝑛

]

𝒏×𝒏

(𝑎𝑖𝑗 𝑖𝑠 𝑎 𝑔𝑒𝑛𝑒𝑟𝑎𝑙 𝑒𝑙𝑒𝑚𝑒𝑛𝑡; 𝑖, 𝑗 = 1 𝑡𝑜 𝑛)

row column

𝑋 = 𝑚𝑎𝑡𝑟𝑖𝑥 = [

𝑋1𝑋2⋮𝑋𝑛

]

𝑛×1

𝑏 = 𝑚𝑎𝑡𝑟𝑖𝑥 = [

𝑏1𝑏2⋮𝑏𝑛

]

𝑛×1

or,

�� = 𝑐𝑜𝑙𝑢𝑚𝑛 𝑣𝑒𝑐𝑡𝑜𝑟 = {

𝑋1𝑋2⋮𝑋𝑛

} , �� = 𝑐𝑜𝑙𝑢𝑚𝑛 𝑣𝑒𝑐𝑡𝑜𝑟 = {

𝑏1𝑏2⋮𝑏𝑛

}

Page 8: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

{

Note: In general, a matrix has 𝑛 × 𝑚 elements

Therefore, aij: i = 1 to n

j = 1 to mIf n = m, there may be unique solution and the rank of the matrix = m

In general, rank >,=,< m (3 cases)(For more, refer a book on matrix operation)

In this course,we will be interested in solving number of equations with as many variables:

3x + 2y = 5x − y = 6

} or 3x + 2y + z = 5x + y − z = 2

2x + 2y − 2z = 4} etc.

Some properties of a matrix and operation

(1) Symmetric matrix, 𝑎𝑖𝑗 = 𝑎𝑗𝑖

Square matrix, n = m

Diagonal matrix, [⋱ 00 ⋱

] (𝑜𝑛𝑙𝑦 𝑑𝑖𝑎𝑔𝑜𝑛𝑎𝑙 𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠)

Banded matrix (tridiagonal)

[ 𝑎11 𝑎12 0 0 ⋯ 0𝑎21 𝑎22 𝑎23 0 ⋯ 00 𝑎32 𝑎33 𝑎34 ⋯ 0⋮ ⋮ ⋮ ⋮ ⋮ ⋮0 0 0 0 𝑎𝑛𝑛−1 𝑎𝑛𝑛]

𝑛×𝑛 𝑚𝑎𝑡𝑟𝑖𝑥

(First and last rows have only two elements and all other rows have 3 elements, one on

the diagonal and the other two on each side of the diagonal element)

Upper/Lower triangular matrix:

(All elements below and above the diagonal are zero, respectively)

UTM:

[ 𝑎11 𝑎12 𝑎13 ⋯ 𝑎1𝑛

𝑎22 𝑎23 ⋯ 𝑎2𝑛⋱ ⋱ ⋮

𝟎 ⋱ 𝑎𝑛−1𝑛𝑎𝑛𝑛 ]

𝒏×𝒏

LTM:

[ 𝑎11𝑎21 𝑎22𝑎31 𝑎32 ⋱ 𝟎

⋮ ⋮ ⋱ ⋱𝑎𝑛1 𝑎𝑛2 ⋯ 𝑎𝑛𝑛−1 𝑎𝑛𝑛]

𝒏×𝒏

(2) Operation:

Summation: [𝐴]𝑚×𝑛 = [𝐵]𝑚×𝑛 + [𝐶]𝑚×𝑛

Page 9: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

Multiplication (rules):

[𝐴]𝑚×𝑛 × [𝐵]𝑛×𝑙 = [𝐶]𝑚×𝑙

same

Therefore, multiplication is not permissible for [𝐵] × [𝐴]

{

𝑛 × 𝑙 𝑚 × 𝑛

𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑡𝑙 ≠ 𝑚

Also, these multiplications are permissible

[5 13 20 3

]

3×2

× [−3 01 0

]2×2

; [5 13 20 3

]

3×2

× [−4 −3 22 7 −3

]2×3

; [1 3 2]1×3 × [05−8]

3×1

Rule: 𝑪𝒊𝒋 = ∑ 𝒂𝒊𝒌 × 𝒃𝒌𝒋𝒌𝒍=𝟏

examples: [3 18 60 4

]

3×2

× [5 67 2

]2×2

= [

(3 × 5 + 1 × 7) 3 × 6 + 1 × 2(8 × 5 + 6 × 7) (8 × 6 + 6 × 2)0 × 5 + 4 × 7) (0 × 6 + 4 × 2

]

3×2

Inverse of a matrix:

[𝐴]−1 ⇒ [𝐴]𝑚×𝑛 × [𝐴 ]𝑛×𝑚−1 = [𝐼] ≡ [

1 0 00 1 00 0 1

]

Identity matrix

For 𝟐 × 𝟐 matrix

[𝐴]−1 =1

|𝐴|[𝑎22 −𝑎12−𝑎21 𝑎11

] 𝑤ℎ𝑒𝑟𝑒 𝐴 = [𝑎11 𝑎12𝑎21 𝑎22

]

Note: |𝐴| = (𝑎11 × 𝑎22 − 𝑎12 × 𝑎21) ≠ 0

else, matrix A is considered to be singular.

For bigger size matrices, there are special methods to determine[𝐴]−1, discussed later.

Transpose of a matrix [𝑨]𝑻:

[𝐴] = [𝑎11 𝑎12 ⋯ 𝑎1𝑛𝑎𝑚1 𝑎𝑚2 ⋯ 𝑎𝑚𝑛

], [𝐴]𝑇 = [𝑎11 𝑎21 ⋯ 𝑎𝑚1𝑎1𝑛 ⋯ ⋯ 𝑎𝑚𝑛

]𝑛×𝑚

(rows have been interchanged with columns)

Page 10: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

example: [𝐴] = [

𝑎1𝑎2⋮𝑎𝑛

]

𝑛×1

⇒ [𝐴]𝑇 = [𝑎1 𝑎2 ⋯ 𝑎𝑛]1×𝑛

Let us get back to solving a set of algebraic equations:

[𝐴]{𝑋} = {𝑏}

𝑜𝑟 [𝐴][𝑋] = [𝑏]

𝑜𝑟 𝐴�� = ��

} 𝑏𝑇 = [𝑏1 𝑏2⋯⋯𝑏𝑛], 𝑋𝑇 = [𝑋1 𝑋2⋯⋯𝑋𝑛]

𝑿 = 𝑨−𝟏𝒃

⇒ {

𝐹𝑖𝑛𝑑𝑖𝑛𝑔 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛 𝑡𝑜 𝑡ℎ𝑒 𝑠𝑒𝑡 𝑜𝑓 𝑙𝑖𝑛𝑒𝑎𝑟 𝑎𝑙𝑔𝑒𝑏𝑟𝑎𝑖𝑐 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 𝑖𝑠 𝑛𝑜𝑡ℎ𝑖𝑛𝑔 𝑏𝑢𝑡 𝑓𝑖𝑛𝑑𝑖𝑛𝑔 𝑖𝑛𝑣𝑒𝑟𝑠𝑒 𝑜𝑓 𝑡ℎ𝑒 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡 𝑚𝑎𝑡𝑟𝑖𝑥, 𝑓𝑜𝑙𝑙𝑜𝑤𝑒𝑑 𝑏𝑦

𝑚𝑢𝑙𝑡𝑖𝑝𝑙𝑖𝑐𝑎𝑡𝑖𝑜𝑛 𝑤𝑖𝑡ℎ 𝒃.

Generally, Cremer’s rule works nicely for small matrix:

𝑿𝒋 =|𝑨𝒋|

|𝑨|

𝐴𝑗 is determined by replacing 𝑗𝑡ℎ column of A by b.

Therefore, if 𝐴 = [3 5 72 0 8−1 2 5

] ; 𝑏 = {732}

𝑋2 = [3 7 72 3 8−1 2 5

] |𝐴|⁄ ; |𝐴| ≠ 0

𝑋3 = [3 5 72 0 3−1 2 2

] |𝐴|⁄ , 𝑒𝑡𝑐.

Let us briefly discuss unique solution, singularity, and rank (r) of a (𝑚 × 𝑛) matrix. (Read the

textbook for details)

Consider the following set of equations:

(1) 2𝑥1 + 3𝑥2 = 11

4𝑥1 + 6𝑥2 = 22

Note: Two equations are not independent.

and |𝐴| = [2 34 6

]2×2

= 0

Page 11: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

Therefore, there is no unique solution, coefficient matrix is singular and 𝑟 of such matrix =

1 < 2 𝑜𝑟 𝑚(# 𝑜𝑓 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛𝑠) < 𝑛(# 𝑜𝑓 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠)

(2) 2𝑥1 + 3𝑥2 = 11

𝑥1 + 𝑥2 = 4

Note: Two equations are independent.

|𝐴| = [2 31 1

]2×2

≠ 0; 𝑎𝑛𝑑 𝑚 = 𝑛, 𝑟 = 2(𝑛)

There is a unique solution.

Geometrically, two equations represent two straight lines intersecting at a unique point.

Similarly, 3 independent equations for 𝑋2

3 variables will represent 3 planes on a ⇒

geometrical space; two planes intersecting

will yield a straight line, and two straight lines 𝑋1

intersecting will yield a point (𝑋1, 𝑋2, 𝑋3), or the unique solution to the equations.

(3) 2𝑥1 + 3𝑥2 − 𝑥3 = 11

𝑥1 + 𝑥2 + 𝑥3 = 4

𝑥1 + 2𝑥2 + 2𝑥3 = 7

Note: There are three linearly independent equations representing three non-parallel

equations. In this case, m = 𝑛, 𝑟 = 3(𝑛).

Page 12: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #03

Gauss Elimination

It is the most widely used method to solve a set of linear algebraic equations. The method

reduces the original matrix to an upper triangular matrix which can also be used to determine

the determinant of the matrix. Interestingly, one can also inspect the intermediate

steps/solutions to determine singularity, rank, and number of independent equations.

General steps: 𝐴�� = �� 𝑤ℎ𝑒𝑟𝑒 𝐴 𝑖𝑠 𝑎 3 × 3 𝑚𝑎𝑡𝑟𝑖𝑥

𝑎11𝑥1 + 𝑎12𝑥2 + 𝑎13𝑥3 = 𝑏1 ⋯⋯⋯𝑅1

𝑎21𝑥1 + 𝑎22𝑥2 + 𝑎23𝑥3 = 𝑏2 ⋯⋯⋯𝑅2

𝑎31𝑥1 + 𝑎32𝑥2 + 𝑎33𝑥3 = 𝑏3 ⋯⋯⋯𝑅3

or [

𝑎11 𝑎12 𝑎13𝑎21 𝑎22 𝑎23𝑎31 𝑎32 𝑎33

] {

𝑥1𝑥2𝑥3} = {

𝑏1𝑏2𝑏3

}

𝑅1, first row is called pivot row and first non-zero element (𝑎11) is called pivotal element.

Subsequent operations are performed around pivot row and pivotal element.

Step 1: [

𝑎11 𝑎12 𝑎130 𝑎22

′ 𝑎23′

0 𝑎32′ 𝑎33

′] {

𝑥1𝑥2𝑥3} = {

𝑏1𝑏2′

𝑏3′}

where

𝑎22′ = 𝑎22 − (

𝑎21

𝑎11) × 𝑎12

𝑎23′ = 𝑎23 − (

𝑎21

𝑎11) × 𝑎13

𝑏2′ = 𝑏2 − (

𝑎21

𝑎11) × 𝑏1 }

(2)

Briefly, the first equation is divided by a11, multiplied by a21, and substractedfrom the second equation to yield the

modified equation (2)

𝑎11 ≠ 0

Similarly,

𝑎32′ = 𝑎32 − (

𝑎31

𝑎11) × 𝑎12

𝑎33′ = 𝑎33 − (

𝑎31

𝑎11) × 𝑎13

𝑏3′ = 𝑏3 − (

𝑎31

𝑎11) × 𝑏1 }

(3)

Briefly, the first equation is divided by a11, multiplied by a31, and substracted

from the 3rd equation to yield the modified equation (3)

or, in the simplest form 𝑅2′ = 𝑅2 − 𝑅1 (

𝑎21

𝑎11)

Page 13: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

𝑅3′ = 𝑅3 − 𝑅1 (

𝑎31

𝑎11)

Note: Multiplication or division of an equation, or subtraction or addition of one independent

equation from/to another independent equation does not yield a new independent equation.

Therefore, at the end of step 1 we still have three linearly independent equations, although

modified, to solve.

Geometrically, two planes (non-parallel) will intersect to yield a straight line. Therefore, step1

has yielded two straight lines by the intersections of plane/(eq 1) with plane 2 (eq 2) and with

plane 3 (eq 3).

Step2: Follow the similar procedure. Now 𝑅2′(2nd row) becomes pivotal equation and

𝑎22′ becomes pivotal element.

[

𝑎11 𝑎12 𝑎130 𝑎22

′ 𝑎23′

0 0 𝑎33′′] {

𝑥1𝑥2𝑥3} = {

𝑏1𝑏2′

𝑏3′′}

where,

𝑎33′′ = 𝑎33

′ − (𝑎32

𝑎22′) × 𝑎23

𝑏3′′ = 𝑏3

′ − (𝑎32

𝑎22′) × 𝑏2

or in the simplest form, 𝑅3′′ = 𝑅3

′ − 𝑅2′ (𝑎32

𝑎22′)

Geometrically, two straight lines (𝑅2′ 𝑎𝑛𝑑 𝑅3

′) intersect at a point.

Note: At the end of step (2) an upper triangular matrix is obtained. The three modified

algebraic equations are as follows:

𝑎11𝑥1 + 𝑎12𝑥2 + 𝑎13𝑥3 = 𝑏1 𝑎22

′𝑥2 + 𝑎23′𝑥3 = 𝑏2

𝑎33′′𝑥3 = 𝑏33

′′}

This is a new set of three linearly independent algebraic equations to solve! Here ‘new’ means

‘modified’.

Page 14: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

Reverse (back) substitution (to determine��):

𝑥3 = 𝑏3′′ 𝑎33

′′⁄ (from the last row)

𝑥2 =𝑏2′−𝑎23

′𝑥3

𝑎22′ (from the 2nd last row)

𝑥1 =𝑏1−𝑎12𝑥2−𝑎13𝑥3

𝑎11 (from the 1st row)

In general, for the ith variable of ‘n’ equations

𝑥𝑖 =𝑏𝑖(𝑖−1)

− ∑ 𝑎𝑖𝑗(𝑖−1)

𝑥𝑗𝑛 𝑗=𝑖+1

𝑎𝑖𝑖(𝑖−1)

A large number of equations (𝑛 > 3) requires a programming code to solve.

Evaluation of determinant:

Consider a simple 2 × 2 matrix

𝐴 = [𝑎11 𝑎12𝑎21 𝑎22

]2×2

⇒ 𝑑𝑒𝑡𝐴 = (𝑎11 × 𝑎22 − 𝑎21 × 𝑎12)

Apply GE method

𝐴′ = [𝑎11 𝑎120 𝑎22

′]2×2 ; 𝑎22

′ = (𝑎22 − (𝑎21

𝑎11) × 𝑎12)

The determinant of the modified matrix 𝐴′ = (𝑎11 × 𝑎22 − 𝑎21 × 𝑎12) = 𝑠𝑎𝑚𝑒 𝑎𝑠 det (𝐴)

“Value of determinant is not changed by the forward elimination step of GE”. This must be

true because forward step only modifies the equations.

Take 3 × 3 matrix:

[

𝑎11 𝑎12 𝑎13𝑎21 𝑎22 𝑎23𝑎31 𝑎32 𝑎33

]𝐺𝐸⇒ [

𝑎11 𝑎12 𝑎130 𝑎22

′ 𝑎23′

0 0 𝑎33′′]

[𝐴] [𝐴′]

𝑑𝑒𝑡[𝐴] = 𝑑𝑒𝑡[𝐴′] = 𝑎11𝑎22′𝑎33

′′ (can be checked)

Therefore,

𝑑𝑒𝑡[𝐴] ⇒ 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 𝑜𝑓 𝑡ℎ𝑒 𝑑𝑖𝑎𝑔𝑜𝑛𝑎𝑙 𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠 𝑜𝑓 𝑖𝑡𝑠 𝑢𝑝𝑝𝑒𝑟 𝑡𝑟𝑖𝑎𝑛𝑔𝑢𝑙𝑎𝑟 𝑚𝑎𝑡𝑟𝑖𝑥

Page 15: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Note that swapping of rows of a matrix does not alter values of determinant. However, sign

changes: (−1)𝑘, where k is the number of times rows are swapped.

Re-visit

𝑑𝑒𝑡[𝐴]3×3 = 𝑎11𝑎22′𝑎33

′′ (𝑝𝑟𝑜𝑑𝑢𝑐𝑡 𝑜𝑓 𝑡ℎ𝑒 𝑑𝑖𝑎𝑔𝑜𝑛𝑎𝑙 𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠 𝑜𝑓 𝑈𝑇𝑀 𝑜𝑓 𝐴)

Note: 1. For a matrix to be non-singular 𝑑𝑒𝑡[𝐴] ≠ 0

𝑜𝑟 𝑎11𝑎22′𝑎33

′′ ≠ 0

Alternatively, the corresponding three equations are linearly independent; rank of

[𝐴] = #𝑜𝑓 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 = #𝑜𝑓 𝑒𝑞𝑛𝑠 = 3.

Geometrically, three planes intersect at a unique point in space, or none of them is ∥ to the

other.

Alternatively,

If a33′′ = 0, det[A] = 0 ⇒ the matrix is singular; rank of the matrix = 2(< 3); only first

two equations are linearly independent; the problem is under-determined and one more

equation is required to solve(𝑥1, 𝑥2, 𝑥3). Algebraically, 3rd plane is ∥ to one of the other two

planes.

Pivoting and ill-conditioning:

𝐴�� = �� ⇒ �� = 𝐴−1�� ; 𝐴−1 =𝐴𝑑𝑗|𝐴|

|𝐴|

Therefore, for �� to be solved or A to be invertible, |𝐴| ≠ 0. Yet if |𝐴| →

0 (𝑜𝑟 𝑖𝑡 𝑖𝑠 𝑎 𝑠𝑚𝑎𝑙𝑙 𝑛𝑢𝑚𝑏𝑒𝑟), a small change in |𝐴| will lead to a large change in 𝐴−1.

[Note: 𝑌 = 1 𝑋⁄ , 𝑑𝑌

𝑑𝑋= −

1

𝑋2

In other words, a small change in X will lead to large change in Y]

In such case, the problem is said to be ill-conditioned. To invert such a matrix, large machine

precision may be required, and one has to be careful with round-off errors.

Recall, determinant of a matrix is the product of the diagonal elements of UTM. Therefore,

pivotal elements should not only be zero, but also large, or the matrix should be “diagonally

strong”.

Page 16: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

Example: 0.0001𝑥1 + 𝑥2 = 1 (𝐴)

𝑥1 + 𝑥2 = 2

Working with 4th decimal, apply GE with 0.0001 as the pivotal element to obtain

𝑋𝑇 = [0.0000 1.0000] which is wrong. Now, swap the equations as

𝑥1 + 𝑥2 = 2

0.0001𝑥1 + 𝑥2 = 1

Apply GE to obtain 𝑥𝑇 = [1.0000 1.0000] which is 4th decimal accurate.

This is called pivoting. Swap the row, so that the pivotal element is relatively larger. Also,

scaling (or multiplying equation (A) by 10000) can be done before applying GE.

Example: Solve by GE:

[1 −1 22 −2 31 1 1

] {

𝑥1𝑥2𝑥3} = {

−8−20−2}

Step 1: [1 −1 20 0 −10 2 −1

] {

𝑥1𝑥2𝑥3} = {

−8−4+6}

Row pivoting is required (or swap 2nd equation with 3rd so that pivotal elemental is non – zero).

[1 −1 20 2 −10 0 −1

] {

𝑥1𝑥2𝑥3} = {

−8+6−4}

We have now UTM. Reverse substitution will yield

𝑥𝑇 = [−11 5 4]

(a) 𝑑𝑒𝑡[𝐴] = −1 × 2 × −1 = 2 ≠ 0 (matrix is singular, rank = 3, all 3 equations are

linearly independent ). Also, note that we swapped one time. So, there is the

multiplication with -1.

Column pivoting (generally it should be avoided)

[1 2 −10 −1 00 −1 2

] {

𝑥1𝑥2𝑥3} = {

−8−4+6}

Page 17: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

Column 2 is replaced with column 3 to make the pivotal element ≠ 0. However, note that the

variables 𝑥2 𝑎𝑛𝑑 𝑥3 are also swapped in the column vector ��, else you would be solving a

different set of equations!

𝑥1 + 2𝑥2 − 𝑥3 = −8 −𝑥2 = −4

−𝑥2 + 2𝑥3 = +6}(left) original equation/(right) swapped equation:

𝑥1 + 2𝑥3 − 𝑥2 = −8 −𝑥3 = −4

2𝑥2 − 𝑥3 = +6}

Proceed as follows:

[1 −2 −10 −1 00 0 2

] {

𝑥1𝑥3𝑥2} = {

−8−410}

Reverse substitution will yield 𝑥𝑇 = [−11 , 5 , 4]

Page 18: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #04

Gauss-Jordan

1. Procedure is similar to that of GE

2. Normalizer the pivotal element

3. Eliminate the unknown from all rows, below and above the pivot row

4. No back substitution is required as required in GE.

𝐴�� = ��

[

𝑎11 𝑎12 𝑎13𝑎21 𝑎22 𝑎23𝑎31 𝑎32 𝑎33

]

3×3

{

𝑥1𝑥2𝑥3} = {

𝑏1𝑏2𝑏3

}

Step 1: 𝑎1𝑗′ =

𝑎1𝑗

𝑎11 𝑗 = 1,3 (𝑛𝑜𝑟𝑚𝑎𝑙𝑖𝑧𝑒 𝑎11(𝑝𝑖𝑣𝑜𝑡𝑎𝑙 𝑒𝑙𝑒𝑚𝑒𝑛𝑡) to 1.0)

𝑏1′ = 𝑏1 𝑎11⁄

𝑎2𝑗′ = 𝑎2𝑗 − 𝑎1𝑗

′ × 𝑎21𝑎3𝑗

′ = 𝑎3𝑗 − 𝑎1𝑗′ × 𝑎31

𝑏2′ = 𝑏2 − 𝑏1

′ × 𝑎21𝑏3′ = 𝑏3 − 𝑏1

′ × 𝑎31 }

𝑠𝑎𝑚𝑒 𝑎𝑠 𝑡ℎ𝑒 𝐺𝐸 𝑚𝑒𝑡ℎ𝑜𝑑;𝑚𝑎𝑘𝑖𝑛𝑔𝑡ℎ𝑒 𝑓𝑖𝑟𝑠𝑡 𝑐𝑜𝑙𝑢𝑚𝑛 𝑏𝑒𝑙𝑜𝑤 𝑡ℎ𝑒 𝑝𝑖𝑣𝑜𝑡𝑎𝑙 𝑟𝑜𝑤 𝑡𝑜 𝑏𝑒 0.

[

1 𝑎12′ 𝑎13

0 𝑎22′ 𝑎23

0 𝑎32′ 𝑎33

′]

3×3

{ �� } = {

𝑏1′

𝑏2′

𝑏3′

}

Step2: 𝑎2𝑗′′ =

𝑎2𝑗′

𝑎22′ 𝑗 = 2,3 (𝑛𝑜𝑟𝑚𝑎𝑙𝑖𝑧𝑒 𝑝𝑖𝑣𝑜𝑡𝑎𝑙 𝑒𝑙𝑒𝑚𝑒𝑛𝑡 𝑜𝑓 2𝑛𝑑 𝑟𝑜𝑤 to 1.0)

𝑏2′′ = 𝑏2

′ 𝑎22′⁄

𝑎1𝑗′′ = 𝑎1𝑗

′ − 𝑎2𝑗′ × 𝑎12

𝑏1′′ = 𝑏1

′ − 𝑏2′ × 𝑎12

′}𝑠𝑢𝑏𝑡𝑟𝑎𝑐𝑡 𝑡ℎ𝑒 𝑚𝑜𝑑𝑖𝑓𝑖𝑒𝑑 𝑝𝑖𝑣𝑜𝑡𝑎𝑙 𝑟𝑜𝑤 𝑓𝑟𝑜𝑚 𝑡ℎ𝑒 𝑟𝑜𝑤 𝑎𝑏𝑜𝑣𝑒.

𝑵𝒐𝒕𝒆 𝒕𝒉𝒊𝒔 𝒊𝒔 𝒕𝒉𝒆 𝒆𝒙𝒕𝒓𝒂 𝒔𝒕𝒆𝒑 𝒊𝒏 𝑮𝑬.

𝑎3𝑗′′ = 𝑎3𝑗

′ − 𝑎2𝑗′ × 𝑎32

𝑏3′′ = 𝑏3

′ − 𝑏2′ × 𝑎32

′}

𝑠𝑢𝑏𝑡𝑟𝑎𝑐𝑡 𝑡ℎ𝑒 𝑚𝑜𝑑𝑖𝑓𝑖𝑒𝑑 𝑝𝑖𝑣𝑜𝑡𝑎𝑙 𝑟𝑜𝑤 𝑓𝑟𝑜𝑚 𝑡ℎ𝑒 𝑟𝑜𝑤 𝑏𝑒𝑙𝑜𝑤.𝑇ℎ𝑖𝑠 𝑖𝑠 𝑡ℎ𝑒 𝑠𝑎𝑚𝑒 𝑠𝑡𝑒𝑝 𝑎𝑠 𝑖𝑛 𝐺𝐸.

Page 19: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

[

1 0 𝑎13′′

0 1 𝑎23′′

0 0 𝑎33′′] �� = {

𝑏1′′

𝑏2′′

𝑏3′′

}

Step 3: 𝑏3′′′ = 𝑏3

′′ 𝑎33′′⁄ (normalize pivotal element to 1)

𝑏2′′′ = 𝑏2

′′ − 𝑏3′′′𝑎23

′′

𝑏1′′′ = 𝑏1

′′ − 𝑏3′′′𝑎13

′′}𝑠𝑢𝑏𝑡𝑟𝑎𝑐𝑡 𝑏𝑜𝑡ℎ 𝑟𝑜𝑤𝑠

1 𝑎𝑛𝑑 2 𝑎𝑏𝑜𝑣𝑒 𝑓𝑟𝑜𝑚 𝑝𝑖𝑣𝑜𝑡𝑎𝑙 𝑟𝑜𝑤. 𝑇ℎ𝑒𝑟𝑒 𝑖𝑠 𝑛𝑜 𝑟𝑜𝑤 𝑏𝑒𝑙𝑜𝑤 𝑡ℎ𝑒 𝑝𝑖𝑣𝑜𝑡𝑎𝑙 𝑟𝑜𝑤.

[1 0 00 1 00 0 1

] {

𝑥1𝑥2𝑥3} = {

𝑏1′′′

𝑏2′′′

𝑏3′′′

}

Therefore, 𝑋𝑇 = 𝑏(′′′)𝑇: 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛.

No back substitution is required for a unit matrix!

Make a note that G-J method can also be used to determine inverse of the matrix, if

working on the augmented matrix. Check text books for more details.

example: [1 −1 21 1 12 −2 3

] { �� } = {−8−2−20

}

⇒ [1 −1 20 2 −10 0 −1

] [

𝑥1𝑥2𝑥3] = [

−8 6−4] (pivotal element already had ‘1’ ⇒ no need to normalize!)

⇒ [1 −1 20 1 −0.50 0 −1

] [

𝑥1𝑥2𝑥3] = [

−83−4] (pivotal row was divided by 2 to make pivotal element to be 1)

⇒ [1 0 1.50 1 −0.50 0 −1

] [

𝑥1𝑥2𝑥3] = [

−5 3−4] (rows were subtracted above and below from the pivotal row)

⇒ [1 0 1.50 1 −0.50 0 1

] [

𝑥1𝑥2𝑥3] = [

−534] (pivotal element was made to be 1)

⇒ [1 0 00 1 00 0 1

] [

𝑥1𝑥2𝑥3] = [

−1154] (rows 1 & 2 subtracted from the pivotal row)

𝑋𝑇 = [−11 5 4]𝑇

You should ensure that the programming code for G-J is written by modifying the code for GE,

instead of writing afresh, by changing the indices for i and j.

Page 20: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

LU Decomposition: Two similar/identical methods

Dolittle Crout’s

𝐴�� = ��

(This method is considered to be the best if only right hand side �� changes from problem/case

to problem/case)

𝐴 = 𝐿𝑈 ⇒𝑑𝑒𝑐𝑜𝑚𝑝𝑜𝑠𝑖𝑡𝑖𝑜𝑛𝑠 𝑖𝑛𝑡𝑜 𝐿 𝑎𝑛𝑑 𝑈

{

[

1 0 0𝑙21 1 0𝑙31 𝑙32 1

] [

𝑈11 𝑈12 𝑈130 𝑈22 𝑈230 0 𝑈33

]

𝐷𝑜𝑙𝑖𝑡𝑡𝑙𝑒

[

𝑙11 0 0𝑙21 𝑙22 0𝑙31 𝑙32 𝑙33

] [1 𝑈12 𝑈130 1 𝑈230 0 1

]

𝐶𝑟𝑜𝑢𝑡

In either case, steps are as follows:

1. 𝐴 = 𝐿𝑈 (𝑑𝑒𝑐𝑜𝑚𝑝𝑜𝑠𝑒)

2. 𝐿𝑈 �� = ��

��

} ⇒ 𝐿�� = ��, 𝑠𝑜𝑙𝑣𝑒 𝑓𝑜𝑟 �� 𝑓𝑖𝑟𝑠𝑡

3. 𝑈�� = �� ⇒ 𝑠𝑜𝑙𝑣𝑒 𝑓𝑜𝑟 ��

example: [1 −1 21 1 12 −2 3

] { �� } = {−8−2−20

}

𝐴 = [1 0 0𝑙21 1 0𝑙31 𝑙32 1

]

3×3

[

𝑈11 𝑈12 𝑈130 𝑈22 𝑈230 0 𝑈33

]

3×3

=

[ 𝑈11 𝑈12 𝑈13

𝑙21𝑈11 (𝑙21𝑈12+𝑈22

) (𝑙21𝑈13+𝑈23

)

𝑙31𝑈11 (𝑙31𝑈12+

𝑙32𝑈22

)

(

𝑙31𝑈13+

𝑙32𝑈23+𝑈33 )

]

3×3

Match,

𝑈11 = 1, 𝑈12 = −1, 𝑈13 = 2

Page 21: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

𝑙21𝑈11 = 1, 𝑙21𝑈12 + 𝑈12 = 1, 𝑙21𝑈13 + 𝑈23 = 1

𝑙31𝑈11 = 2, 𝑙31𝑈12 + 𝑙32𝑈23 = −2, 𝑙31𝑈13 + 𝑙32𝑈23 + 𝑈33 = 3

Therefore, there are 9 unknown & 9 equations to solve and the problem is well defined.

How do we obtain LU?

Well, use GE to reduce A to an upper triangular matrix U.

However, in addition, store multiplication coefficients of GE as the coefficients 𝑙21, 𝑙31, 𝑎𝑛𝑑 𝑙32

of lower triangular matrix

as: 𝑙𝑖𝑘 =𝑎𝑖𝑘

𝑎𝑘𝑘;

𝑘 = 1 𝑡𝑜 𝑛 − 1𝑖 = 𝑘 + 1 𝑡𝑜 𝑛

}

It is clear that the programming code used for GE to reduce the matrix A to UTM (U) is the

same as that for determining U of LU decomposition method. In addition, the coefficients of L

are also determined automatically by defining an extra coefficient 𝑙𝑖𝑘(see above) in the same

programming code.

Example:

𝐴 = [1 −1 21 1 12 −2 3

]

Step 1:

= [

1 0 0𝑙21 1 0𝑙31 𝑙32 1

] [

𝑈11 𝑈12 𝑈130 𝑈22 𝑈230 0 𝑈33

]

L U

= [

1 0 0𝑙21 = 1 1 0𝑙31 = 2 𝑙32 = 0 1

] [1 −1 20 2 −10 0 −1

]

{

𝑁𝑜𝑡𝑒 𝑙21 𝑖𝑠 𝑡ℎ𝑒 𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡 𝑡𝑜 𝑚𝑎𝑘𝑒 𝑡ℎ𝑒 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡𝑈12 = 0. 𝑆𝑖𝑚𝑖𝑙𝑎𝑟𝑖𝑡𝑦,

𝑙31 𝑎𝑛𝑑 𝑙32 𝑎𝑟𝑒 𝑑𝑒𝑡𝑒𝑟𝑚𝑖𝑛𝑒𝑑

L U

Therefore, [1 −1 21 1 12 −2 3

] = [1 0 01 1 02 0 1

] [1 −1 20 2 −10 0 −1

]

A L U

Page 22: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

Step 2: 𝐿𝑑 = ��

[1 0 01 1 02 0 1

] [

𝑑1𝑑2𝑑3

] = [−8−2−20

]

𝑑1 = −8 ; 𝑑2 = −2 + 8 = 6; 𝑑3 = −20 + 16 = −4

𝑑𝑇 = [−8 6 − 4]

(Note: you have done forward substitution or solved a LTM, which is just opposite to

solving an UTM or reverse/backward substitution step of GE)

Step 3: 𝑈�� = ��

[1 −1 20 2 −10 0 −1

] {𝑋1𝑋2𝑋3

} = {−8 6−4}

(Note this is the reverse/backward substitution of GE)

𝑋3 = 4, 𝑋2 = (6 + 4) 2⁄ = 5, 𝑋1 = −8 + 5 − 8 = −11

𝑋𝑇 = [−11 5 4]𝑇 Ans.

You should ensure that you are not writing a fresh code for the LU decomposition method.

Rather, you simply modify the code you wrote earlier for the 1st part (forward substitution) of

GE, or the code to reduce A to UTM. Then, write a code for inverting LTM and use the

previously written code for the back-substitution or the reverse substitution of GE. In other

words, the code of LU decomposition has three sub-parts.

Page 23: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #05

Matrix Inverse 𝑨 𝑨−𝟏 = 𝑰(𝒅𝒆𝒇𝒊𝒏𝒊𝒕𝒊𝒐𝒏 𝒇𝒐𝒓 𝑨−𝟏)

[1 0 00 1 00 0 1

]

If 𝐴 = [

𝑎11 𝑎12 𝑎13

𝑎21 𝑎22 𝑎23

𝑎31 𝑎32 𝑎33

], then

[

𝑎11 𝑎12 𝑎13

𝑎21 𝑎22 𝑎23

𝑎31 𝑎32 𝑎33

] [

𝑏11 𝑏12 𝑏13

𝑏21 𝑏22 𝑏23

𝑏31 𝑏32 𝑏33

] = [1 0 00 1 00 0 1

]

𝐴 𝐴−1 𝐼

Making use of the rule of matrix multiplication (row×column), it is clear that

[

𝑎11 𝑎12 𝑎13

𝑎21 𝑎22 𝑎23

𝑎31 𝑎32 𝑎33

] [

𝑏11

𝑏21

𝑏31

] = [100] ⇒ 𝐴𝑏1 = [

100]

and [ ] [

𝑏12

𝑏22

𝑏32

] = [010] ⇒ 𝐴𝑏2

= [0 1 0]𝑇

[ ] [

𝑏13

𝑏23

𝑏33

] = [001] ⇒ 𝐴𝑏3

= [0 0 1]𝑇

Therefore, 𝑏𝑖𝑗 can be calculated from as many equations.

However, LU decomposition can be used to determine 𝐴−1as well:

𝐴𝑏1 = 𝐿𝑈 𝑏1 = [1 0 0]𝑇

𝑑1

or 𝐿 𝑑1 = [1 0 0]𝑇 ⇒ 𝑑𝑒𝑡𝑒𝑟𝑚𝑖𝑛𝑒 𝑑1

So, 𝑈𝑏1 = 𝑑1 ⇒ 𝑑𝑒𝑡𝑒𝑟𝑚𝑖𝑛𝑒 𝑏1

Similarly,

𝐴𝑏2 = 𝐿𝑈 𝑏2

= [0 1 0]𝑇

or 𝐿 𝑑2 = [0 1 0]𝑇 ⇒ 𝑑𝑒𝑡𝑒𝑟𝑚𝑖𝑛𝑒 𝑑2

Page 24: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

So, 𝑈𝑏2 = 𝑑2

⇒ 𝑑𝑒𝑡𝑒𝑟𝑚𝑖𝑛𝑒 𝑏2 , 𝑠𝑜 𝑓𝑜𝑟𝑡ℎ,

Example: [𝐴] = [25 5 164 8 1144 12 1

] = 𝐿𝑈

[25 5 164 8 1144 12 1

]

Apply GE (Forward step)

[25 5 10 −4.8 0.560 −16.8 −4.36

] ⇒

𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡𝑠 𝑢𝑠𝑒𝑑 𝑡𝑜 𝑚𝑎𝑘𝑒

1𝑠𝑡 𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠 𝑜𝑓 𝑡ℎ𝑒 𝑟𝑜𝑤𝑠, 𝑏𝑜𝑡𝑡𝑜𝑚𝑜𝑓 𝑡ℎ𝑒 𝑝𝑖𝑣𝑜𝑡𝑎𝑙 𝑟𝑜𝑤 𝑡𝑜 𝑏𝑒 𝑧𝑒𝑟𝑜

= 64 25⁄ 𝑎𝑛𝑑 144

25

𝑜𝑟 2.56 𝑎𝑛𝑑 5.76

[25 5 10 −4.8 −1.560 0 0.7

] ⇒

𝑇ℎ𝑖𝑠 𝑖𝑠 𝑎𝑛 𝑈𝑇𝑀 .𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡 𝑢𝑠𝑒𝑑 𝑡𝑜 𝑚𝑎𝑘𝑒 𝑡ℎ𝑒

1𝑠𝑡 𝑒𝑙𝑒𝑚𝑒𝑛𝑡 𝑜𝑓 𝑡ℎ𝑒 𝑙𝑎𝑠𝑡 𝑟𝑜𝑤𝑡𝑜 𝑏𝑒 𝑧𝑒𝑟𝑜

= 16.8 4.8 = 3.5⁄

Therefore,

𝐿 = [1 0 0

2.56 1 05.76 3.5 1

]

or,

[25 5 164 8 1144 1 1

] = [1 0 0

2.56 1 05.76 3.5 1

] [25 5 10 −4.8 −1.560 0 0.7

]

A L U

Now, determine 𝐴−1

Step 1: 𝐿𝑈 𝑏1 = [1 0 0]𝑇

𝑑1

Page 25: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

[1 0 0

2.56 1 05.76 3.5 1

] {

𝑑1

𝑑2

𝑑3

} = {100}

L 𝒅𝟏

𝑑1 = 1, 𝑑2 = 0 − 2.56 = −2.56, 𝑑3 = 0 − 5.76 + 3.50 × 2.56 = 3.2

2. [25 5 10 −4.8 −1.560 0 0.7

] {

𝑏11

𝑏21

𝑏31

} = {

𝑑1

𝑑2

𝑑3

}

U 𝒃𝟏

𝑏31 = 3.20.7⁄ = 4.571, 𝑏21 = (−2.56 − 4.571 × (−1.56))/−4.8 = −0.9524

𝑏11 = (1 − 4.571 − 5 × (−0.9524))/25.0 = 0.04762

or, 𝑏1𝑇 = [0.04762 − 0.9524 4.571]𝑇

3. [1 0 0

2.56 1 05.76 3.5 1

] {

𝑑1

𝑑2

𝑑3

} = {010} ⇒ 𝑑1 = 0, 𝑑2 = 1, 𝑑3 = −3.5

L 𝒅𝟏

[25 5 10 −4.8 −1.560 0 0.7

] {

𝑏12

𝑏22

𝑏32

} = {01

−3.5}

U 𝒃𝟐

��2𝑇

= [−0.0833 1.417 − 5.0]𝑇

Similarly,

��3𝑇

= [0.03571 − 0.4643 1.429]𝑇

𝐴−1 = [0.04762 −0.0833 0.03571−0.9524 1.417 −0.46434.571 −0.5 1.429

]

⇒ Methods so far to solve 𝑨�� = �� and programming codes:

(a) GE: To solve a large number of algebraic equations, a programming code is

required. As earlier shown, GE contains two distinct steps: (1) forward

elimination to convert �� to an upper triangular matrix (UTM), (2)

Page 26: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Backward/reverse substitution to solve UTM. Therefore, while writing the code;

it is recommended that one clearly distinguishes the two steps as “subroutines”

(# 1 and 2). You will later see that the other methods also often require one or

both of the steps/codes.

(b) GJ: The programming code for GJ is similar to that (code 1) of the forward

elimination of GE, with some modification. The second part (code) of GE, ie.

reverse substitution is not required. The modification or extra step is simple.

First, pivotal elements should be normalized to 1; in addition to subtracting the

modified pivotal row from the rows below the ‘𝑖𝑡ℎ’ row of GE, the pivotal row is

also subtracted from the rows above. Therefore, one extra line is included in the

code for GJ.

(c) The code to determine the determinant of the matrix A is the same as that (code

1) for converting A to UTM, ie. the first or forward elimination step of GE. Further, add a line to determine the ∏ 𝑎𝑖𝑖

𝑛𝑖=1 product of the diagonal elements of

the UTM ie. one can put the flag to check if any of the 𝑎𝑖𝑖 is zero, the matrix is

singular and cannot be inverted. One can also write a simple code to check the

number # of zeros on the diagonal elements and therefore, determine the rank

of the matrix as (𝑛 − #).

(d) LU method: The programming code (# 3) is similar to that (code 1) of the forward step of GE, to determine UTM. An extra line in the programming loop is

required to store the coefficients 𝑙𝑖𝑘 = (𝑎𝑖𝑘

𝑎𝑘𝑘), used to make the elements of the

first column of the UTM to be zero, as the elements of the empty columns of the LTM.

𝐴 = [𝑙11

𝑙21 𝑙22

] × [ ]

LTM UTM

(e) Inverse of the matrix: First, the programming code (# 3) of LU is to be used. The forward substitution on LTM will yield/give �� (𝑐𝑜𝑙𝑢𝑚𝑛 𝑚𝑎𝑡𝑟𝑖𝑥) and the backward substitution on UTM will yield ��(𝑐𝑜𝑙𝑢𝑚𝑛 𝑚𝑎𝑡𝑟𝑖𝑥)(already available; # 2). Therefore, one new code/subroutine (# 4) is required for the forward substitution on LTM, which is not different from that (# 2) for the reverse substitution on UTM:

𝐴 = 𝐿𝑈 (𝑐𝑜𝑑𝑒 # 3)

𝐹𝑜𝑟𝑤𝑎𝑟𝑑 𝑠𝑢𝑏𝑠𝑡𝑖𝑡𝑢𝑡𝑖𝑜𝑛 → �� (𝑐𝑜𝑑𝑒 #4)

𝐵𝑎𝑐𝑘𝑤𝑎𝑟𝑑 𝑠𝑢𝑏𝑠𝑡𝑖𝑡𝑢𝑡𝑖𝑜𝑛 → �� (𝑐𝑜𝑑𝑒 # 2)

Page 27: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #06

Thomas Algorithm (Tridiagonal matrix)

𝐴�� = ��

[ 𝑎11 𝑎12 0 ⋯ 0 0 0 0𝑎21 𝑎22 𝑎23 ⋯ 0 0 0 00 𝑎32 𝑎33 𝑎34 0 ⋯ 0 00 0 𝑎43 𝑎44 𝑎45 ⋯ 0 0

0 0 0 0 0 0 𝑎𝑛𝑛−1 𝑎𝑛𝑛]

{

𝑋1𝑋2𝑋3⋮𝑋𝑛}

=

{

𝑏1𝑏2𝑏3⋮𝑏𝑛}

Tridiagonal matrix has 3 non-zero elements in all of its rows, except in the 1st and last row,

with one element each on the left and right of the diagonal element. The 1st and last rows have

one element on the right and left of the diagonal elements, respectively. It is a banded matrix

around its diagonal:

[

]

{

𝑋1𝑋2𝑋3⋮𝑋𝑛}

=

{

𝑏1𝑏2𝑏3⋮𝑏𝑛}

Therefore, a tridiagonal matrix can be represented using single subscripted indices for its

elements:

[ 𝑏1 𝑐1 0 0 ⋯ 0𝑎2 𝑏2 𝑐2 0 ⋯ 00 𝑎3 𝑏3 𝑐3 ⋯ 0

𝑎4 𝑏4 𝑐4𝑧𝑒𝑟𝑜

𝑎𝑛 𝑏𝑛]

Zero

Note that the element in the 𝑖𝑡ℎ row is represented as (𝑎𝑖, 𝑏𝑖, 𝑐𝑖). All bs are on the diagonal.

Therefore, 𝐴�� = ��, where 𝐴 is a tridiagonal matrix and it represents the following set of linear

algebraic equations:

Page 28: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

𝑏1𝑥1 + 𝑐1𝑥2 = 𝑑1𝑎2𝑥1 + 𝑏2𝑥2 + 𝑐2𝑥3 = 𝑑2𝑎3𝑥2 + 𝑏3𝑥3 + 𝑐3𝑥4 = 𝑑3𝑎4𝑥3 + 𝑏4𝑥4 + 𝑐4𝑥5 = 𝑑4

𝑎𝑛𝑥𝑛−1 + 𝑏𝑛𝑥𝑛 = 𝑑𝑛}

⇒ You must have noted that for the 𝑖𝑡ℎ row, 𝑏𝑖 is the diagonal element multiplied with the

variable 𝑥𝑖 in the some row, whereas 𝑎𝑖 is multiplied with 𝑥𝑖−1(the variable above 𝑖𝑡ℎ row) and

𝑐𝑖 is multiplied with 𝑥𝑖+1(the variable below 𝑖𝑡ℎrow). Naturally, the first and last rows have

only two variables.

⇒(Tridiagonal system is quite common when using Finite Difference 2nd order method to solve

boundary value problems or partial differential 𝑒𝑞𝑛𝑠.)

Thomas algorithm to solve such system:

Step 1:

𝒙𝟏 is eliminated : (𝑏2 −𝑐1

𝑏1𝑎2) 𝑥2 + 𝑐2𝑥3 = (𝑑2 −

𝑑1

𝑏1𝑎2)

(by dividing 1st row with 𝑏1, multiplying with 𝑐1 and subtracting from row 2)

𝒙𝟐 is eliminated : (𝑏3 −𝑐2

𝑏2𝑎3) 𝑥3 + 𝑐3𝑥4 = (𝑑3 −

𝑑2

𝑏2𝑎3)

𝒙𝒌−𝟏 is eliminated : (𝑏𝑘 −𝑐𝑘−1

𝑏𝑘−1𝑎𝑘) 𝑥𝑘 + 𝑐𝑘𝑥𝑘+1 = (𝑑𝑘 −

𝑑𝑘−1

𝑏𝑘−1𝑎𝑘)

It is clear that;

𝐴𝑙𝑙 𝑎𝑠 𝑎𝑟𝑒 𝑒𝑙𝑖𝑚𝑖𝑛𝑎𝑡𝑒𝑑𝐴𝑙𝑙 𝑏𝑠 𝑎𝑟𝑒 𝑚𝑜𝑑𝑖𝑓𝑖𝑒𝑑𝐴𝑙𝑙 𝑐𝑠 𝑎𝑟𝑒 𝑢𝑛𝑎𝑙𝑡𝑒𝑟𝑒𝑑𝐴𝑙𝑙 𝑑𝑠 𝑎𝑟𝑒 𝑚𝑜𝑑𝑖𝑓𝑖𝑒𝑑

}

Last row: 𝑏𝑛 = 𝑏𝑛 −𝑐𝑛−1

𝑏𝑛−1𝑎𝑛; 𝑑𝑛 = 𝑑𝑛 −

𝑑𝑛−1

𝑏𝑛−1𝑎𝑛

(Note that 𝑎𝑛 has moved to RHS, leaving behind 𝑏𝑛𝑥𝑛 only on the LHS)

Page 29: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

(It is important to note that 𝑘𝑡ℎ row uses the latest modified values of 𝑏𝑘 and 𝑑𝑘 from the

previous (k-1) step. Therefore, there is no need to store the previous values of (a, b, d) while

writing the code)

Back-substitution: 𝑋𝑛 =𝑑𝑛

𝑏𝑛 (𝑛𝑡ℎ 𝑟𝑜𝑤 ℎ𝑎𝑠 𝑜𝑛𝑙𝑦 𝑏𝑛 𝑎𝑛𝑑 𝑑𝑛)

𝑋𝑛−1 =𝑑𝑛−1−𝑐𝑛−1𝑥𝑛

𝑏𝑛−1 (𝑛 − 1 𝑟𝑜𝑤 ℎ𝑎𝑠 𝑏𝑛−1, 𝑐𝑛−1, 𝑎𝑛𝑑 𝑑𝑛−1)

⇒ A pseudo programming code can be written as follows:

Tridiagonal (N, a, b, c, d, X)

𝑑𝑜 𝑖 = 1,𝑁

𝑎(𝑖) =

𝑏(𝑖) =

𝑐(𝑖) =

𝑑(𝑖) =

end do

𝑑𝑜 𝑖 = 2, 𝑁

𝑏(𝑖) = 𝑏(𝑖) − 𝑎(𝑖)𝑐(𝑖 − 1)

𝑏(𝑖 − 1)

𝑑(𝑖) = 𝑑(𝑖) − 𝑎(𝑖)𝑑(𝑖 − 1)

𝑏(𝑖 − 1)}

𝑓𝑜𝑟𝑤𝑎𝑟𝑑 𝑠𝑢𝑏𝑠𝑡𝑖𝑡𝑢𝑡𝑖𝑜𝑛

end do

𝑋𝑛 =𝑑(𝑛)

𝑏(𝑛)

𝑑𝑜 (𝑖) = 𝑁 − 1, 1, −1

𝑋𝑖 =𝑑(𝑖) − 𝑐(𝑖)𝑋𝑖+1

𝑏(𝑖)} 𝑟𝑒𝑣𝑒𝑟𝑠𝑒 𝑠𝑢𝑏𝑠𝑡𝑖𝑡𝑢𝑡𝑖𝑜𝑛

end do

Page 30: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Indirect Methods

GE, GJ, LU decomposition are the direct methods to solve 𝐴�� = ��. Simple iterations

can also be done to solve a set of algebraic equations, Jacobi and Gauss-Seidel being the two

commonly used indirect methods.

Ex. [2 1 01 2 10 1 1

] {𝑋1𝑋2𝑋3

} = {124}

Make a guess 𝑋1(1), 𝑋2

(1), 𝑋3

(1)

Jacobi Gauss-Seidel

𝑋1(2)=

1−𝑋2(1)

2 =

1−𝑋2(1)

2

𝑋2(2)=

2−𝑋1(1)−𝑋3

(1)

2 =

2−𝑋1(2)−𝑋3

(1)

2

𝑋3(2) =

4−𝑋2(1)

1 =

4−𝑋2(2)

1

Takes all 𝑋𝑠(𝑘−1)

of the previous iteration Uses the most latest iterated values of 𝑋𝑠.

In general: 𝐴�� = ��

Jacobi: 𝑋𝑖(𝑘+1) =

𝑏𝑖−∑ 𝑎𝑖𝑗𝑋𝑗(𝑘)𝑛

𝑗=1

𝑎𝑖𝑖(≠0) (𝑗 ≠ 𝑖)

diagonal elements

G-S: 𝑋𝑖(𝑘+1) =

{

𝑏𝑖 − ∑ 𝑎𝑖𝑗𝑋𝑗

(𝑘+1)− ∑ 𝑎𝑖𝑗𝑋𝑗

(𝑘)𝑛𝑗=𝑖+1

𝑖−1𝑗=1

𝑢𝑝𝑑𝑎𝑡𝑒𝑑 𝑜𝑙𝑑 𝑙𝑎𝑡𝑒𝑠𝑡 𝑣𝑎𝑙𝑢𝑒𝑠𝑣𝑎𝑙𝑢𝑒𝑠

𝑎𝑖𝑖(≠ 0)

Page 31: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

At any 𝑖𝑡ℎ row:

1⋯⋯ 𝑖 − 1 𝑖 𝑖 + 1⋯⋯ 𝑁

𝑢𝑝𝑑𝑎𝑡𝑒𝑑𝑣𝑎𝑙𝑢𝑒𝑠(𝑘 + 1)

𝑜𝑙𝑑

𝑣𝑎𝑙𝑢𝑒𝑠(𝑘)

Schematically,

elements multiply with the variables 1 to 𝑥𝑖−1

[

1 ⋯ 𝑖 − 1 𝑖 𝑖 + 1 ⋯ 𝑛

]

{

𝑋1𝑋2⋮𝑋𝑖⋮⋮𝑋𝑛}

elements multiply with the𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 𝑥𝑖+1 𝑡𝑜 𝑥𝑛.

G-S (modified)

𝑋𝑖 = 𝜆𝑋𝑖(𝑛𝑒𝑤) + (1 − 𝜆)𝑋𝑖

(𝑜𝑙𝑑)

𝜆 = 1 (𝑢𝑛𝑚𝑜𝑑𝑖𝑓𝑖𝑒𝑑)

0 < 𝜆 < 1 ⇒ 𝑢𝑛𝑑𝑒𝑟 − 𝑟𝑒𝑙𝑎𝑥𝑎𝑡𝑖𝑜𝑛 𝑓𝑎𝑐𝑡𝑜𝑟

1 < 𝜆 < 2 ⇒ 𝑜𝑣𝑒𝑟 − 𝑟𝑒𝑙𝑎𝑥𝑎𝑡𝑖𝑜𝑛 𝑓𝑎𝑐𝑡𝑜𝑟

(′𝜆′𝑖𝑠 𝑜𝑓𝑡𝑒𝑛 𝑎𝑠𝑠𝑢𝑚𝑒𝑑 𝑑𝑒𝑝𝑒𝑛𝑑𝑖𝑛𝑔 𝑢𝑝𝑜𝑛 𝑔𝑢𝑒𝑠𝑒𝑠, 𝑒𝑡𝑐)

Look differently! : LDU method

Page 32: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

[ 𝑎11 𝑎12 ⋯ 𝑎1𝑛⋮⋮⋮𝑎𝑛1 ⋯ ⋯ 𝑎𝑛𝑛]

𝑛×𝑛

=

[ 0𝑎21 0

00

𝑎𝑛1 ⋯ 𝑎𝑛−1 ]

+

[ 𝑎11

⋱⋱

𝑎𝑛𝑛]

+

[ 0 ⋯ ⋯ 𝑎1𝑛

00

𝑎𝑛−1𝑛0 ]

strictly lower𝑡𝑟𝑖𝑎𝑛𝑔𝑢𝑙𝑎𝑟 𝑚𝑎𝑡𝑟𝑖𝑥

(𝐿) +

𝐷(𝑑𝑖𝑎𝑔𝑜𝑛𝑎𝑙

𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠 𝑜𝑛𝑙𝑦) +

𝑠𝑡𝑟𝑖𝑐𝑡𝑙𝑦 𝑢𝑝𝑝𝑒𝑟𝑡𝑟𝑖𝑎𝑛𝑔𝑢𝑙𝑎𝑟 𝑚𝑎𝑡𝑟𝑖𝑥

(𝑈)

𝐴 = 𝐿 + 𝐷 + 𝑈

𝐴�� = ��

(𝐿 + 𝐷 + 𝑈)�� = �� ⇒ 𝐷�� = �� − 𝐿�� − 𝑈��

𝑜𝑟 �� =�� − 𝐿�� − 𝑈��

𝐷

Jacobi:

��(𝑘+1) =�� − (𝐿 + 𝑈)��(𝑘)

𝐷

𝑜𝑟 𝑋𝑖(𝑘+1)

=𝑏𝑖 − ∑ 𝑋𝑗

(𝑘)𝑎𝑖𝑗

𝑛𝑗=1

𝑎𝑖𝑖 ; 𝑗 ≠ 𝑖 (𝑗 = 𝑖 𝑤𝑖𝑙𝑙 𝑟𝑒𝑝𝑟𝑒𝑠𝑒𝑛𝑡 𝑑𝑖𝑎𝑔𝑜𝑛𝑎𝑙 𝑒𝑙𝑒𝑚𝑒𝑛𝑡)

𝐆 − 𝐒 ∶ (𝐿 + 𝐷)�� = �� − 𝑈��

(𝐿 + 𝐷)��(𝑘+1) = �� − 𝑈��(𝑘)

𝐷��(𝑘+1) = �� − 𝑈��(𝑘) − 𝐿��(𝑘+1)

𝑋𝑖(𝑘+1)

=𝑏𝑖−∑ 𝑋𝑖

(𝑘+1)𝑎𝑖𝑗−∑ 𝑋𝑖

𝑘𝑎𝑖𝑗𝑛𝑗=𝑖+1

𝑖−1𝑗=1

𝑎𝑖𝑖

(𝑠𝑎𝑚𝑒 𝑎𝑠 𝑏𝑒𝑓𝑜𝑟𝑒 ) ( 𝑎𝑖𝑖 ≠ 0 )

Both methods will lead to the same solutions, with different # of iterations.

Page 33: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #07

Homogeneous linear algebraic equations

-Represents a special class of problems, also known as the Eigenvalue or Characteristic type of

problems

- Mathematically represented as 𝐴�� = 0 or �� = 0 (𝑛𝑢𝑙𝑙 𝑣𝑒𝑐𝑡𝑜𝑟)

𝑜𝑟 (

𝑎11𝑥1 + 𝑎12𝑥2 +⋯⋯𝑎1𝑛𝑥𝑛 = 0⋮ ⋮ 𝑎𝑛1𝑥1 + 𝑎𝑛2𝑥2 +⋯⋯𝑎𝑛𝑛𝑥𝑛 = 0

)

Naturally, a trivial solution is �� = 0 . In the simplest geometrical term, two straight lines or

three planes intersect at the origin:

𝑥1 − 𝑥2 = 0 𝑥1 − 0.3𝑥2 = 0

} ⇒ 𝑥2

𝑥1

⇒ A more interesting problem to solve is in seeking a non-trivial solution when 𝑑𝑒𝑡(𝐴) =

0 𝑜𝑟 𝑟 < 𝑚. Such simultaneous set of homogeneous linear equations when 𝑑𝑒𝑡(𝐴) = 0 is

common in several engineering and mechanics applications, and also in the initial and boundary

value problems. Such situation is better known as the eigenvalue problem and is represented by

eigenvalues and the corresponding eigenvectors.

Compare this situation to the earlier discussed set of non-homogeneous linear algebraic

equation 𝐴�� = 𝑏 , where we sought a unique solution, when 𝑑𝑒𝑡|𝐴| ≠ 0. Comparatively,

Non-homogeneous Homogeneous equations

𝐴�� = �� 𝐴�� = 0

det (𝐴) ≠ 0 det(𝐴) = 0

𝑟 = 𝑚 𝑟 < 𝑚

Unique solution Non-trivial solution

𝐸𝑖𝑔𝑒𝑛𝑣𝑎𝑙𝑢𝑒 𝑝𝑟𝑜𝑏𝑙𝑒𝑚

Page 34: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

Let us look at

𝐴�� = 𝜆�� 1 where A is the coefficient matrix and ′𝜆′ is a non-zero number.

matrix scalar quantity

or (𝐴 − 𝜆𝐼)�� = 0 2 where 𝐼 is an identity matrix

𝐼 = [1 0 00 1 00 0 1

]

Equation 1 or 2 represents eigenvalue problem and such equations commonly occur in several

dynamic studies of distillation, adsorption and CSTR, viz. in solving 𝑑��

𝑑𝑡= 0. Equation (2) can

also be written as

{

(𝑎11 − 𝜆)𝑋1 + 𝑎12𝑋2 +⋯⋯𝑎1𝑛𝑋𝑛 = 0

𝑎21𝑋1 + (𝑎22 − 𝜆)𝑋2 +⋯⋯𝑎2𝑛𝑋𝑛 = 0⋮ ⋮

𝑎𝑛1𝑋1 + 𝑎𝑛2𝑋2 +⋯⋯(𝑎𝑛𝑛 − 𝜆)𝑋𝑛 = 0}

or

[

𝑎11 𝑎12 ⋯ 𝑎1𝑛⋮⋮𝑎𝑛1 𝑎𝑛2 ⋯ 𝑎𝑛𝑛

] {

𝑋1𝑋2⋮𝑋𝑛

} = 𝜆{

𝑋1𝑋2⋮𝑋𝑛

}

𝐴(𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡 𝑚𝑎𝑡𝑟𝑖𝑥) 𝑐𝑜𝑙𝑢𝑚𝑛𝑣𝑒𝑐𝑡𝑜𝑟

𝑎 𝑠𝑐𝑎𝑙𝑎𝑟𝑞𝑢𝑎𝑛𝑡𝑖𝑡𝑦

𝑐𝑜𝑙𝑢𝑚𝑛𝑣𝑒𝑐𝑡𝑜𝑟

Re-visit 𝐴�� = 𝜆�� - eigenvalue problem

Most vectors �� will not satisfy such an equation. A common vector (𝑖𝑋1 + 𝑗𝑋2) will change

direction and magnitude to (𝑖𝑏1 + 𝑗𝑏2) on the transformation by A. Only certain special

vectors ��, called eigenvectors, corresponding to only special numbers, 𝜆 (𝑒𝑖𝑡ℎ𝑒𝑟 + 𝑣𝑒 𝑜𝑟 −

𝑣𝑒), called eigenvalues, will satisfy the above equation. In such case, the eigenvector �� does not

change its direction or does not rotate when transformed by the coefficient matrix A, but is

only scaled by the eigenvalue 𝜆. See the geometrical representation below:

Page 35: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

𝑋2

𝑋2

��

�� 𝜆��

��

𝑋1 𝑋1

𝐴�� = �� 𝐴�� = 𝜆��

(𝑛𝑜𝑡 𝑎𝑛 𝑒𝑖𝑔𝑒𝑛𝑣𝑎𝑙𝑢𝑒 𝑝𝑟𝑜𝑏𝑙𝑒𝑚)

(𝑒𝑖𝑔𝑒𝑛𝑣𝑎𝑙𝑢𝑒 𝑝𝑟𝑜𝑏𝑙𝑒𝑚)

(�� 𝑖𝑠 𝑡ℎ𝑒 𝑒𝑖𝑔𝑒𝑛𝑣𝑒𝑡𝑜𝑟 𝑜𝑓 𝐴; 𝑖𝑠 𝑡ℎ𝑒 𝑒𝑖𝑔𝑒𝑛𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝐴)

𝜆

It turns out that (𝑛 × 𝑛) matrix 𝐴 will give ‘𝑛’ 𝜆𝑠(𝑒𝑖𝑔𝑒𝑛𝑣𝑎𝑙𝑢𝑒𝑠), and each eigenvalue will give

‘𝑛’ eigenvectors that will also be linearly independent. As an example,

[𝑎11 𝑎12𝑎21 𝑎22

]2×2

will have 2 𝜆𝑠 (𝜆1 & 𝜆2) ⇒ 𝜆1 → {𝑋}1𝜆2 → {𝑋}2

Both vectors {𝑋}1, & {𝑋}2 will satisfy 𝐴�� = 𝜆��. They will also be linearly independent so that

they can be used as a basis for the space-description. They may be orthogonal or non-

orthogonal.

𝑋2

𝜆1

𝜆2

𝑋1

In the figure above, dotted and solid lines represent two vectors scaled by the respective

eigenvalues1 and 2, respectively.

Similarly, (3 × 3) A matrix will give 3𝜆𝑠(𝜆1, 𝜆2, 𝜆3). Each 𝜆 will give three independent

vectors {𝑋}1, {𝑋}2, {𝑋}3 satisfying 𝐴�� = 𝜆��.

Page 36: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

or (𝐴 − 𝜆𝐼)�� = 0

Linear algebra tells us that for �� to have a non-trivial solution 𝑑𝑒𝑡|(𝐴 − 𝜆𝐼)| = 0.

Example: 𝐴 = [2 11 2

] 𝐴�� = 𝜆��(𝐴 − 𝜆𝐼)�� = 0

𝑑𝑒𝑡 [2 − 𝜆 11 2 − 𝜆

] = 0 ⇒ (2 − 𝜆)2 − 1 = 0

𝜆1 = 1, 3

𝜆1 = 1: [2 11 2

] {𝑋1𝑋2} = 1 {

𝑋1𝑋2}

Both equations yield 𝑋1 = −𝑋2 𝑜𝑟 𝑋1 + 𝑋2 = 0 (𝑟 = 1)

So, �� (𝜆1 = 1): (𝑖 − 𝑗) ≡ { 1−1}

𝜆2 = 3: [2 11 2

] {𝑋1𝑋2} = 3 {

𝑋1𝑋2}

Both equations yield 𝑋1 = 𝑋2 𝑜𝑟 𝑋1−𝑋2 = 0 (𝑟 = 1)

�� (𝜆2 = 3): (𝑖 + 𝑗) ≡ {11}

Note two vectors (𝑖 − 𝑗) 𝑎𝑛𝑑 (𝑖 + 𝑗) are linearly independent and can be used as a basis for

defining 2D space. They need not be orthogonal! They can be used as a linear combination of

any other vector �� in 2D space:

𝑋2

�� = 𝑐1(𝑖 + 𝑗) + 𝑐2(𝑖 − 𝑗)

𝑖 + 𝑗

𝑋1

(𝑖 − 𝑗)

Page 37: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

System of ODEs

It may represent dynamics, i.e. how a system behaves due to a perturbation around steady state

value. Such situation is common in kinetics and the heat and mass transfer related problems in

chemical engineering.

𝑑𝑋1

𝑑𝑡= 𝑓1(𝑋1……𝑋𝑛)

𝑑𝑋2

𝑑𝑡= 𝑓2(𝑋1……𝑋𝑛)

⋮ 𝑑𝑋𝑛

𝑑𝑡= 𝑓𝑛(𝑋1……𝑋𝑛) }

⇒ dynamics

�� 𝑋3

𝑑��

𝑑𝑡= 𝑓(��) [��]𝑇 ≡ [𝑋1, …… . 𝑋𝑛] 𝑋2 𝑋1

Under SS, 𝑓(��) = 0 ⇒ �� = ��𝑠 0 𝑡

𝑜𝑟

𝑓1(𝑋1……𝑋𝑛) = 0

𝑓2(𝑋1……𝑋𝑛) = 0⋮ 𝑓𝑛(𝑋1……𝑋𝑛) = 0

} These sets of algebraic equationsmay represent energy or species

balance under SS.

��(𝑡) = ?

Define, 𝜉(𝑡) = ��(𝑡) − ��𝑠 (𝑑𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 𝑑𝑒𝑝𝑎𝑟𝑡𝑢𝑟𝑒/𝑒𝑟𝑟𝑜𝑟 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠)⁄

𝐸𝑙𝑒𝑚𝑒𝑛𝑡 − 𝑤𝑖𝑠𝑒 𝜉1(𝑡) = 𝑋1(𝑡) − 𝑋1𝑠

𝑜𝑟 𝜉𝑖(𝑡) = 𝑋𝑖(𝑡) − 𝑋𝑖𝑠 (𝑖 = 1………𝑛)

𝑜𝑟, 𝑑��

𝑑𝑡=

𝑑��(𝑡)

𝑑𝑡= 𝑓(��)

𝑜𝑟, 𝑑𝜉𝑖

𝑑𝑡= 𝑓𝑖(𝑋1……𝑋𝑛) (𝑖 = 1……𝑛)

= 𝑓𝑖(𝑋1𝑠 + 𝜉1, 𝑋2𝑠 + 𝜉2, ……𝑋𝑛𝑠 + 𝜉𝑛)

= 𝑓𝑖(𝑋1𝑠, 𝑋2𝑠, 𝑋3𝑠, ……𝑋𝑛𝑠) +

𝜕𝑓𝑖

𝜕𝑋1|𝑋1𝑠

𝜉1 +𝜕𝑓𝑖

𝜕𝑋2|𝑋2𝑠

𝜉2 +⋯⋯𝜕𝑓𝑖

𝜕𝑋𝑛|𝑋𝑛𝑠

𝜉𝑛

(𝑆𝑆)0

Page 38: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

𝜉1 = (𝑋1 − 𝑋1𝑠), 𝜉2 = (𝑋2 − 𝑋2𝑠)…… . , 𝜉𝑛 = (𝑋𝑛 − 𝑋𝑛𝑠)

(Taylor series expansion for multivariables: retain 1st order terms only, i.e. small departure from SS)

{

𝑑𝜉1𝑑𝑡....𝑑𝜉𝑛𝑑𝑡}

=

[ 𝜕𝑓1𝜕𝑋1

𝜕𝑓1𝜕𝑋2

⋯𝜕𝑓1𝜕𝑋𝑛

𝜕𝑓2𝜕𝑋1

𝜕𝑓2𝜕𝑋2

⋯𝜕𝑓2𝜕𝑋𝑛

⋮𝜕𝑓𝑛𝜕𝑋1

𝜕𝑓𝑛𝜕𝑋2

⋯𝜕𝑓𝑛𝜕𝑋𝑛]

{

𝜉1𝜉2⋮ . . . . 𝜉𝑛}

(𝑟𝑜𝑤 × 𝑐𝑜𝑙𝑢𝑚𝑛 𝑚𝑢𝑙𝑡𝑖𝑝𝑙𝑖𝑐𝑎𝑡𝑖𝑜𝑛 𝑟𝑢𝑙𝑒)

𝑁𝑜𝑡𝑒: 𝐹𝑜𝑟 𝑡𝑤𝑜 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 𝑋1 𝑎𝑛𝑑 𝑋2

𝑑𝜉1𝑑𝑡

=𝜕𝑓1𝜕𝑋1

|𝑋1𝑠

(𝑋1 − 𝑋1𝑠) +𝜕𝑓1𝜕𝑋2

|𝑋2𝑠

(𝑋2 − 𝑋2𝑠)

𝑑𝜉2𝑑𝑡

=𝜕𝑓2𝜕𝑋1

|𝑋1𝑠

(𝑋1 − 𝑋1𝑠) +𝜕𝑓2𝜕𝑋2

|𝑋2𝑠

(𝑋2 − 𝑋2𝑠)}

1𝑠𝑡 𝑜𝑟𝑑𝑒𝑟𝑡𝑒𝑟𝑚 𝑜𝑛𝑙𝑦

{

𝑑𝜉1𝑑𝑡𝑑𝜉2𝑑𝑡

} =

[ 𝜕𝑓1𝜕𝑋1

𝜕𝑓1𝜕𝑋2

𝜕𝑓2𝜕𝑋1

𝜕𝑓2𝜕𝑋2]

{𝑋1 − 𝑋1𝑠 = 𝜉1𝑋2 − 𝑋2𝑠 = 𝜉2

}

or,

𝑑��

𝑑𝑡= 𝐴𝜉 𝑜𝑟 𝜉′ = 𝐴𝜉

𝑤ℎ𝑒𝑟𝑒 𝐴 =

[ 𝜕𝑓1

𝜕𝑋1⋯

𝜕𝑓1

𝜕𝑋𝑛

⋮𝜕𝑓𝑛

𝜕𝑋1⋯

𝜕𝑓𝑛

𝜕𝑋𝑛]

; 𝐴 𝑖𝑠 𝑐𝑎𝑙𝑙𝑒𝑑 𝑡ℎ𝑒

𝐽𝑎𝑐𝑜𝑏𝑖𝑎𝑛 𝑚𝑎𝑡𝑟𝑖𝑥 𝑜𝑓 𝐴.

}

Thus, we started from

𝑑��

𝑑𝑡= 𝑓(��)

And derived:

𝑑��

𝑑𝑡= 𝐴𝜉

where 𝜉 = (�� − ��𝑠), and A is the Jacobian matrix of 𝑓 as

[ 𝜕𝑓1

𝜕𝑋1⋯

𝜕𝑓1

𝜕𝑋𝑛

⋮𝜕𝑓𝑛

𝜕𝑋1⋯

𝜕𝑓𝑛

𝜕𝑋𝑛]

Page 39: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #08 (continue..)

Seeking solution to 𝑑��

𝑑𝑡= 𝐴𝜉 𝑜𝑟 𝜉′ = 𝐴𝜉

Let us assume, 𝜉𝑖 = 𝑧𝑖𝑒𝜆𝑡, 𝑖 = 1……𝑛 (𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛)

(This is the most plausible solution to a simple ODE)

or, 𝜉 = 𝑧𝑒𝜆𝑡 (𝜆 = 𝑠𝑐𝑎𝑙𝑎𝑟, 𝑧 = 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝑣𝑒𝑐𝑡𝑜𝑟)

Substitute,

𝑧𝑖𝜆𝑒𝜆𝑡 = 𝑎𝑖1𝑧1𝑒

𝜆𝑡 + 𝑎𝑖2𝑧2𝑒𝜆𝑡 +⋯⋯𝑎𝑖𝑛𝑧𝑛𝑒

𝜆𝑡 (𝑖 = 1⋯⋯⋯𝑛)

or,

𝑎11𝑧1 + 𝑎12𝑧2 +⋯⋯⋯𝑎1𝑛𝑧𝑛 = 𝜆𝑧1⋮ 𝑎𝑛1𝑧1 + 𝑎𝑛2𝑧2 +⋯⋯⋯𝑎𝑛𝑛𝑧𝑛 = 𝜆𝑧𝑛

} 𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛𝑠.

(∑ 𝑎𝑖𝑗𝑧𝑗 = 𝜆𝑧𝑖; 𝑖 = 1, ⋯⋯𝑛)𝑛𝑗=1

or, 𝐴𝑧 = 𝜆𝑧 𝑧𝑇 = [𝑧1⋯⋯𝑧𝑛]

or, (𝐴 − 𝜆𝐼)𝑧 = 0 𝑤ℎ𝑒𝑟𝑒 𝐴 = [

𝑎11 ⋯ 𝑎1𝑛⋮𝑎𝑛1 ⋯ 𝑎𝑛𝑛

]

Thus, we have got a set of homogeneous equations which describes the characteristics of the

system dynamics AND this equation can represent an eigenvalue problem. In summary, we

started from

and got

𝑑��

𝑑𝑡= 𝑓(��)

𝑑𝜉

𝑑𝑡= 𝐴𝜉

Now, we have (𝐴 − 𝜆𝐼)𝑧 = 0}

𝑤ℎ𝑒𝑟𝑒, 𝐴 = 𝐽𝑎𝑐𝑜𝑏𝑖𝑎𝑛 𝑚𝑎𝑡𝑟𝑖𝑥 𝑜𝑓 𝑓 𝑎𝑛𝑑

𝜉 = 𝑧𝑒𝜆𝑡

Therefore, for a non-trivial solution (eigenvalue problem)

det|𝐴 − 𝜆𝐼| = 0 (𝑟 < 𝑚)

Page 40: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

or 𝑑𝑒𝑡 |

𝑎11 − 𝜆 𝑎12 ⋯ 𝑎1𝑛⋮⋮𝑎𝑛1 ⋯ ⋯ 𝑎𝑛𝑛−𝜆

| = 0

Solve for 𝑛 𝜆𝑠′ (eigenvalues) from the 𝑛𝑡ℎ degree polynomial on ′𝜆′ after you have expanded the

(𝑛 × 𝑛) |𝐴 − 𝜆𝐼|matrix to determine its determinant. Recall, every 𝜆𝑖(𝑖 = 1⋯⋯𝑛) will give

one 𝑧(𝑖) eigenvector so that 𝐴𝑧(𝑖) = 𝜆𝑖𝑧(𝑖) . In other words,

𝜆1 → 𝑧(1)𝑒𝜆1𝑡

𝜆2 → 𝑧(2)𝑒𝜆2𝑡

⋮ 𝜆𝑛 → 𝑧(𝑛)𝑒𝜆𝑛𝑡 }

And all these eigenvectors are linearly

independent

Therefore, we have a general solution:

𝜉 = 𝑐1𝑧(1)𝑒𝜆1𝑡 + 𝑐2𝑧

(2)𝑒𝜆2𝑡⋯+ 𝑐𝑛𝑧(𝑛)𝑒𝜆𝑛𝑡

where, 𝑐1, 𝑐2⋯𝑐𝑛 are arbitrary constants to be determined from initial conditions.

{

𝜉1𝜉2⋮𝜉𝑛

} = 𝑐1𝑒𝜆1𝑡 {

𝑧1𝑧2⋮𝑧𝑛

}

(1)

+ 𝑐2𝑒𝜆2𝑡 {

𝑧1𝑧2⋮𝑧𝑛

}

(2)

+⋯𝑐𝑛𝑒𝜆𝑛𝑡 {

𝑧1𝑧2⋮𝑧𝑛

}

(𝑛)

(𝑁𝑜𝑡𝑒 �� = ��𝑠 + 𝜉)

Numerical values of ′𝜆′ decides how solution will behave i.e. error 𝜉 or perturbation or

deviation from SS will grow or decay. If the real part of 𝜆 𝑖𝑠 ′ − 𝑣𝑒′, 𝑦 → 𝑦𝑠 or solution will

decay; if ′ + 𝑣𝑒′ solution will grow ⇒ (unstable)

Example: Study the dynamics

𝑋1′ = −3𝑋1 + 2𝑋2

𝑋2′ = 𝑋1 − 2𝑋2

}

𝐍𝐨𝐭𝐞: If there is a non − homogeneous part inthe equations, ignore it because only homogenous parts

contribute to the growth or decay of the solution.

𝑜𝑟 𝑑��

𝑑𝑡= 𝐴��, 𝐴 = [

−3 2 1 −2

]

Determine 𝜆𝑠: det [−3 − 𝜆 2 1 −2 − 𝜆

] ⇒ 𝜆2 + 5𝜆 + 4 = 0 (𝑐ℎ𝑎𝑟𝑎𝑐𝑡𝑒𝑟𝑖𝑠𝑡𝑖𝑐 𝑝𝑜𝑙𝑦𝑛𝑜𝑚𝑖𝑎𝑙)

𝜆1 = −1, 𝜆2 = −4 (two unique solutions or eigenvalues)

Page 41: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

Determine corresponding eigenvectors:

𝜆1 = −1: [−3 2 1 −2

] {𝑋1𝑋2} = −1 {

𝑋1𝑋2}

or − 3X1 + 2X2 = −X1and X1 − 2X2 = −X2

} ⇒𝑋1 = 𝑋2 ⇒ ��(1) = {

11}

(𝑟 = 1 < 𝑚)

𝜆2 = −4 𝑋1 = −2𝑋2 ⇒ ��(2) = {−2 1}

Check ��1(1) and ��(2) are linearly independent.

⇒ Note: both 𝜆𝑠 are −𝑣𝑒. Therefore, the solutions will decay to the SS values or perturbation

will die/decay, or solutions will not grow, or the systems will be stable.

General solution:

�� = 𝐶1��(1)𝑒𝜆1𝑡 + 𝐶2��

(2)𝑒𝜆2𝑡

𝑜𝑟 {𝑋1𝑋2} = 𝐶1𝑒

−𝑡 {11} + 𝐶2𝑒

−4𝑡 {−2 1}

𝑜𝑟 𝑋1 = 𝐶1𝑒−𝑡 − 2𝐶2𝑒

−4𝑡

𝑋2 = 𝐶1𝑒−𝑡 + 𝐶2𝑒

−4𝑡 }

(Note: For repeat or complex 𝜆, check the books for the methods to determine ��)

Ex. [𝐴] = [ 0 2 3−10 −1 2−2 4 7

] determine all λs and Xs.

From 𝑑𝑒𝑡[𝐴 − 𝜆𝐼] = 0 ⇒ 𝜆1 = 1, 𝜆2 = 2, 𝜆3 = 3

(A 3 × 3 matrix will give 3λs )

𝜆1 = 1 [𝐴 − 𝜆𝐼]�� = 0 ⇒ [ −1 2 3−10 −2 2−2 4 6

] {𝑋1𝑋2𝑋3

} = 0

Apply Gauss Elimination:

[ −1 2 3 0 −22 −28 0 0 0

] {𝑋1𝑋2𝑋3

} = 0

Page 42: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

You will get only 2 independent 𝑒𝑞𝑛𝑠: (𝑟𝑎𝑛𝑘 𝑟 = 2 < 𝑚, 𝑑𝑒𝑡( ) = 0)

𝑋1 = 2𝑋2 + 3𝑋3−22𝑋2 − 28𝑋3 = 0

} ⇒

choose 𝑋3 = 1

𝑋1 = 5 11⁄

𝑋2 = −14 11⁄

Therefore,

��(1) = {5 11⁄

−14 11⁄1

}

Similarly for

𝜆2 = 2: [��(2)]

𝑇= [1 2 − 1 1⁄ ]

𝜆3 = 3: [��(3)]𝑇= [1 2 −3 4⁄ 1⁄ ]

Note: These are all linearly independent vectors (��0(1) ≠ 𝐶1��

(2) + 𝐶2��(3)). They may not be

orthogonal.

Spring-problem (2nd order ODEs can also describe/represent an eigenvalue problem)

𝑋1 𝑋2

𝑚1 𝑚2

𝐾𝑋1 𝐾(𝑋1 − 𝑋2)

Force balance or mass 𝑚1 𝑎𝑛𝑑 𝑚2, when the two blocks are displaced by 𝑋1 & 𝑋2 in the right

direction from its original position:

Page 43: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

𝑚1 𝑑2𝑋1𝑑𝑡2

= −𝐾𝑋1 + 𝐾(𝑋2 − 𝑋1)

𝑚2 𝑑2𝑋2𝑑𝑡2

= −𝐾(𝑋2 − 𝑋1) − 𝐾𝑋2}

�� = {

𝑋1𝑋2}

𝑋𝑖 = 𝐴𝑖𝑠𝑖𝑛(𝜔𝑡) (𝑎𝑠𝑠𝑢𝑚𝑒 𝑎 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛)

( 𝑜𝑟 �� = �� 𝑠𝑖𝑛(𝜔𝑡))

Therefore,

𝑋𝑖′′ = −𝐴𝑖𝜔

2𝑠𝑖𝑛𝜔𝑡

Substitute,

(2𝐾

𝑚1− 𝜔2)𝐴1 −

𝐾

𝑚1𝐴2 = 0

−𝐾

𝑚2𝐴1 + (

2𝐾

𝑚2− 𝜔2) 𝐴2 = 0

}

𝑜𝑟

||(2𝐾

𝑚1− 𝜔2) −

𝐾

𝑚1

−𝐾

𝑚2(2𝐾

𝑚2− 𝜔2)

|| {𝐴1𝐴2} = 0

Therefore, the characteristic equation describes an eigenvalue problem (or spring dynamics is

an eigenvalue problem). It has assumed the form of

(𝐴 − 𝜔2𝐼)�� = 0

where 𝜔2 = 𝜆, 𝐴 = |

2𝐾

𝑚1−

𝐾

𝑚1

−𝐾

𝑚2

2𝐾

𝑚2

| and �� = {𝑋1𝑋2}

𝑒𝑖𝑔𝑒𝑛 𝑣𝑎𝑙𝑢𝑒 𝑒𝑖𝑔𝑒𝑛𝑣𝑒𝑐𝑡𝑜𝑟

Example (From Kreysig's Math book)

𝑚1 = 𝑚2 = 40 𝑘𝑔 ; K = 200𝑁 𝑚⁄

For a non-trivial solution 𝑑𝑒𝑡(𝐴 − 𝜔2𝐼)�� = 0

𝑒𝑞𝑛𝑠: (10 − 𝜔2)𝐴1 − 5𝐴2 = 0

−5𝐴1 + (10 − 𝜔2)𝐴2 = 0

Page 44: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

𝑑𝑒𝑡( ) : (10 − 𝜔2)2 − 25 = 0

𝜆1 = 15, 𝜆2 = 5 𝑜𝑟 𝜔1 = √𝜆1, 𝜔2 = √𝜆2

𝜆1 = 15 𝐴1 = −𝐴2 𝑜𝑟 𝐴(1) = {

1−1}

𝜆2 = 5 𝐴1 = 𝐴2 𝑜𝑟 𝐴(2) = {

11}

General solution:

�� = 𝐶1��(1)𝑠𝑖𝑛𝜔1𝑡 + 𝐶2��

(2)𝑠𝑖𝑛𝜔2𝑡

𝑜𝑟 {𝑋1𝑋2} = 𝐶1 {

1−1} 𝑠𝑖𝑛𝜔1𝑡 + 𝐶2 {

11} 𝑠𝑖𝑛𝜔2𝑡

𝑜𝑟 𝑋1 = 𝐶1𝑠𝑖𝑛𝜔1𝑡 + 𝐶2𝑠𝑖𝑛𝜔2𝑡𝑎𝑛𝑑 𝑋2 = −𝐶1𝑠𝑖𝑛𝜔1𝑡 + 𝐶2𝑠𝑖𝑛𝜔2𝑡

}

Graphical representation of block oscillations:

𝜆1=15

𝜔1=√15 𝐴1 𝐴2

𝜆2=5

𝜔2=√5 𝐴1 𝐴2

Page 45: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #09

One more example of eigenvalue or characteristic type of problem:

Let us revisit Jacobi iteration to invert a matrix.

𝐴�� = ��

⇒ (𝐿 + 𝐷 + 𝑈)�� = ��

⇒ 𝐷�� = �� − (𝐿 + 𝑈)��

𝑜𝑟 �� = 𝐷−1�� − 𝐷−1(𝐿 + 𝑈)��

or �� = 𝑆�� + 𝐶

𝑜𝑟 ��(𝑘+1) = 𝑆��(𝑘) + 𝐶 ∶ 𝐽𝑎𝑐𝑜𝑏𝑖 𝐼𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛 𝑓𝑜𝑟𝑚𝑢𝑙𝑎

S is called stationary matrix because very often, matrix 𝐴 𝑜𝑟 (𝐿, 𝐷, 𝑈) do not change and are

fixed. It is �� (right hand side) that varies from one problem to the other, as a forcing function.

Define, error vector ��(𝑘) = ��(𝑘) − ��

Approximate

𝑣𝑎𝑙𝑢𝑒 𝑎𝑡 𝑖𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛# 𝑘

𝑇𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒

Similarly,

��(𝑘+1) = ��(𝑘+1) − ��

= 𝑆(��(𝑘) − ��) = 𝑆��(𝑘)

𝑜𝑟 ��(𝑘+1) = 𝑆��(𝑘)

𝑜𝑟 ��(𝑘) = 𝑆𝑘 ��(0)

(𝑦𝑜𝑢 𝑠ℎ𝑜𝑢𝑙𝑑 𝑟𝑒𝑎𝑙𝑖𝑧𝑒 𝑡ℎ𝑎𝑡 𝑖𝑡

𝑖𝑠 𝑎𝑛 𝑒𝑖𝑔𝑒𝑛𝑣𝑎𝑙𝑢𝑒 𝑝𝑟𝑜𝑏𝑙𝑒𝑚 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛⁄

𝐴�� = 𝜆�� 𝑤𝑖𝑡ℎ 𝜆 = 1)

For 𝑘 → ∞ 𝑆𝑘 → 0 𝑓𝑜𝑟 𝑐𝑜𝑛𝑣𝑒𝑟𝑔𝑒𝑛𝑐𝑒 𝑏𝑒𝑐𝑎𝑢𝑠𝑒 ��(𝑘) → 0 𝑎𝑠 𝑒(0) ≠ 0

Therefore, criteria for the convergence: 𝑆𝑘 → 0 𝑎𝑠 𝑘 → ∞

Let {𝜈𝑗}𝑗=1,𝑛 be the eigenvectors corresponding to the 𝜆𝑗 eigenvalue of the stationary matrix

Page 46: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

𝑆(𝑛 × 𝑛). Recall eigenvectors are linearly independent. So, they can form the basis of n

dimensional space. Alternatively, any vector can be represented as the linear combination of the

eigenvectors.

Therefore,

𝑒(0) = ∑ 𝑐𝑗𝜈𝑗 𝑛𝑗=1

where Sνj = λjνj

or Sν1 = λ1ν1, etc.

𝑒(1) = 𝑆𝑒(0) = ∑ 𝑐𝑗𝜈𝑗𝜆𝑗 𝑛𝑗=1

𝑒(2) = 𝑆2𝑒(0) = ∑ 𝑐𝑗𝜈𝑗𝜆𝑗2 𝑛

𝑗=1

(𝑢𝑠𝑒 𝑆𝜈𝑗 = 𝜆𝑗𝜈𝑗)

𝑒(𝑘) = ∑ 𝑐𝑗𝜈𝑗𝜆𝑗𝑘 𝑛

𝑗=1

For convergence, 𝑘 → ∞ 𝑒(𝑘) → 0 𝑜𝑟 |𝜆𝑗| < 1 (𝑗 = 1⋯𝑛)

For a 𝑛 × 𝑛 S matrix, there will be 𝜆1 ⋯𝜆𝑛 eigenvalues.

If |𝜆𝑚𝑎𝑥| < 1 𝑡ℎ𝑒𝑛 𝑎𝑙𝑙 𝜆𝑗 < 1

Therefore, for Jacobi Iteration to converge: |𝜆𝑚𝑎𝑥| < 1

(𝑀𝑎𝑥 (𝜆𝑗) ≡ 𝑠𝑝𝑒𝑐𝑡𝑟𝑎𝑙 𝑟𝑎𝑑𝑖𝑢𝑠 𝜌(𝑆) < 1)

There is the Gershgorin Theorem (Check the book by Strang) which states that in such case

∑|𝑎𝑖𝑗| < |𝑎𝑖𝑖|

𝑛𝑜𝑛 − 𝑑𝑖𝑎𝑔𝑜𝑛𝑎𝑙

𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠

𝑑𝑖𝑎𝑔𝑜𝑛𝑎𝑙𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠

Such matrix is said to be diagonally strong. It is a desirable characteristic of a matrix to be

inverted. Compare two extreme situations:

and

non-zero

Note that zero or no iterations are required to solve an identity matrix! Also, a diagonally

strong matrix will require relatively fewer number of iterations. On the other hand, the above

right hand matrix is a singular matrix and cannot be inverted. Similarly, a matrix with smaller

Page 47: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

value-numbers on its diagonal relative to the other elements in the same row will require a

relatively larger number of iterations to converge.

Power Method

The previous examples have shown that the ‘dynamics’ of a 1st order system can be

inspected or characterized by determining 𝜆𝑚𝑎𝑥 𝑎𝑛𝑑 𝜆𝑚𝑖𝑛, instead of all 𝜆𝑠. Therefore, a 𝑛 × 𝑛

matrix will have 𝑛𝜆𝑠, and the overall response of the system will be the least sensitive to

𝜆𝑚𝑖𝑛and most sensitive to 𝜆𝑚𝑎𝑥. The response corresponding to the other 𝜆𝑠 will be

intermediate. Power method is commonly used to determine 𝜆𝑚𝑎𝑥 and also, 𝜆𝑚𝑖𝑛.

If [𝐴]𝑛×𝑛 matrix has 𝑛 𝜆𝑠(𝑒𝑖𝑔𝑒𝑛𝑣𝑎𝑙𝑢𝑒𝑠), then one can write |𝜆1| > |𝜆2| > ⋯⋯ |𝜆𝑛|

𝜆𝑚𝑎𝑥 𝜆𝑚𝑖𝑛

And AX = λmaxX and AX = λminX

Method: Make a guess of 𝑋𝑇 = [1 0 1] 𝑜𝑟 [1 1 0] (say, for a 3 × 3 matrix)

Then 𝐴��(0) ⇒ ��(1)

Use ��(1) = ��(1)

‖��(1)‖=

𝐴𝑋(0)

‖𝐴𝑋(0)‖

(

magnitude (you are scaling or normalizing the vector,

i. e. a |a|⁄ or a √a12 + a2

2 + a32⁄

)

��(𝑘) =𝐴��(𝑘−1)

‖𝐴��(𝑘−1)‖ , 𝑘 = 1, 2,3 (# 𝑜𝑓 𝑖𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛𝑠)

Can be shown that when 𝑘 → ∞ ‖𝐴��(𝑘−1)‖ → |𝜆𝑚𝑎𝑥|

In other words, after sufficient # of iterations, one obtains maximum eigenvalue and the vector

��(𝑘−1) when transformed by ‘A’ matrix does not rotate and is just scaled by 𝜆𝑚𝑎𝑥, i.e.

𝐴��(𝑘−1) = 𝜆𝑚𝑎𝑥��(𝑘)

In other wors, X(k−1) and X(k) have the same directions.

𝜆𝑚𝑎𝑥 ��(𝑘+1)

��(𝑘)

Page 48: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Example: Determine 𝜆𝑚𝑎𝑥 of 𝐴 = [ 0 2 3−10 −1 2−2 4 7

]

𝜈(1) = {100} ≡ [1 0 0]𝑇 (1𝑠𝑡 𝑔𝑢𝑒𝑠𝑠)

𝜈(2) =[ 0 2 3−10 −1 2−2 4 7

]{100}

‖𝐴𝜈(1)‖=

{0

−10−2

}

√100+4= {

0.0000−0.9806−0.1961

}

|𝜆| = √104 = 10.198

𝜈(3) =

[A]{0.0000−0.9806−0.1961

}

‖Aν(2)‖=

{−2.54950.5884−5.2951

}

√2.54952+.58842+5.29512= { }

𝜆2 = 5.9063

After 20 iterations,

𝑋(20) = {−0.3714 0.556980.7428

} with λ(20) = 3.0014

You will see a gradual convergence from 10.198 to 3.0014.

The basics remains the same:

𝐴𝑋(19) = 𝜆𝑚𝑎𝑥𝑋(20) and 𝑋(19) 𝑎𝑛𝑑 𝑋(20) will have approximately the same direction.

It can be shown that 𝝀𝒎𝒊𝒏𝐨𝐟 𝐀 = 𝟏𝝀𝒎𝒂𝒙

⁄ 𝒘𝒉𝒆𝒓𝒆 𝝀𝒎𝒂𝒙 is the highest eigenvalue of the

inverse of matrix 𝑨 𝒐𝒓 𝑨−𝟏:

AX = λmaxX

or X = A−1(λmaxX) = λmax(A−1X)

or A−1X = (1 λmax⁄ )X

or BX ≡ λ′maxX

where B is A−1 and λmin of A is (1λ′max

⁄ ) of B where λ′max is the highest λ of B.

Page 49: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

The λmax to λmin ratio is known as stiffness ratio and indicates the stiffness (maximum rate of

change in the functional value corresponding to λmax relative to minimum rate corresponding to

λmin) of the system. A ratio > 10 indicates the system to be stiff requiring a fine step size for

calculations (to be discussed later)

Notes (From Strang's book):

(1) If X is an eigenvector of A corresponding to 𝜆𝑚𝑎𝑥 and A is invertible, then X is also an

eigenvector of 𝐴−1 corresponding to the inverse of its 𝜆𝑚𝑎𝑥.

(2) Eigenvectors corresponding to different 𝜆𝑠 are linearly independent.

(3) A matrix and its transpose have the same eigenvalues.

(4) A matrix is singular if and only if it has zero 𝜆 . A non-singular matrix has all non zero

𝜆𝑠.

(5) ∑𝜆𝑖 = 𝑡𝑟𝑎𝑐𝑒 𝑜𝑓 𝐴 = ∑ 𝑎𝑖𝑖𝑛𝑖=1

(6) ∏𝜆𝑖 = det (𝐴)

(7) The 𝜆𝑠 of an upper or lower triangular matrix are the elements on its main diagonal.

[It also follows that det A = det (UTM of A) = ∏(𝑎𝑖𝑖)𝑈𝑇𝑀]

Quiz 1

Page 50: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #10

Nonlinear Algebraic Equations

Solving

𝐹1(𝑋1 ⋯ ⋯ 𝑋𝑛) = 0

𝐹2(𝑋1 ⋯ ⋯ 𝑋𝑛) = 0⋮ 𝐹𝑛(𝑋1 ⋯ ⋯ 𝑋𝑛) = 0

} 𝑜𝑟 ��(��) = 0

𝑜𝑟 ��(��) = {𝐹1(��)⋮ 𝐹𝑛(��)

} = 0

where, 𝐹1(��) takes the form such as (𝑋1 − sin 𝑋1) = 0

𝑜𝑟 𝑋1 − sin 𝑋2 = 0

and 𝑋1 = 𝑒𝑋2}

Solving a set of nonlinear algebraic equations is naturally difficult.

Let us begin with solving one nonlinear equation:

𝑓(𝛼) = 0 (𝑅𝑜𝑜𝑡 𝑓𝑖𝑛𝑑𝑖𝑛𝑔) 𝛼 =?

Closed Methods

1. Bracketing method (for a monotonically increasing or decreasing function)

𝑓(𝑋)

𝑓(𝛼) = 0

𝛼

𝑋𝑙1 𝑋𝑙2

𝑋𝑚2 𝑋𝑚1 𝑋𝑈 𝑋

Step 1: Corner the root. Find 𝑋𝑙 𝑎𝑛𝑑 𝑋𝑈 such that

𝑓(𝑋𝑙)𝑓(𝑋𝑈) < 0 ∶

All it means is that one root is cornered or bracketed. Some functions may have multiple

Page 51: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

roots (be careful and corner all three roots separately by plotting the function qualitatively but

accurately).

𝑁𝑜𝑡𝑒: 𝑇ℎ𝑖𝑠 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑡ℎ𝑟𝑒𝑒 𝑟𝑜𝑜𝑡𝑠

𝑏𝑒𝑡𝑤𝑒𝑒𝑛 𝑋𝑙 𝑎𝑛𝑑 𝑋𝑈.

𝑋𝑈

𝑋𝑙

Step 2: 𝑋𝑚(1) =

𝑋𝑈+𝑋𝑙

2= 𝑋𝑜𝑙𝑑

Check f(Xm) = 0. If true, you have the root or Xm = α

If not, check ⇒ if f(Xm)f(Xl) < 0. If true,

XU = Xm (replace XU with Xm)

else Xl = Xm (replace Xl with Xm)

(This way, you are cornering the root or coming closer to the root)

(Note: The other check f(X)f(XU) < 0 will also work. If – ve Xl = Xm else

XU = Xm)

Step 3: Xm(2) =

XU+Xl

2= Xnew (XU & Xl are new values)

{

you can begin errorchecks after 2nditerations only

Check |ξa| = |Xm

new−Xmold

Xmold | × 100 <∈ (specified by user)

else go to step 2 (keep iterating)

till |X(i+1)−X(i)

X(i) | × 100 <∈

Example: Van der Waals gas law/equation:

(P +a

V2) (V − b) = constant

Page 52: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

It is clear that this equation is polynomial in V with 𝑛 = 3.

Let us assume that the other variables and constants are known and the simplified

equation takes the following form:

f(V) = 0

V3 − 0.165V − 3.993 × 10−4 = 0

Calculate V or find the roots

Step 0: Bracket the root: V{0, 0.11} f(V) Xm(1)

Xl = 0, XU = 0.11 by plotting

0.11

1. Check f(Xl)f(XU) < 0 V

So that the root is bracketed (cornered)

2. Xm(1) =

0+0.11

2= 0.055 (3 digits accurate after decimal)

f(0.055)f(0) = 3.993 × 10−4 × 6.655 × 10−5 > 0

(You would have checked whether f(0.055) x f(0.11) < 0 or not as well!)

Xl = 0.055, XU = 0.11 (remains the same)

3. Xm(2) =

Xl+Xu

2=

0.055+0.011

2= 0.0825 = Xnew

f(Xm(2)) = −1.622 × 10−4

Check f(Xl)f(Xm) < 0

XU = 0.0825, Xl = 0.055

4: Check ∈a= |0.0825−0.055

0.055| × 100 = 50.00% > 0.2% (∈s)

Therefore, Xm =0.055+0.0825

2 = 0.00875

Do 10 iterations to obtain Xm = 0.0625 with ∈a= 0.1721% < 0.2%

Page 53: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Ans. V (root) = 0.0625.

You should also prepare a table while solving:

Xl XU Xm ∈ f(Xm)f(Xl)

> < 0

or f(Xm)f(XU)> 0<

}your

decision

1. Yes

2. Xm No

10.

2. False – Position method (Regular-Falsi)

(This method is similar to the previous one, except draw a straight line connecting

XU and Xm to determine the intersection on X axis as the approximate value for the root)

Step1: Bracket root

f(X) f(XU)f(Xl) < 0

2. Xr(1) = XU −

f(XU)

f(Xl) − f(XU)× (Xl − XU)

X (f(XU)

XU − Xr=

0 − f(Xl)

Xr − Xl)

α(root)

Xl Xr(1)

=XUf(Xl) − Xlf(XU)

f(Xl) − f(XU)= Xold

3. Check: f(Xr)f(Xl) < 0 or f(Xr)f(XU) < 0

XU = Xr or Xl = Xr

Xr(2) =

XUf(Xl) − Xlf(XU)

f(Xl) − f(XU)= Xnew

Check ∈a<∈s else go to 2; iterate till convergence. Note that it is difficult to choose

between two methods. In general, this method is faster. There are always exceptions. Try

f(X) = X10 − 1!

Page 54: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

Open Methods

1. Fixed Point Iteration.

Step1. f(X) = 0 ⇒ Modify transform it to⁄

f(X) = X − g(X) = 0

eg. f(X) = X − cos X

or X − eX

(Try for x2 − 1 as X − g(X) = 0 or X = g(X)

Sometimes it is not straight forward & there may be more than one combination.

The working formula is

Y = X = g(X) (2 equations and find its interaction)

Y = X f(X) = 0 split into

Y Y = X and Y = g(X)

Y = g(X)

Therefore, a sequence is generated.

X3X2 X1 X0 Xn+1 = g(Xn)

Sometimes, one has to start from left to the root; sometimes there is a divergence or

spiral convergence, depending on type of functions.

Y or

𝑔(𝑋)

𝑋0 𝑋1𝑋2

fast convergence slow convergence divergence

(spiral)

Criterion for convergence: |𝐠′(𝐗)| < 𝐘′(𝐗) = 𝟏 at 𝐗 = 𝐗𝐧

Page 55: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

Note: Closed methods often generate at least one root. Open methods may sometimes result in

divergence depending upon type of function and starting guess, Xo. However, if they converge,

they will do more quickly than the closed methods.

Step 2: Start with Xo

X1 = g(Xo)

Step 3: Check ∈a= |X1−X0

X1| <∈s

If not, Xold = Xr(iterated value)

Xr = g(Xold)

Check ∈a= |Xr −Xold

Xold| <∈s

Else keep on iterating, keeping in mind the sequence Xn+1 = g(Xn).

2. Newton-Raphson Method

(Most popular method to solve a non-linear algebraic equation)

f(X) = 0 tangent Step1: Choose

tangent Xr = Xo (guess)

2. f ′(Xr) = tangent at Xr = f(Xr)

X0 − X1

X2 X0 X1 = Xr −f(Xr)

f′(Xr)

(Note: f ′(Xr) ≠ 0)

3. If ∈a= |X1−Xr

Xr| × 100 <∈s stop

α = X1 (root)

else Xr = X1 (repeat the steps)

Sequence: Xi+1 = Xi −f(Xi)

f′(Xi); f ′(Xi) ≠ 0

and ∈i+1= |Xi+1−Xi

Xi| × 100

Page 56: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

7

Notes: ⇒

f ′(X) ≠ 0 is the major drawback of the method. There is a price for computing f ′(X)

Simple to code and convergence is fast (see later)

There are cases of divergence and ‘missing’ roots, depending on function and initial guess

divergence

Y missing root

X0

X1 X3 X2X0 X X1

root

In all such cases, the best strategy is to plot and locate all roots graphically (qualitatively but

accurately), and also, start close to the root.

The NR method can be derived from the Taylor series expansion showing the order of error

in the method.

f(Xi+1) = f(Xi) + f ′(Xi)(Xi+1 − Xi) +f′′(Xi)

2!(Xi+1 − Xi)

2 + ⋯ ⋯

≃ f(Xi) + f ′(Xi)(Xi+1 − Xi) + 0(h2)

(error)

If f(Xi+1) = 0, root is located

Xi+1 = Xi −f(Xi)

f′(Xi)

Example (NR) : 𝑓(𝑋) = 𝑋3 − 0.165𝑋2 + 3.993 × 10−4

𝑓′(𝑋) = 3𝑋2 − 0.33𝑋

Step 1. 𝑋0 = 0.05: 𝑃𝑙𝑜𝑡 𝑓(𝑋)𝑎𝑛𝑑 𝑐ℎ𝑜𝑜𝑠𝑒 𝑋0 𝑐𝑙𝑜𝑠𝑒 𝑡𝑜 𝑡ℎ𝑒 𝑖𝑛𝑡𝑒𝑟𝑠𝑒𝑐𝑡𝑖𝑜𝑛 𝑜𝑓 𝑓(𝑋) 𝑤𝑖𝑡ℎ 𝑋 – axis

2. 𝑓′(𝑋0) = 3𝑋02 − 0.33𝑋0

𝑋1 = 𝑋0 −𝑓(𝑋0)

𝑓′(𝑋0)= 0.06242

3. ∈ = |0.06242−0.0500

0.0500| × 100 = 24.84%

Page 57: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

8

4. 𝑋2 = 𝑋1 −𝑓(𝑋1)

𝑓′(𝑋1)= 0.06238

∈ = 0.06411 ⇒ 𝛼 = 0.06238 (𝑟𝑜𝑜𝑡)

(accurate to the 1st significant digit after decimal)

Page 58: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #11

Newton-Raphson (Multi-variables)

F1(X1, X2⋯Xn) = 0

F2(X1, X2⋯Xn) = 0⋮

Fn(X1, X2⋯Xn) = 0

] ⇒F (X) = 𝟎

or Fi(X) = 0, i = 1⋯n or Fi(Xi) = 0, i = 1⋯n

Taylor-expansion of multi-variables:

𝐹1(��(𝑘+1)) ≈ 𝐹1(��

(𝑘)) +𝜕𝐹1𝜕𝑋1

|(𝑋1

(𝑘+1) − 𝑋1(𝑘)) +

��(𝑘) ≠ 𝑋1

𝜕𝐹1𝜕𝑋2

|(𝑋2

(𝑘+1) − 𝑋2(𝑘)) +

��(𝑘) ≠ 𝑋2

⋯⋯𝜕𝐹1𝜕𝑋𝑛

(𝑋𝑛

(𝑘+1) − 𝑋𝑛(𝑘))

��(𝑘) ≠ 𝑋𝑛 (1𝑠𝑡𝑜𝑟𝑑𝑒𝑟 𝑎𝑐𝑐𝑢𝑟𝑎𝑡𝑒)

𝐹2(��(𝑘+1)) ≈ 𝐹2(��

(𝑘)) +𝜕𝐹2𝜕𝑋1

|(𝑋1

(𝑘+1) − 𝑋1(𝑘)) +

��(𝑘) ≠ 𝑋1

𝜕𝐹2𝜕𝑋2

|(𝑋2

(𝑘+1) − 𝑋2(𝑘)) +

��(𝑘) ≠ 𝑋2

⋯⋯𝜕𝐹2𝜕𝑋𝑛

(𝑋𝑛

(𝑘+1) − 𝑋𝑛(𝑘))

��(𝑘) ≠ 𝑋𝑛

.

.

.

𝐹𝑛(��(𝑘+1)) ≈ 𝐹𝑛(��

(𝑘)) +𝜕𝐹𝑛𝜕𝑋1

|(𝑋1

(𝑘+1) − 𝑋1(𝑘)) +

��(𝑘) ≠ 𝑋1

𝜕𝐹𝑛𝜕𝑋2

|(𝑋2

(𝑘+1) − 𝑋2(𝑘)) +

��(𝑘) ≠ 𝑋2

⋯⋯𝜕𝐹𝑛𝜕𝑋𝑛

(𝑋𝑛

(𝑘+1) − 𝑋𝑛(𝑘))

��(𝑘) ≠ 𝑋𝑛

If ��(𝑘+1) = 𝛼 (𝑟𝑜𝑜𝑡 𝑎𝑡 (𝑘 + 1)𝑡ℎ 𝑖𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠) ⇒ 𝐹𝑖(��(𝑘+1)) = 0,

(𝑖 = 1⋯𝑛)

Page 59: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

{

00⋮⋮0}

=

{

𝐹1𝐹2⋮⋮𝐹𝑛}

(𝑘)

+

[ 𝜕𝐹1

𝜕𝑋1

𝜕𝐹1

𝜕𝑋2⋯

𝜕𝐹1

𝜕𝑋𝑛𝜕𝐹2

𝜕𝑋1⋯ ⋯ ⋯

⋮⋮𝜕𝐹𝑛

𝜕𝑋1

𝜕𝐹𝑛

𝜕𝑋2⋯

𝜕𝐹𝑛

𝜕𝑋𝑛] (𝑘)

{

∆𝑋1∆𝑋2⋮⋮

∆𝑋𝑛}

(∆𝑋1 = 𝑋1(𝑘+1) − 𝑋1

(𝑘), 𝑒𝑡𝑐)

𝑜𝑟

[ 𝜕𝐹1

𝜕𝑋1⋯

𝜕𝐹1

𝜕𝑋𝑛

⋮𝜕𝐹𝑛

𝜕𝑋1⋯

𝜕𝐹𝑛

𝜕𝑋𝑛] (𝑘)

{∆𝑋1⋮

∆𝑋𝑛

} = − {𝐹1⋮𝐹𝑛

}

(𝑘)

𝑜𝑟 𝐽𝐽 ∆��(𝑘) = −𝐹 (𝑘)

𝑜𝑟 ∆��(𝑘) = − 𝐽𝐽 −1𝐹 (𝑘)

𝑜𝑟 ��(𝑘 + 1) = ��(𝑘) − 𝐽𝐽 −1𝐹 (𝑘) ⇒ Multi-variable NR method (similar in form to single

variable NR method)

Example: 𝐹1(��) = 4 − 8𝑌1 + 4𝑌2 − 2𝑌13 = 0

𝐹2(��) = 1 − 4𝑌1 + 3𝑌2 + 𝑌22 = 0

Starting guess values

��(1) = [𝑌1 𝑌2]𝑇(1) = [0.5 0.5]𝑇

Apply NR multivariable method formula:

��(𝑘+1) = ��(𝑘) − 𝐽��−1𝐹 (𝑘)

𝑜𝑟 {𝑌1𝑌2}(𝑘+1)

= {𝑌1𝑌2}(𝑘)

[ 𝜕𝐹1𝜕𝑌1

𝜕𝐹1𝜕𝑌2

𝜕𝐹2𝜕𝑌1

𝜕𝐹2𝜕𝑌2]

−1

{𝐹1𝐹2}(𝑘)

Page 60: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

{𝑌1𝑌2}1

= {0.50.5} − [

(−8 − 6𝑌12) 4

−4 (3 + 2𝑌2)]−1

{𝐹1𝐹2}0.5,0.5

= {0.50.5} − [

−9.5 4−4 4

]−1

{1.750.75

}

= {0.50.5} +

1

22[ 4 −4 4 −9.5

] {1.750.75

}

(Note: For 𝟐 × 𝟐 matrix simple Cramer’s rule was applied to determine the inverse of

the matrix, else apply 𝑮 − 𝑱 𝒐𝒓 𝑳𝑼 decomposition method can be used for a large size

matrix)

𝑌1(1) = 0.5 +

1

22(4 × 1.75 − 4 × 0.75) = 0.6818

𝑌2(1) = 0.5 +

1

22(4 × 1.75 − 9.5 × 0.75) = 0.4943

- Continue iteration till there is a convergence. One can prepare a table like this:

# 𝑌1 𝑌2 𝐹1 𝐹2 𝜕𝐹1

𝜕𝑌1

𝜕𝐹1

𝜕𝑌2

𝜕𝐹2

𝜕𝑌1

𝜕𝐹2

𝜕𝑌2 𝑌1 𝑌2 ∈𝑎1 ∈𝑎2

1

2

Secant Method

(Another common open method; it does not require derivative to compute. Requires two

starting adjacent guess values instead)

Step1:

Straight line: Choose 𝑋𝑖−1 𝑎𝑛𝑑 𝑋𝑖 adjacent guess values near the root ′𝛼′.

2. Draw straight line connecting 𝑓(𝑋𝑖−1) 𝑎𝑛𝑑 𝑓(𝑋𝑖). Find

𝑓(𝑥) intersection on X axis → 𝑋𝑖+1

′𝛼′ 𝑓′(𝑋𝑖+1) =𝑓(𝑋𝑖)

𝑋𝑖−𝑋𝑖+1=

𝑓(𝑋𝑖−1)

𝑋𝑖−1−𝑋𝑖+1

𝑋𝑖+1 𝑋 𝑋𝑖+1 = 𝑋𝑖 − 𝑓(𝑋𝑖) ×(𝑋𝑖−𝑋𝑖−1)

𝑓(𝑋𝑖)−𝑓(𝑋𝑖−1)

𝑜𝑟 𝑋𝑖+1 = 𝑋𝑖 −𝑓(𝑋𝑖)

𝑓(𝑋𝑖)−𝑓(𝑋𝑖−1)

𝑋𝑖−𝑋𝑖−1

: sequence

Page 61: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Check if 𝑓(𝑋𝑖+1) → (𝑦𝑜𝑢 ℎ𝑎𝑣𝑒 ℎ𝑖𝑡 𝑡ℎ𝑒 𝑟𝑜𝑜𝑡), else repeat with 𝑋𝑖 𝑎𝑛𝑑 𝑋𝑖+1 following

the above sequence.

The method converges faster than Bisection method, but slower that NR. It is preferred

over NR to avoid 𝑓′ = 0.

If 𝑋𝑖 → 𝑋𝑖−1, note 𝑋𝑖+1 = 𝑋𝑖 −𝑓(𝑋𝑖)

𝑓′(𝑋𝑖) (same as NR!)

At this stage, let us look at Taylor’s series. Any function f(X) can be expanded as:

𝑓(𝑋) = 𝑓(𝑋0) + 𝑓′(𝑋0)(𝑋 − 𝑋0) +

𝑓′′(𝑋0)

2!(𝑋 − 𝑋0)

2 +⋯𝑓𝑛(𝑋0)(𝑋−𝑋0)

𝑛

𝑛!+⋯ 𝑡𝑜 ∞

exact

or, 𝑓(𝑋𝑖+1) = 𝑓(𝑋𝑖) + 𝑓′(𝑋𝑖)(𝑋 − 𝑋𝑖) +

𝑓′′(𝑋𝑖)

2!(𝑋𝑖+1 − 𝑋𝑖)

2 +⋯𝑓𝑛(𝑋𝑖)(𝑋𝑖+1−𝑋𝑖)

𝑛

𝑛!+⋯ 𝑡𝑜 ∞

exact

≈ 𝑓(𝑋𝑖) +𝑓′(𝑋𝑖)(𝑋𝑖+1−𝑋𝑖)

1!+𝑓′′(𝑋𝑖)(𝑋𝑖+1−𝑋𝑖)

2

2!+⋯0(ℎ3)

approximate

or truncation error is 0(ℎ3) (accurate to 2nd order)

≈ 𝑓(𝑋𝑖) +𝑓′(𝑋𝑖)(𝑋𝑖+1−𝑋𝑖)

1!+ 0(ℎ2)

approximate

(accurate to 1st order or truncation error is 0(ℎ2))

(error is one order greater than the accuracy of the method)

= 𝑓(𝑋𝑖) + 𝑓′(𝑋𝑖)(𝑋𝑖+1 − 𝑋𝑖) + ⋯

𝑓𝑛(𝑋𝑖)(𝑋𝑖+1−𝑋𝑛)𝑛

𝑛!+ 𝑅𝑛+1

exact!

where, 𝑅𝑛+1 =𝑓𝑛+1(𝜉)(𝑋𝑖+1−𝑋𝑛)

𝑛+1

𝑛+1! (𝑐𝑎𝑛 𝑏𝑒 𝑒𝑥𝑎𝑐𝑡𝑙𝑦 𝑑𝑒𝑡𝑒𝑟𝑚𝑖𝑛𝑒𝑑)

However, 𝜉 is ‘some’ number between 𝑋𝑖+1𝑎𝑛𝑑 𝑋𝑖.

Therefore,

𝑓(𝑋𝑖+1) = 𝑓(𝑋𝑖) +𝑓′(𝑋𝑖)(𝑋𝑖+1−𝑋𝑖)

1!+𝑓2(𝜉)(𝑋𝑖+1−𝑋𝑖)

2

2!

exact

Page 62: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

= 𝑓(𝑋𝑖) +𝑓′(𝜉)(𝑋𝑖+1−𝑋𝑖)

1! (1st Mean Value Theorem)

exact

In other words, 𝑓′(𝜉) =𝑓(𝑋𝑖+1)−𝑓(𝑋𝑖)

(𝑋𝑖+1−𝑋𝑖)

All it means there is ′𝜉′ somewhere between 𝑋𝑖𝑎𝑛𝑑 𝑋𝑖+1, where the tangent equals the divided

difference between two end points 𝑋𝑖 − 𝑋𝑖+1.

Note: Taylor series is used to determine the error or accuracy of a numerical method, or to

determine the convergence of the method.

Convergent Analysis

Fixed Point Iteration method

𝑓(𝑋) = 𝑋 − 𝑔(𝑋)

𝑜𝑟 𝑋(𝑛+1) = 𝑔(𝑋(𝑛)) (𝑖𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛)

If 𝛼 is the root then 𝛼 − 𝑔(𝛼) = 0

Error at (𝑛 + 1)𝑡ℎ iteration =|True Value − Approximate Value|

𝑒𝑛+1 = |𝛼 − 𝑋(𝑛+1)|

= |𝑔(𝛼) − 𝑔(𝑋(𝑛))|

= |𝑔′(��)(𝛼 − 𝑋(𝑛)| ∶ Recall Mean Value Theorem. X is between

α and X(n)

= |𝑔′(��)𝑒𝑛|

𝑒𝑛+1

𝑒𝑛= |𝑔′(��)| < 1 for error to decrease as 𝑛 → ∞ where �� is {𝛼, 𝑋𝑛}

NR Convergent

𝑋𝑘+1 = 𝑋𝑘 −𝑓𝑘

𝑓𝑘′ ; 𝑓𝑘

′ ≠ 0

𝑒(𝑘+1) = |𝛼 − 𝑋𝑘+1| = |𝛼 − 𝑋𝑘 +𝑓𝑘

𝑓𝑘′|

Page 63: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

𝑓(𝑋𝑘+1) = 𝑓(𝑋𝑘) + 𝑓𝑘′(𝑋𝑘+1 − 𝑋𝑘) + 𝑓′′(��)

(𝑋𝑘+1−𝑋𝑘)2

2!

exact (��: {𝑋𝑘, 𝑋𝑘+1})

If 𝑋𝑘+1 is the root (𝛼)

0 = 𝑓(𝑋𝑘) + 𝑓𝑘′(𝛼 − 𝑋𝑘) +

(𝛼 − 𝑋𝑘)2

2!𝑓′′(��)

∴ 𝑒(𝑘+1) = |𝑓′′(��)

2𝑓′𝑘

(𝛼 − 𝑋𝑘)2|

= |𝑓′′(��)

2𝑓′𝑘(𝑒𝑘)2|

𝑒(𝑘+1)

(𝑒𝑘)2= |

𝑓′′(��)

2𝑓′(𝛼)| ; 𝑓′(𝛼) ≠ 0

If 𝑘 → ∞ 𝑒(𝑘+1) decreases by the square of the error in the previous step. In other words, the

method has quadratic convergence (fast convergence), although the method is only 1st order

accurate. This is the special feature of NR method.

Page 64: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #12

Function Approximation: Interpolation

Fit a line passing through the data points to

predict the functional value at an intermediate interpolated value

data. The line must pass through the data. The method is used

to interpolate, for example, certain properties such as enthalpy and

vapour pressure, at an intermediate point where the functional 𝑓𝑖

values or properties are not available.

Therefore, the data provided for the interpolation must

be reliable/accurate. 𝑋𝑖

- Mathematically, interpolating function must be smooth

(differential); continuous and pass through all data points.

- Compare it to ‘regression’ (best fit to the data) when the line need not pass through each

data. Regression is used for prediction when data are experimentally measured or

approximately calculated. Therefore, the regressed data may have errors.

Yi experimental data

𝑓𝑖

𝑋𝑖

- (No regression topic to be covered in this course; no extrapolation as well!)

The main motivation for developing an interpolating function is not only to predict the

functional value at an interpolating/intermediate point, but also to approximate a continuous f(x)

or a discrete data set, y(x) as the nth degree polynomial, Pn(x); thus the name of the current topic:

function approximation. You will see in the later lessons that once you have your own

approximated simple Pn(x), you will forgo the complex f(x) and work on Pn(x) instead, not only

for calculating functional values at the intermediate points but also for computing f’(x) and f’’(x)

as Pn’(x) and Pn’’(x), respectively. Also, all formulae for integration are also derived from Pn(x).

Page 65: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

Interpolating function for ‘n’ data points

𝑃𝑛−1(𝑋) = 𝑎𝑛−1𝑋𝑛−1 + 𝑎𝑛−2𝑋

𝑛−2 +⋯𝑎0: a polynomial of degree (𝑛 − 1).

If there are ‘n’ data points, a unique polynomial of degree (n-1) passes through the points:

Ex. 1. 𝑦 = 𝑚𝑥 + 𝑏 (1st order polynomial) passing through two data points. Two unknown &

two equations to solve m and b:

2. Three data points

y = ax2 + bx + c (2nd order polynomial, a quadratic equation)

(3 equations to solve three unknowns 𝑎, 𝑏 & 𝑐)

3. Thus, ‘n’ data points will have a 𝑢𝑛𝑖𝑞𝑢𝑒 polynomial of degree (n − 1) passing through the

points.

𝑦 = 𝑎𝑛−1𝑥𝑛−1 + 𝑎𝑛−2𝑥

𝑛−2 +⋯⋯𝑎0

Therefore,

𝑦1 = 𝑎𝑛−1𝑥1𝑛−1 + 𝑎𝑛−2𝑥1

𝑛−2 +⋯⋯𝑎0𝑦2 = 𝑎𝑛−1𝑥2

𝑛−1 + 𝑎𝑛−2𝑥2𝑛−2 +⋯⋯𝑎0

⋮ 𝑦𝑛 = 𝑎𝑛−1𝑥𝑛

𝑛−1 + 𝑎𝑛−2𝑥𝑛𝑛−2 +⋯⋯𝑎0}

nequations

or

{

𝑦1𝑦2⋮𝑦𝑛

} = ||

1 𝑥1 𝑥12 ⋯ 𝑥1

𝑛−1

1 𝑥2 𝑥22 ⋯ 𝑥2

𝑛−1

⋮1 𝑥𝑛 𝑥𝑛

2 𝑥𝑛𝑛−1

|| {

𝑎0⋮⋮

𝑎𝑛−1

}

Although the problem is well defined, it is tedious to solve (𝑎0⋯⋯𝑎𝑛−1) from a large sized 𝑛 ×

𝑛 matrix.

�� = 𝐴𝑛×𝑛��

The common methods to fit 𝑃𝑛−1 polynomial passing through ‘n’ data points, or 𝑃𝑛 through

(n + 1) data points:

(1) Newton’s divided-difference scheme

Consider 2 data points

Let a line pass through (𝑋0, 𝑌0) & (𝑋1, 𝑌1):

P2

Page 66: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

𝑌 − 𝑌0𝑋 − 𝑋0

=𝑌1 − 𝑌0𝑋1 − 𝑋0

or 𝑌 = 𝑌0 +𝑌1−𝑌0

𝑋1−𝑋0(𝑋 − 𝑋0)

𝑜𝑟 𝑌 = 𝑎0 + 𝑎1(𝑋 − 𝑋0)

{

where a0 = Y0

a1 =Y1−Y0

X1−X0= Y(X1, X0) defined as

Newton First DividedDifference(N1DD)

Similarly, define

𝑌[𝑋2, 𝑋1, 𝑋0] ≡ Newton 2nd divided difference

=𝑌[𝑋2, 𝑋1] − 𝑌[𝑋1, 𝑋0]

𝑋2 − 𝑋0 (𝑁2𝐷𝐷)

𝑌[𝑋𝑛, 𝑋𝑛−1, ⋯𝑋0] =𝑌[𝑋𝑛, 𝑋𝑛−1, ⋯𝑋1] − 𝑌[𝑋𝑛−1, 𝑋𝑛−2,⋯𝑋0]

𝑋𝑛 − 𝑋0 (𝑁𝑛𝐷𝐷)

Take 3 data points (𝑋0, 𝑋1, 𝑋2):

𝑌(𝑋) ≡ 𝑃2(𝑋) = 𝑎0 + 𝑎1(𝑋 − 𝑋) + 𝑎2(𝑋 − 𝑋0)(𝑋 − 𝑋1)

By fitting 𝑃2(𝑋) to three data points, the three coefficients

can be determined as

𝑎0 = 𝑌0, 𝑎1 =𝑌1−𝑌0

𝑋1−𝑋0≡ 𝑌[𝑋1, 𝑋0]

and 𝑎2 =𝑌[𝑋2,𝑋1]−𝑌[𝑋1,𝑋0]

𝑋2−𝑋0≡ 𝑌[𝑋2, 𝑋1, 𝑋0]

Similarly for (n+1) data

𝑌(𝑋) 𝑜𝑟 𝑃𝑛(𝑋)

= 𝑎0 + 𝑎1(𝑋 − 𝑋0) + 𝑎2(𝑋 − 𝑋0)(𝑋 − 𝑋1) + ⋯𝑎𝑛(𝑋 − 𝑋0)(𝑋 − 𝑋1)⋯ (𝑋 − 𝑋𝑛−1)

where 𝑎0 = 𝑌0

𝑎1 = 𝑌[𝑋1, 𝑋0] =𝑌1−𝑌0

𝑋1−𝑋0 (1st divided difference)

𝑎𝑛 = 𝑌[𝑋𝑛, 𝑋𝑛−1⋯𝑋0] ( nthdivided difference )

Y1

Y

Y0

X0 X1

X

X0 X1 X2

Xi

Y0

Y2

Yi Y1

Page 67: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

(Substitute x = x0, x1, x2…xn in Pn(x) to explore the sequence of polynomial)

In the tabular form,

𝑖 𝑋𝑖 𝑌𝑖 1𝑠𝑡 2𝑛𝑑 ⋯⋯ 𝑛𝑡ℎ

{

0 𝑋0 𝑌0 1 𝑋1 𝑌1 2 𝑋2 𝑌2 ⋮ 𝑛 − 1 𝑋𝑛−1 𝑌𝑛−1 𝑛 𝑋𝑛 𝑌𝑛

𝑎𝑛 = (𝑌[𝑋𝑛,⋯𝑋1]

−𝑌[𝑋𝑛−1, ⋯𝑋0])𝑋𝑛 − 𝑋0

Note: Top row (circles) provides all NDD coefficients, ao, a1, a2….

2. Lagrangian Interpolation

𝑦(𝑥) = ∑ 𝑙𝑘(𝑥) 𝑦𝑘𝑛𝑘=0 (𝑛 + 1 𝑑𝑎𝑡𝑎)

Lagrangian coefficient of the kth term

Function must be a linear combination of 𝑦𝑘.

𝑙𝑘(𝑥) must not depend on 𝑦𝑘

𝑙𝑘(𝑥) is defined as 𝑙𝑗(𝑥𝑖) = 𝛿𝑖𝑗 (Kronecker delta)

= 1 when i = j and 0 when i ≠ j

Propose, lj(𝑥) = 𝐶𝑗(𝑥 − 𝑥0)(𝑥 − 𝑥1)⋯ (𝑥 − 𝑥𝑗−1)(𝑥 − 𝑥𝑗+1)⋯ (𝑥 − 𝑥𝑛), and

= 0 (𝑥 ≠ 𝑥𝑗)

= 1 (𝑥 = 𝑥𝑗)

Therefore, 𝐶𝑗 = (𝑥𝑗 − 𝑥0)−1(𝑥𝑗 − 𝑥1)

−1⋯(𝑥𝑗 − 𝑥𝑗−1)

−1(𝑥𝑗 − 𝑥𝑗+1)

−1⋯(𝑥𝑗 − 𝑥𝑛)

−1

and, 𝑙𝑗(𝑥) =(𝑥 − 𝑥0)(𝑥 − 𝑥1)⋯ (𝑥 − 𝑥𝑗−1)(𝑥 − 𝑥𝑗+1)⋯ (𝑥 − 𝑥𝑛)

(𝑥𝑗 − 𝑥0)(𝑥𝑗 − 𝑥1)⋯(𝑥𝑗 − 𝑥𝑗−1)(𝑥𝑗 − 𝑥𝑗+1)⋯ (𝑥𝑗 − 𝑥𝑛)

The interpolating function is as follows:

𝑌𝑛(𝑥) = ∑ 𝑙𝑘(𝑥)𝑌𝑘 ≡ 𝑃𝑛

𝑛

𝑘=0

where

𝑙𝑗(𝑥) = ∏(𝑥 − 𝑥𝑖)

(𝑥𝑗 − 𝑥𝑖)

𝑛

𝑖=0(𝑖≠𝑗)

Page 68: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

Suppose 2 data points: (𝑋0, 𝑌0) and (𝑋1, 𝑌1)

Y1(x) = l0(x)Y0 + l1(x)Y1

l0 =x−x1

x0−x1, l1 =

x−x0

x1−x0

or Y1(x) = (x−x1

x0−x1) Y0 + (

x−x0

x1−x0) Y1

(Since 𝑌1(𝑥) is unique, it cannot be different from Newton-Divided difference formula; only

forms are different)

Suppose there are 3 data points: (X0, Y0), (X1, Y1), and (X2, Y2)

𝑌2(𝑥) = 𝑙0(𝑥)𝑌0 + 𝑙1(𝑥)𝑌1 + 𝑙2(𝑥)𝑌2

𝑙0(𝑥) =(𝑥 − 𝑥1)(𝑥 − 𝑥2)

(𝑥0 − 𝑥1)(𝑥0 − 𝑥2); 𝑙1(𝑥) =

(𝑥 − 𝑥0)(𝑥 − 𝑥2)

(𝑥1 − 𝑥0)(𝑥1 − 𝑥2) ,

𝑌(𝑥) =(𝑥 − 𝑥1)(𝑥 − 𝑥2)

(𝑥0 − 𝑥1)(𝑥0 − 𝑥2)𝑌0 +

(𝑥 − 𝑥0)(𝑥 − 𝑥2)

(𝑥1 − 𝑥0)(𝑥1 − 𝑥2)𝑌1 +

(𝑥 − 𝑥0)(𝑥 − 𝑥1)

(𝑥2 − 𝑥0)(𝑥2 − 𝑥1)𝑌2

≡ 𝑠𝑎𝑚𝑒 𝑎𝑠 𝑁𝐷𝐷𝐸 𝑜𝑟 𝑎𝑋2 + 𝑏𝑋2 + 𝑐

Ex. 𝑋1 𝑋2 𝑋 𝑋3

Depth (m) -1 0 0.5 1.0

𝑌(𝑡0𝑐) 10.1 11.3 ? 11.9

𝑌2(𝑥) = 𝐶0 + 𝐶1𝑥 + 𝐶2𝑥2 (unique)

3 data points and 3 eqns to solve Cs:

[1 −1 11 0 01 1 1

] {𝐶0𝐶1𝐶2

} = {10.111.311.9

}…….>Solve by any previously learnt method to obtain

𝐶0 = 11.3, 𝐶1 = 0.9, 𝑎𝑛𝑑 𝐶2 = −0.3 ⇒ 𝑌(0.5) = 11.675

(1) 𝑁𝐷𝐷 1𝑠𝑡𝐷𝐷: 𝑌[𝑋0, 𝑋1] 2𝑛𝑑𝐷𝐷: 𝑌[𝑋0, 𝑋1, 𝑋2]

𝑋0 − 1 10.1 11.3−10.1

0+1= 1.2

1.2−0.6

−1−1= −0.3

𝑋1 0 11.3 11.9−11.3

1−0= 0.6

𝑋2 1 11.9

(X,Y) (X1,Y1)

(X0,Y0)

Page 69: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

Therefore, Y2(x) = a0 + a1(x − x0) + a2(x − x0)(x − x1)

a0 = Y0 = 10.1, a1 = FDD = 1.2, a2 = SDD = −0.3

= 10.1 + 1.2(x + 1) − 0.3(x + 1)x

- (Same as before, check) Y(0.5) = 11.675

(2) Lagrange Y2(x) = ∑ lkYk2k=0 ; lj(x) = ∏ (

x−xi

xj−xi)2

i=0i≠j

l0(x) =(x−x1)(x−x2)

(x0−x1)(x0−x2); l1(x) =

(x−x0)(x−x2)

(x1−x0)(x1−x2) , etc.

Y2(x) =(x − 0)(x − 1)

−1 × −2× 10.1 +

(x + 1)(x − 1)

1 × −1× 11.3 +

(x + 1)x

2 × 1× 11.9

- (Same as before, check) Y(0.5) = 11.675

Note: ⇒ If ‘n’ is large, (> 4), the polynomial shows oscillation. In principle, one uses ‘piece-

wise’ interpolation for large # of data points.

⇒ Less smooth if data points are less or sparse.

⇒ ‘Problem’ at the end points.

⇒ NDD uses the previous calculations, if an extra point is to be included in finding a new

polynomial, unlike each coefficient has to be recalculated in ‘LI’. However, it is easy to

program ‘LI’.

Error analysis: For (n+1) data points, 𝑃𝑛(𝑜𝑟𝑑𝑒𝑟 𝑛) is the unique polynomial to pass through

(n+1) data points. This polynomial can be used to predict 𝑃𝑛(𝑋) at a new data points ‘X’.

How much error can be expected in this prediction/interpolation? From engineering point of

view, how much confidence an user has in the interpolated functional value? Well, in such

case one should use an additional data (𝜉, 𝑌(𝜉)) over the range (𝑋0⋯𝑋𝑛) and check the

convergence in the re-interpolated value at 𝑃𝑛+1(𝑋). Note, now you have (n+2) data points

including 𝜉.

Theoretically, it can be shown using Taylor’s series that the error in the interpolation using

𝑃𝑛(𝑋) for (n+1) data is

𝑦𝑛+1(𝜉)

𝑛+1!(𝑥 − 𝑥0)(𝑥 − 𝑥1)⋯⋯(𝑥 − 𝑥𝑛)

where (𝑥0 < 𝜉 < 𝑥𝑛)

additional data pt.

Page 70: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

7

You should have also noted that

𝑦[𝑥0, 𝑥1] =𝑦(𝑥1)−𝑦(𝑥0)

𝑥1−𝑥0= 𝑦′ (accurate to the 1st order)

𝑦[𝑥0, 𝑥1, 𝑥2] = ⋯⋯ = 𝑦′′ (accurate to the 2nd order)

and 𝑦[𝜉, 𝑥0, 𝑥1, ⋯ 𝑥𝑛] =𝑌[𝜉,⋯𝑥𝑛−1]−𝑌[𝑥0,⋯𝑥𝑛]

𝜉−𝑥𝑛= 𝑦𝑛+1(𝜉)

Therefore, the error calculated is nothing but 𝑅𝑛+1(remainder) of the Taylor’s series. For

more on this, read the book by Ferziger.

Page 71: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #13

Similar to the Newton’s Divided Difference and Lagrangian interpolation schemes, there is the

Newton’s interpolation formula that makes use of ′Δ′ operator (Forward Difference Operator)

Δ𝑦(𝑥) = 𝑦(𝑥 + Δ𝑥) − y(𝑥) ∶ 𝐹𝑜𝑟𝑤𝑎𝑟𝑑 − 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝑜𝑝𝑒𝑟𝑎𝑡𝑜𝑟

{

𝐸 𝑦(𝑥) = 𝑦(𝑥 + Δ𝑥) ∶ 𝑆ℎ𝑖𝑓𝑡 𝑂𝑝𝑒𝑟𝑎𝑡𝑜𝑟

𝐸2𝑦(𝑥) = 𝐸[𝑦(𝑥 + Δ𝑥)] = 𝑦(𝑥 + 2Δ𝑥)

𝐸𝑛𝑦(𝑥) = 𝑦(𝑥 + 𝑛Δ𝑥)

Therefore, Δ𝑦(𝑥) = 𝐸𝑦(𝑥) − 𝑦(𝑥) = (𝐸 − 1)𝑦(𝑥)

𝑜𝑟 𝐸 = 1 + Δ ∶ 𝐸 & Δ operators

𝑜𝑟 𝐸𝛼 = (1 + Δ)𝛼 = 1 + 𝛼Δ +𝛼(𝛼 − 1)

2! Δ2 +⋯

𝛼(𝛼 − 1)⋯ (𝛼 − 𝑛 + 1)

𝑛! Δn+. ..

𝑜𝑟 𝐸𝛼𝑦(𝑥0) = 𝑦(𝑥0 + 𝛼Δ𝑥) = (1 + Δ)𝛼𝑦(𝑥0)

= 𝑦0 + 𝛼Δ𝑦0 +𝛼(𝛼−1)

2! Δ2𝑦0 +⋯

𝛼(𝛼−1)⋯(𝛼−𝑛+1)

𝑛! Δn𝑦0 +

If 𝛼 =𝑥−𝑥0

Δ𝑥

𝑦(𝑥) = 𝑦(𝑥0 + 𝛼Δ𝑥) = 𝑦0 + 𝛼(Δ𝑦0) + 𝛼(𝛼−1)

2! Δ2𝑦0 +⋯

𝛼(𝛼−1)⋯(𝛼−𝑛+1)

𝑛! Δn𝑦0 + 𝑅

𝑅 =𝛼(𝛼−1)(𝛼−𝑛)

(𝑛+1)!Δn+1𝑦(𝜉) 𝑤ℎ𝑒𝑟𝑒 𝑥𝑜 < 𝜉 < 𝑥𝑛

- Newton Forward-Difference Interpolation formula

In general

Δ𝑦𝑖 = y(𝑥𝑖 + Δ𝑥) − 𝑦(𝑥𝑖) = 𝑦𝑖+1 − 𝑦𝑖Δ2𝑦𝑖 = Δ(Δ𝑦𝑖) = 𝑦𝑖+2 − 2𝑦𝑖+1 + 𝑦𝑖

}

Similar to ′Δ′, ∇ has been defined as backward difference operator:

∇𝑦𝑖 = 𝑦𝑖 − 𝑦𝑖−1 𝑜𝑟 ∇𝑦(𝑥) = 𝑦(𝑥𝑛 + 𝛼Δ𝑥), where α =x−xn

Δx

And, therefore, there is another Newton’s interpolation formula! Again, note that all

interpolating functions are one and the same, but written in different forms. Considering that the

Newton’s interpolation formula resembles Taylor’s series, it can also be used for error analysis.

To this end, we have learnt how to approximate f(x) or y(x) with Pn(x). We will see later

f’(x) or y’(x) and f’’(x) or y’’(x) will be approximated with P’n(x) and Pn”(x), respectively.

Page 72: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

Splines

We have earlier noted that a high order polynomial (𝑛 ≥ 4) often shows oscillation. Therefore,

a piece-wise polynomial (𝑛 ≤ 3) is usually preferred for most engineering applications.

→ ‘Spline’ is a piece-wise cubic polynomial (𝑦 = 𝑎𝑥3 + 𝑏𝑥2 + 𝑐𝑥 + 𝑑) fitting 2 data

points in segments or pieces. Is it unique? No. Because there are two extra degrees of freedom.

In other words, two extra constraints or conditions may be imposed.

→ Let us define the problem:

𝑆𝑖 = 𝑎𝑖𝑥3 + 𝑏𝑖𝑥

2 + 𝑐𝑖𝑥 + 𝑑𝑖 is the spline fitting the data 𝑥𝑖 𝑎𝑛𝑑 𝑥𝑖+1 . Thus, it is a

higher order polynomial for two data points.

(1) Each spline (𝑆𝑖) is a piece-wise cubic.

(2) Curve must pass through the points (𝑥𝑖 & 𝑥𝑖+1)

(3) 𝑓𝑖′𝑎𝑛𝑑 𝑓𝑖′′ are continuous at all ‘knots’, i.e, curve is smooth and curvature is the same

at all nodes.

or

𝑆𝑖−1(𝑥𝑖) = 𝑆𝑖(𝑥𝑖)

𝑆′𝑖−1(𝑥𝑖) = 𝑆𝑖′(𝑥𝑖)

𝑆𝑖−1′′(𝑥𝑖) = 𝑆𝑖′′(𝑥𝑖)} ≡

𝑆+ = 𝑆−

𝑆′+ = 𝑆′−

𝑆′′+ = 𝑆′′−}

Therefore, for n data points there are (n-1) spline segments or 4(n-1) unknown quantities

(coefficients) to be determined:

Equations: 𝑦𝑖 = 𝑆𝑖(𝑥𝑖) ∶ 𝑛

𝑆+ = 𝑆− ∶ (𝑛 − 2) ∶ only interior pts.

𝑆′+ = 𝑆′− ∶ (𝑛 − 2)

𝑆′′+ = 𝑆′′− ∶ (𝑛 − 2)

4𝑛 − 6

You have two BCs specified at the end data points or knots.

Therefore, there are as many (4n-4) equations as # of unknowns.

The problem is now well defined:

Si-1 Si

Si+1

xi-1 xi xi+1

Page 73: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

𝑆𝑖(𝑥) = ∑ 𝑎𝑖𝑥𝑖3

𝑖=0 = ?

Note that 𝑆𝑖"(𝑥) is a piece-wise linear and continuous (i. e. 𝑆𝑖"(𝑥) = 6𝑎𝑖𝑥 + 2𝑏𝑖)

𝑆𝑖"(𝑥)

𝑥𝑖 𝑥𝑖+1

𝑆𝑖(𝑥) ≡ 𝑐𝑢𝑏𝑖𝑐

Therefore, 𝑆𝑖”(𝑥) = ∑ 𝑙𝑘(𝑥)𝑦𝑘1𝑘=0 (𝐿𝑎𝑔𝑟𝑎𝑛𝑔𝑖𝑎𝑛 𝑖𝑛𝑡𝑒𝑟𝑝𝑜𝑙𝑎𝑡𝑖𝑜𝑛)

=𝑥−𝑥𝑖+1

𝑥𝑖 −𝑥𝑖+1𝑆”(𝑥𝑖) +

𝑥−𝑥𝑖

𝑥𝑖+1 −𝑥𝑖𝑆”(𝑥𝑖+1)

On integrating twice, 𝑆𝑖(𝑥) = (𝑥3

6− 𝑥𝑖+1

𝑥2

2 )𝑆”(𝑥𝑖)

Δ𝑖+ (

𝑥3

6− 𝑥𝑖

𝑥2

2 )𝑆”(𝑥𝑖+1)

Δ𝑖+1+ 𝑐1𝑥 + 𝑐2

Apply the conditions

𝑆𝑖(𝑥𝑖) = 𝑦𝑖 and Si(𝑥𝑖+1) = 𝑦𝑖+1

→ 𝑆𝑖(𝑥) =𝑆′′(𝑥𝑖)(𝑥𝑖+1 − 𝑥)

3

6Δ𝑖+𝑆′′(𝑥𝑖+1)(𝑥 − 𝑥𝑖)

3

6Δ𝑖+ (

𝑦𝑖Δ𝑖−Δ𝑖6𝑆"𝑖(𝑥𝑖)) (𝑥𝑖+1 − 𝑥)

+ (𝑦𝑖+1Δ𝑖

−Δ𝑖6𝑆"𝑖(𝑥𝑖+1)) (𝑥 − 𝑥𝑖)

Apply another condition:

𝑆𝑖−1′(𝑥𝑖) = 𝑆𝑖′(𝑥𝑖) on the following

𝑆𝑖′(𝑥) = −

𝑆′′(𝑥𝑖)(𝑥𝑖+1 − 𝑥)2

2Δ𝑖+𝑆′′(𝑥𝑖+1)(𝑥 − 𝑥𝑖)

2

2Δ𝑖− (

𝑦𝑖Δ𝑖−Δ𝑖6𝑆𝑖′′(𝑥𝑖))

+ [(𝑦𝑖+1Δ𝑖

−Δ𝑖6𝑆𝑖′′(𝑥𝑖+1))]

On re-arrangement it can be shown

Δ𝑖−16𝑆′′(𝑥𝑖−1) +

Δ𝑖−1 + Δ𝑖3

𝑆′′(𝑥𝑖) +Δ𝑖6𝑆′′(𝑥𝑖+1)

=𝑦𝑖+1 − 𝑦𝑖

Δ𝑖−𝑦𝑖 − 𝑦𝑖−1Δ𝑖−1

,

𝑖 = 2, 𝑛 − 1 (𝑖𝑛𝑡𝑒𝑟𝑖𝑜𝑟 𝑛𝑜𝑑𝑒𝑠)

(linear)

Page 74: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

1 2 𝑥𝑖−1 𝑥𝑖 𝑥𝑖+1 𝑛 − 1 𝑛

If 𝑆′′(𝑥1) 𝑎𝑛𝑑 𝑆′′(𝑥𝑛) are pre-known as boundary conditions, we have

𝐴�� = �� 𝑜𝑟 𝐴𝑆′′(𝑥) = �� where A is the tridiagonal matrix

For a ‘natural’ spline, 𝑆′′(𝑥1) = 𝑆′′(𝑥𝑛) = 0 OR 𝑆′′(1) = 𝑆′′(𝑛) = 0

If Δ𝑖 = Δ𝑖−1 (𝑒𝑞𝑢𝑎𝑙𝑙𝑦 𝑠𝑝𝑎𝑐𝑒𝑑 𝑑𝑎𝑡𝑎)

** 1

6[𝑆′′(𝑥𝑖−1) + 4𝑆

′′(𝑥𝑖) + 𝑆′′(𝑥𝑖+1)] = (

𝑦𝑖+1−2𝑦𝑖+𝑦𝑖−1

Δ2)

Call subroutine Tridiag(𝑛 − 2, 1 6⁄ , 2 3⁄ ,1

6, ��)

# 𝑜𝑓 𝑒𝑞𝑛𝑠 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡𝑠

𝑜𝑓 �� 𝑅𝐻𝑆 𝑜𝑟 𝑏

𝑣𝑒𝑐𝑡𝑜𝑟

𝑆𝑖′′(𝑥𝑖), 𝑖 = 2, 𝑛 − 1 are now known on solving the set of eq

ns.

Thus, 𝑆𝑖(𝑥) is determined from the boxed equation on the preceding page 3.

Example: -2.5 0 2.5

0 1.67 0

Fit a cubic natural spline.

Use ** above

1

6𝑆′′(𝑥1) +

2

3𝑆′′(𝑥2) +

1

6𝑆′′(𝑥3) =

0−2×1.67+0

2.52

(You have only one linear algebraic eqn)

𝑆′′(𝑥2) = −0.8016 𝑖 = 2 (middle node only)

𝑆1(𝑥) = −0.05344(𝑥 + 2.5)3 + 1.002(𝑥 + 2.5)

𝑆2(𝑥) = 1.667 − 0.4𝑥2 + 0.0533𝑥3)

} 𝐴𝑛𝑠.

Page 75: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

Numerical Differentiation

P2 approximated polynomial

f(x) ≈ Pn(x)

Given a continuous 𝑓(𝑥), numerical differentiation can be performed to determine gradient

𝑓′(𝑥𝑖) 𝑎𝑡 𝑥𝑖. Fit a polynomial (𝑢𝑠𝑢𝑎𝑙𝑙𝑦 𝑃1−3) and then determine 𝑃1−3′ to estimate 𝑦𝑖

′, depending

on desired order of accuracy or error. Taylor’s series can be conveniently used to derive 𝑓′ 𝑜𝑟 𝑓′′

because the series terms contain 𝑓′ 𝑜𝑟 𝑓′′ .

Taylor’s series: 𝑓(𝑥 + ℎ) = 𝑓(𝑥) + ℎ𝑓′(𝑥) + ℎ2 2⁄ 𝑓′′(𝑥) + ⋯ (1)

𝑓(𝑥 − ℎ) = 𝑓(𝑥) − ℎ𝑓′(𝑥) + ℎ2 2⁄ 𝑓′′(𝑥) − ⋯ (2)

2 pts

{

𝑓

′(𝑥𝑖) =𝑓(𝑥𝑖+1)−𝑓(𝑥𝑖)

ℎ+ 0(ℎ2) ∶ 𝐹𝑜𝑟𝑤𝑎𝑟𝑑 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝑆𝑐ℎ𝑒𝑚𝑒 (𝐹𝐷𝑆)

𝑓′(𝑥𝑖) =𝑓(𝑥𝑖)−𝑓(𝑥𝑖−1)

ℎ+ 0(ℎ2) ∶ 𝐵𝑎𝑐𝑘𝑤𝑎𝑟𝑑 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝑆𝑐ℎ𝑒𝑚𝑒 (𝐵𝐷𝑆)

𝑓′(𝑥𝑖) =𝑓(𝑥𝑖+1)−𝑓(𝑥𝑖−1)

2ℎ+ 0(ℎ3) ∶ 𝐶𝑒𝑛𝑡𝑟𝑎𝑙 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝑆𝑐ℎ𝑒𝑚𝑒 (𝐶𝐷𝑆)

(1) Richardson’s extrapolation technique can be used to take 3 data pts.

𝑓(𝑥𝑖 + 2ℎ) = 𝑓(𝑥) + 2ℎ𝑓′(𝑥) + 4 (ℎ2 2)⁄ 𝑓′′(𝑥) + ⋯⋯ (3)

𝑓(𝑥𝑖 − 2ℎ) = 𝑓(𝑥) − 2ℎ𝑓′(𝑥) + 4 (ℎ2 2)⁄ 𝑓′′(𝑥) + ⋯⋯ (4)

Use 1 an 3 : Multiply eq(1) by 4 and subtract from 3 to eliminate 𝑓′′(𝑥𝑖)

3𝑝𝑜𝑖𝑛𝑡𝑠

{

𝑓′(𝑥𝑖) =

4𝑓(𝑥𝑖+1) − 3𝑓(𝑥𝑖) − 𝑓(𝑥𝑖+2)

2ℎ + 0(ℎ3) ∶ 𝐹𝐷𝑆

𝑆𝑖𝑚𝑖𝑙𝑎𝑟𝑙𝑦 2 𝑎𝑛𝑑 4 𝑤𝑖𝑙𝑙 𝑔𝑖𝑣𝑒

𝑓′(𝑥𝑖) =−4𝑓(𝑥𝑖−1) + 3𝑓(𝑥𝑖) + 𝑓(𝑥𝑖−2)

2ℎ + 0(ℎ3) ∶ 𝐵𝐷𝑆

You will see later in the course that although BDS and FDS are also 2nd order accurate like CDS,

such equations are used at the boundary points or end points only to discretize Neumann or

f(x)

y(xi)

xi-1

or

xi xi+1

xi-2 xi-1 xi xi+1 xi+2

(1)

Page 76: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

mixed or flux (gradient) terms: −𝑘𝜕𝑇

𝜕𝑥 𝑜𝑟 − 𝐷

𝜕𝐶

𝜕𝑥 𝑜𝑟 − µ

𝜕𝑣

𝜕𝑥, whereas CDS is invariably used at

interior nodes.

Higher order 𝑓′(𝑥𝑖) can also be obtained as CDS:

4𝑑𝑎𝑡𝑎 𝑝𝑜𝑖𝑛𝑡𝑠

{𝑓′(𝑥𝑖) =−4𝑓(𝑥𝑖+2) − 8𝑓(𝑥𝑖−1) + 8𝑓(𝑥𝑖+1) + 4𝑓(𝑥𝑖+2)

12ℎ + 0(ℎ4)

( See the book by Ferziger)

Similarly, use eqns 1 & 2 to obtain

𝑓′′(𝑥𝑖) =𝑓(𝑥𝑖+1)−2𝑓(𝑥𝑖)+𝑓(𝑥𝑖−1)

ℎ2 + 0(ℎ3)

= 𝑓′′(𝑥𝑖−1) = 𝑓′′(𝑥𝑖+1):

𝑊ℎ𝑦? (𝑌𝑜𝑢 ℎ𝑎𝑣𝑒 2𝑛𝑑 𝑜𝑟𝑑𝑒𝑟 𝑝𝑜𝑙𝑦𝑛𝑜𝑚𝑖𝑎𝑙 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 3 𝑑𝑎𝑡𝑎 𝑝𝑜𝑖𝑛𝑡𝑠)

You should note that similar to 𝑓′(𝑥𝑖), FDS and BDS or formulae can also be derived for

𝑓′′(𝑥𝑖) using three points or manipulating Taylor’s series or equations 1-4. However, these

equations are seldom or in fact, never used for most of chemical engineering problems. Why

not? Because the N-S or species or thermal energy balance equations (PDEs) are 2nd order,

with the 1st order (flux) boundary condition. Therefore, CDS for 𝑓′′(𝑥𝑖), applied at interior

nodes, suffices.

To this end, apply Richardson’s extrapolation technique to obtain even higher order 𝑓′′

𝑓′′(𝑥𝑖) =−𝑓(𝑥𝑖−2) + 16𝑓(𝑥𝑖−1) − 30𝑓(𝑥𝑖) + 16𝑓(𝑥𝑖+1) − 𝑓(𝑥𝑖+2)

12ℎ2 + 0(ℎ4)

(Five data points)

Note the notations: 𝒇(𝒙𝒊) 𝐚𝐧𝐝 𝒚𝒊(𝒙𝒊); 𝐟′𝐚𝐧𝐝 𝐟′′ 𝐚𝐧𝐝 𝐲′𝐚𝐧𝐝 𝐲′′. 𝑺𝒖𝒎𝒎𝒂𝒓𝒚 𝒂𝒕 𝒂 𝒈𝒍𝒂𝒏𝒄𝒆:

𝒇(𝒙) ≃ 𝑷𝒏(𝒙), 𝒇′(𝒙) ≃ 𝑷′𝒏(𝒙), 𝒇′′(𝒙) ≃ 𝑷′′𝒏(𝒙)

Page 77: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #14-15

Numerical Integration

Similar to numerical differentiation, the integration of 𝑓(𝑥), i.e., ∫ 𝑓(𝑥)𝑑𝑥 may be performed by

approximating 𝑓(𝑥) ≈ 𝑃𝑛(𝑥), usually 𝑛 ≤ 3. Therefore, first calculate 𝑦𝑖(𝑥𝑖) from 𝑓(𝑥), then

fit a polynomial through the ′𝑛′ data points and determine∫𝑃𝑛𝑑𝑥 𝑜𝑟 area under the

approximated curve. Considering usual oscillations set in the fitted polynomial for 𝑛 ≥ 4, piece-

wise integration is performed Detailed method and analysis are as follows.

𝑃𝑛(𝑥) is the interpolating 𝑓𝑛 between (𝑥0, ⋯ 𝑥𝑛)

It can be shown/proposed that

∫ 𝑓(𝑥)𝑑𝑥 = ∑ 𝑤𝑘𝑓(𝑥𝑘); 𝑓(𝑥𝑘) = 𝑦(𝑥𝑘)𝑛𝑘=0

𝑏

𝑎

where, 𝑛 is the number of segments between ‘a’ and ‘b’

and ‘𝑤𝑖’ is the respective weight at 𝑥𝑖 . It is also known

as Quadrature formula. Let us look at the proposed formula differently. Apply Lagrange

interpolation between (𝑛 + 1) data points or 𝑛 segments:

𝑃𝑛(𝑥) = ∑ 𝑙𝑘(𝑥)𝑦𝑘 (𝑦𝑘 ≡ 𝑦(𝑥𝑘) ≡ 𝑦𝑘(𝑥𝑘))𝑛𝑘=0

∫ 𝑓(𝑥)𝑑𝑥 = ∫ ∑ 𝑙𝑘(𝑥)𝑦𝑘𝑑𝑥 = ∑ ∫ 𝑙𝑘(𝑥)𝑦𝑘𝑑𝑥𝑏

𝑎𝑛𝑘=0

𝑛𝑘=0

𝑏

𝑎

𝑏

𝑎

= (𝑏 − 𝑎)∑ 𝐶𝑘𝑦𝑘; 𝐶𝑘 =

1

(𝑏−𝑎)∫ 𝑙𝑘(𝑥)𝑑𝑥𝑏

𝑎𝑛𝑘=0

Cotes number

- It is the same as the Quadrature formula ; n ≡ parameter(degree of polynomial)

(It can be shown ∑ 𝐶𝑘 = 1 (𝑝𝑢𝑡 𝑓(𝑥) = 1))𝑛𝑘=0

Therefore, we can have a table as follows:

𝑎 𝑏 𝑥𝑖

𝑓(𝑥)

𝑃𝑛(𝑥)

Page 78: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

Newton-Cotes Coefficients (ends points included)

𝑛 𝑁 𝑁𝐶0𝑛 𝑁𝐶1

𝑛 𝑁𝐶2𝑛⋯⋯ 𝑁𝐶0

𝑁 𝐸𝑟𝑟𝑜𝑟

12345

26890288

111719

1433275

131250

13250

775

19

. 0183Δ3𝑓′′

. 0035Δ5𝑓′′′′

. 00016Δ5𝑓′′′′⋯⋯

These are called closed N-C formula because they use functions at the end points also (𝑎, 𝑏).

Note, 𝑛 or the number of segments is usually 1 or 2 or 3, or the degree of polynomial is 1 or 2

or 3, respectively. Readers may have recognized that n = 1 corresponds to Trapezoidal rule

with ‘1 2⁄ ’ coefficients of 𝑦𝑘; 𝑛 = 2 corresponds to Simpson’s ‘1 3⁄ 𝑟𝑑’ rule with

(1 6⁄ , 2 3⁄ , 1 6⁄ ) coefficients, etc. For more details, you can refer the book by Ferziger or SKG.

The error in the numerical integration can be calculated from the remainder term of the

polynomial:

⇒ 𝐼 = ∫(𝑒𝑟𝑟𝑜𝑟)𝑑𝑥 ⇒ 𝑤ℎ𝑒𝑟𝑒 ′𝑒𝑟𝑟𝑜𝑟′ = 𝑦𝑛+1(𝜉)

𝑛 + 1!(𝑥 − 𝑥0)(𝑥 − 𝑥1)⋯ (𝑥 − 𝑥𝑛)

𝑓𝑜𝑟 (𝑛 + 1) 𝑑𝑎𝑡𝑎 𝑝𝑜𝑖𝑛𝑡𝑠

⇒ SKG’s book uses Newton’s Interpolation formula to determine the various

integration formulae:

𝑦 (𝑥) = 𝑦(𝑥0 + 𝛼Δ𝑥) = 𝑦0 + 𝛼(Δ𝑦0) +𝛼(𝛼−1)(Δ2𝑦0)

2!+

⋯⋯𝛼(𝛼−1)(𝛼−2)𝛼⋯(𝛼−𝑛)(Δ𝑛+1𝑦0)

𝑛+1!

𝑅𝑛

To obtain the different methods for integration, viz. Trapezoidal’s rule, Simpson’s 1 3⁄𝑟𝑑

, etc, two approaches must give the identical results because polynomial of the highest degree

that can fit to (𝑛 + 1) data points is unique.

Take 𝑛 = 1

∫ 𝑓(𝑥)𝑑𝑥 = (𝑏 − 𝑎)∑ 𝐶𝑘𝑛𝑓(𝑥𝑘)

𝑛𝑘=0

𝑏

𝑎

= (𝑏 − 𝑎) [1

2𝑦𝑎 +

1

2𝑦𝑏]

=(𝑏−𝑎)

2(𝑦𝑎 + 𝑦𝑏)

𝑓(𝑥) 𝑃1(𝑥)

𝑓(𝑏)

𝑓(𝑎)

𝑎 𝑥 𝑏

𝑓(𝑥)

Page 79: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

[𝑜𝑟 = (𝑏−𝑎)

2(𝑓(𝑎) + 𝑓(𝑏))]

(Trapezoidal rule)

𝑛 = 2

∫ 𝑓(𝑥)𝑑𝑥 =(𝑏 − 𝑎)

6[𝑓(𝑎) + 4𝑓 (

𝑎 + 𝑏

2) + 𝑓(𝑏)]

𝑏

𝑎

(𝑁𝑜𝑡𝑒: 𝑃2 ≡ (𝑎 + 𝑏𝑥 + 𝑎𝑥2) ≡ 𝑝𝑎𝑟𝑎𝑏𝑜𝑙𝑎)

=Δ𝑋

3[𝑓(𝑎) + 4𝑓 (

𝑎+𝑏

2) + 𝑓(𝑏)] Δ𝑋 =

𝑏−𝑎

2

𝑛 = 3

∫ 𝑓(𝑥)𝑑𝑥 =(𝑏 − 𝑎)

8[𝑓(𝑎) + 3𝑓(𝑐) + 3𝑓(𝑑) + 𝑓(𝑏)]

𝑏

𝑎

=3Δ𝑋

8[ − 𝑑𝑖𝑡𝑡𝑜 − ], Δ𝑥 =

(𝑏−𝑎)

3

- Simpson’s 3 8⁄𝑡ℎ

formula.

In actual practice, applying a single Cotes formula over the entire range is rarely done.

Considering large error for large ′Δ𝑋′, interval is broken into sub-intervals & then applying

piece-wise quadrature formula and summing it over.

∫ 𝑓(𝑥)𝑑𝑥 =ℎ

2[𝑓(𝑋𝑖−1) + 𝑓(𝑋𝑖)]

𝑋𝑖𝑋𝑖−1

ℎ =(𝑏−𝑎)

𝑛 (𝑛 + 1 data points or 𝑛 segments)

𝑓(𝑥)

𝑆𝑖𝑚𝑝𝑠𝑜𝑛′𝑠 1 3⁄𝑟𝑑 𝑓𝑜𝑟𝑚𝑢𝑙𝑎

(ℎ𝑖𝑔ℎ𝑒𝑟 𝑜𝑟𝑑𝑒𝑟 𝑎𝑐𝑐𝑢𝑟𝑎𝑡𝑒)

𝑎 𝑏 (𝑎 + 𝑏)2⁄

𝑃2(𝑥)

ΔX ΔX

𝑎 𝑏 𝑋𝑖−1 𝑋𝑖 𝑋𝑛 𝑋0

Page 80: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Therefore, ∫ 𝑓(𝑥)𝑑𝑥 = ∑ℎ

2[𝑓(𝑥𝑖−1) + 𝑓(𝑥𝑖)]

𝑛𝑖=1

𝑏

𝑎

=

2[𝑓(𝑥0) + 2∑𝑓(𝑥𝑘) + 𝑓(𝑥𝑛)

𝑛−1

𝑘=1

]

(𝑏 − 𝑎)

𝑛[∑𝑓(𝑥𝑘) −

1

2[𝑓(𝑎) + 𝑓(𝑏)]

𝑛

𝑘=0

]}

* Trapezoidal rule

𝑺𝒊𝒎𝒑𝒔𝒐𝒏’𝒔 𝟏 𝟑⁄𝒓𝒅 𝒓𝒖𝒍𝒆: (intervals must be even or data points must be odd),

𝑛 𝑁 𝑁𝐶0𝑛 𝑁𝐶1

𝑛 𝑁𝐶2𝑛

2 6 1 4 1

∫𝑓(𝑥)𝑑𝑥 = (

𝑏−𝑎

6) (𝑓(𝑎) + 4𝑓(𝑐) + 𝑓(𝑏))

ℎ =𝑏−𝑎

2

𝑏

𝑎

ℎ =(𝑏−𝑎)

𝑛 (𝑛 𝑒𝑣𝑒𝑛 𝑠𝑒𝑔𝑚𝑒𝑛𝑡𝑠 𝑜𝑟𝑛 + 1 𝑜𝑑𝑑 𝑑𝑎𝑡𝑎 )

∫ 𝑓(𝑥)𝑑𝑥 = ∑ℎ

3[𝑓(𝑋𝑖−1) + 4∑𝑓(𝑋𝑖) + 𝑓(𝑋𝑖+1)]

𝑏

𝑎

=ℎ

3(𝑓(𝑋0) + 4∑ +2𝑛−1

𝑘=1,3,5 ∑ +𝑓(𝑋𝑛))𝑛−2𝑘=2,4,6

(Note that all even nodes ‘𝑋𝑘’ are summed/counted twice in calculating total area)

What do you do if 𝑛 ≡ odd or data are even? Apply the method to one data less so that n =

even. Add the area corresponding to the left-over segment, calculated using Trapezoidal rule!

One open NC method is popular: Mid-point rule, the method is frequently applied when the

𝑓𝑛 is discontinuous at end points: a or b or both.

∫ 𝑓(𝑥)𝑑𝑥 = (𝑏 − 𝑎) [𝑓 (𝑎+𝑏

2)]

𝑏

𝑎

𝑎 𝑏 (𝑎+𝑏)

2

𝑎 𝑏 𝑐

ℎ =(𝑏 − 𝑎)

2⁄

𝑋𝑖 𝑋𝑖 𝑋𝑖+1 ℎ ℎ

𝑋𝑖−1 𝑋𝑖+1 𝑋𝑖 𝑎 𝑏

(𝑋𝑛) (𝑋0)

Page 81: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

ex. ∫1

1−𝑥2𝑑𝑥

1

0 (Note 𝑓(1) → ∞)

Example:

𝑣 = 2��(1 −𝑟2

𝑅2)

𝜃 =𝑇−𝑇𝑤

𝑇𝑤= −4𝑧 − 𝑟2 +

𝑟4

4+

7

24

(𝑧, 𝑟 are dimensionless quantities: 𝑟 𝑅⁄ 𝑎𝑛𝑑 𝑧 𝐿⁄ )

Consider the classical heat transfer/transport problem of SS heat transfer at constant wall

temperature in the fully developed region of a tubular laminar parabolic flow, often discussed in

TP lectures. The dimensionless SS temperature 𝜃(𝑧, 𝑟) in the fluid is analytically derived. See

the solution above. Determine the ‘mix-cup’ temperature at z = 0.5.

Soln : In a flow-system, mix-cup temperature is the radially emerged temperature, taking into

consideration the total heat (cal) carried away by the flowing fluid in unit time across the cross-

section of the tube.

�� =

(

∫ 𝜌𝐶𝑝𝑣(𝑟′)𝑇(2𝜋𝑟′)𝑑𝑟′

𝑅

0

𝑘𝑔 𝑚3⁄ 𝑐𝑎𝑙 𝑘𝑔⁄ − 𝐾 𝐾

∫ 𝜌𝐶𝑝𝑣(𝑟′)2𝜋𝑟′𝑑𝑟′𝑅

0

𝑐𝑎𝑙 𝑠 − 𝐾⁄ )

(𝑁𝑜𝑡𝑒: 𝑑𝑞 = 𝑣2𝜋𝑟𝑑𝑟𝑚3

𝑠)

𝑄 = ∫ 𝑣2𝜋𝑟𝑑𝑟𝑅

0

at a ref. temperature

In the dimensionless quantities,

��(𝑧) =∫ 𝜃(𝑟, 𝑧)(1 − 𝑟2)𝑟𝑑𝑟1

0

∫ (1 − 𝑟2)𝑟𝑑𝑟1

0

Simpson’s 1 3⁄ rule can be applied by taking odd number (5) of data points over 𝑟 ≡ (0, 1).

Therefore # of segment = 4, step size, ℎ =1−0

4= 0.25, Δ𝑟 ≡ ℎ = 0.25; 𝑟𝑖 = 𝑖Δ𝑟

Δr T(r) 𝑣(r)

Tw

z

fully developed region (2) for both flow and temperature

r

R

Page 82: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

Numerical integration is performed for both numerator and denominator terms.

𝐼 = ∫ 𝑓(𝑟)𝑑𝑟1

0∫ Φ(𝑟)𝑑𝑟1

0⁄

where 𝑓(𝑟) = 𝜃(𝑟, 𝑧)(1 − 𝑟2)𝑟 & Φ(𝑟) = (1 − 𝑟2)𝑟

For both functions,

𝐼 = ℎ 3⁄ [𝑓(𝑋0) + 4∑ +2∑ + 𝑓(𝑋𝑛)𝑛−2𝑘=2,4

𝑛−1𝑘=1,3,5 ]

= ℎ 3⁄ [𝑓(𝑋0) + 4∑ +2∑ +𝑓(𝑋4)21,3 ]

Best way is to prepare a table for calculations:

𝑘 𝑟𝑘 𝜃𝑘 (1 − 𝑟𝑘

2)𝑟𝑘or Φ(𝑟)

𝜃𝑘(1 − 𝑟𝑘

2)𝑟𝑘𝑜𝑟 𝑓(𝑟)

01234

00.250.500.751.00

−1.7083−1.7698−1.9427−2.1917−2.4583

0.0

0.0

0.0

0.0

𝐹𝑖𝑙𝑙 − 𝑢𝑝 𝑡ℎ𝑒

𝑡𝑎𝑏𝑙𝑒

∑ Add ∑ Add

Show,

��𝑚𝑖𝑥−𝑐𝑢𝑝(0.5) ≡ −1.9976 =𝑇−𝑇𝑤

𝑇𝑤

(wall is colder than bulk fluid)

What does decide the # of data points ‘n’ or the step size ‘h’ ? It is the level of desired accuracy.

Repeat the entire calculations for n = 9 and check your requirement of an improved ��𝑚𝑖𝑥−𝑐𝑢𝑝

from the previous value -1.9976. Sometimes you have to decrease ‘n’ or increase ‘h’ if you have

exceeded accuracy limit!

Error Analysis

Let us take the simplest Trapezoidal rule applied to one segment over (a,b).

Start from Newton’s Difference Interpolation formula:

𝑇𝑤

𝑇𝑓𝑙𝑢𝑖𝑑

𝑇𝑤

(𝑛) 4 3 2 1 𝑘 = 0

Page 83: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

7

𝑓(𝑥) = 𝑓(𝑥0) + 𝛼Δ𝑓(𝑥0) +𝛼(𝛼 − 1)

2!Δ2𝑓(𝑥0) + ⋯𝑅𝑛

𝑅𝑛 =𝛼(𝛼−1)⋯(𝛼−𝑛)

𝑛+1!Δ𝑛+1𝑓(𝜉) 𝑤ℎ𝑒𝑟𝑒 𝑥0 < 𝜉 < 𝑥

𝛼 =𝑥−𝑥0

ℎ 𝑜𝑟 𝑑𝑥 = ℎ 𝑑𝛼 ; 𝑥0 = 𝑎,

If there is only one segment, ℎ = (𝑏 − 𝑎)

𝐼 = ∫ 𝑓(𝑥)𝑑𝑥 = ℎ∫ (𝑓(𝑥0) + 𝛼Δ𝑓(𝑥0) +𝛼(𝛼−1)

2!Δ2𝑓(𝜉))

1

0

𝑏

𝑎𝑑𝑥

𝑃1 = (𝑎𝑥 + 𝑏)

= ℎ [𝑓(𝑎) +1

2(𝑓(𝑏) − 𝑓(𝑎)) + (

𝛼3

6−𝛼2

4)∫ ℎ2𝑓′′(𝜉)

1

0

]

= ℎ [𝑓(𝑎)+𝑓(𝑏)

2] −

1

12ℎ3𝑓′′(𝜉) (𝑓′′(𝜉) =

Δ2𝑓(𝜉)

2ℎ)

Therefore, error on one segment is 1 2⁄ ℎ3𝑓′′(𝜉) 𝑜𝑟 0(ℎ3)

If there are n segments between (a & b) error should also be summed up to

1

12ℎ3∑ 𝑓′′(𝜉) =

1

12ℎ2𝑓′′(𝜉)(𝑏 − 𝑎) 𝑜𝑟 0(ℎ2) 𝑛

𝑁𝑜𝑡𝑒: 𝑓′′(𝜉) =∑𝑓′′(𝜉)

𝑛=

ℎ∑𝑓′′(𝜉)

(𝑏−𝑎).

Similarly, for the error estimation of Simpson’s 1 3⁄ rule start with 𝑃2 = 𝑎𝑥2 + 𝑏𝑥 + 𝑐, 𝑜𝑟

𝑅𝑛 =𝛼(𝛼−1)(𝛼−2)Δ3𝑓(𝜉)

3! over one segment or 3 data pts.

to show that error ≡ 0(ℎ5)𝑓′′′′(𝜉) and if summed over ‘n’ segments error = 0(ℎ4)𝑓′′′′(𝜉).

Simpson’s 3 8⁄ 𝑟𝑢𝑙𝑒: error(one segment) ≡ 0(h5)

error( segments) ≡ 0(h4)

A common question is asked: Show that Simpson’s 1 3⁄ 𝑟𝑢𝑙𝑒 gives the error corresponding to

a cubic interpolating function, although it is based on a parabola or a quadratic polynomial. See

Chhapra and Cannale's book for the details.

Mid-Term

Page 84: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #15-16

1st order ODE

A set of ODEs takes the following form:

𝑑𝑦1

𝑑𝑡= 𝑓1(𝑡, 𝑦1, 𝑦2⋯𝑦𝑛)

⋮ 𝑑𝑦𝑛

𝑑𝑡= 𝑓𝑛(𝑡, 𝑦1, 𝑦2⋯𝑦𝑛)

} 𝑜𝑟 𝑑��

𝑑𝑡= 𝑓(𝑡, ��)

Requires initial conditions to solve �� .

𝑡 = 0, 𝑦1 = 𝑦10… . . 𝑦𝑛 = 𝑦𝑛0, 𝑒𝑡𝑐 𝑜𝑟 �� = ��0

Note that ODEs can also be1st order on x (space) & 𝑑��

𝑑𝑥= 𝑓(𝑥, 𝑦 ) with 𝑥 = 0, �� = ��0.

⇒ We explore numerical solution to ODEs starting with Euler’s forward and backward

methods. These methods are basics, and also set the tone for the stability analysis. Let us begin

with one ODE.

Euler’s Method

𝑑𝑦

𝑑𝑥= 𝑓(𝑥, 𝑦) ; 𝑦(𝑥0) = 𝑦0

𝑜𝑟 , 𝑦𝑛+1−𝑦𝑛

ℎ= 𝑓(𝑥𝑛, 𝑦𝑛) + 0(ℎ

2)

(This is the general ‘discretization’ of a derivative at the ‘n’ th grid. Recall the lecture on

numerical differentiation. We have used FDS.)

or 𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓(𝑥𝑛, 𝑦𝑛) + 0(ℎ2)

𝑦𝑛′

Note: The RHS terms are known to be 1st order accurate or have 2nd order error.

From the previous calculations, start from 𝑦(𝑥 = 0 ) = 𝑦0 → 𝑦1 → 𝑦2⋯𝑒𝑡𝑐. Therefore, you

march forward and the method is called Euler’s forward or explicit method. Think carefully.

The method is all about taking a linear slope/tangent at

(xn, yn) and moving on to (xn+1, yn+1).

𝑦0 𝑦1 𝑦𝑛 𝑦𝑛+1

𝑥0 𝑥1 𝑥𝑛 𝑥𝑛+1

Page 85: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

Graphically,

Theoretical y(x)

}

It is all aboutcalculating true derivatives

(gradients) at xn asyou march forward:

y0′ = f(x0, y0)

y1′ = f(x1, y1)⋮ yn′ = f(xn, yn)

It is clear that smaller is ‘h’ (step-size), less is the error, or accuracy is higher: 0(ℎ2). However,

there is a price for long CPU time. Also, stability may become an issue. Let us look at the

stability aspect of the method.

𝑑𝑦

𝑑𝑥= 𝑓(𝑥, 𝑦) = 𝑓(𝑥0 + Δ𝑥, 𝑦0 + Δ𝑦)

= 𝑓(𝑥0, 𝑦0) + (𝑦 − 𝑦0)𝑑𝑓

𝑑𝑦|𝑥0,𝑦0

+ (𝑥 − 𝑥0)𝑑𝑓

𝑑𝑥|𝑥0,𝑦0

+ 0(Δ𝑥2, Δ𝑦2)

Multi-variable Taylor series can be applied to estimate gradient 𝑦′(𝑥0, 𝑦0):

= 𝛼𝑦 + 𝛽𝑥 + 𝜈

gives exponential

solution

term const. for linear solution

𝑑𝑦

𝑑𝑥= 𝛼𝑦 ∶

Model equation for testing stability.(Note: Stability is governed by thehomogeneous part of the solution)

Let us look at differently: Introduce perturbation or find true value, 𝑦 .

Therefore, 𝑑𝑦

𝑑𝑥= 𝛼�� + 𝛽𝑥 + 𝜈

𝑜𝑟, 𝑑𝜉

𝑑𝑥= 𝛼(𝑦 − 𝑦) = 𝛼𝜉 (𝜉 = 𝑦 − 𝑦)

We have the same inference: error satisfies homogeneous part of the solution. The equation

describes how ‘𝜉’ can grow because of a small perturbation.

At 𝑥 = 𝑥0, 𝑦 = 𝑦0 ⇒ exact solution: 𝑦 = 𝑦0𝑒𝛼𝑥 𝐼𝑓 𝛼 > 0, fngrows, α < 0, fn is bounded.

Numerical calculations

𝑌

𝑦0

𝑥0 𝑥1 𝑥2 𝑋

Page 86: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

Now Apply Euler’s method:

𝑦𝑛+1 − 𝑦𝑛 = ℎ𝑓(𝑥𝑛, 𝑦𝑛) = ℎ𝑦𝑛′ = ℎ(𝛼 𝑦𝑛)

𝑦𝑛+1 = 𝑦𝑛(1 + 𝛼ℎ)

𝑦1 = 𝑦0(1 + 𝛼ℎ), 𝑦2 = 𝑦0(1 + 𝛼ℎ)2

𝑦𝑛 = 𝑦0(1 + 𝛼ℎ)𝑛 ⇒ Numerical solution

If α > 0 function grows or unboundedIf α < 0 function may be bounded

]

Let us write, 𝛼 = 𝛼𝑟 + 𝑖𝛼𝐼

𝑦𝑛 = 𝑦0(1 + 𝛼𝑟ℎ + 𝑖𝛼𝐼ℎ)𝑛

For function to be bounded

|(1 + 𝛼𝑟ℎ) + 𝑖𝛼𝐼ℎ| < 1

(1 + 𝛼𝑟ℎ)2 + 𝛼𝑖

2ℎ2 < 1

0 > 𝛼𝑟ℎ > −2 if αi = 0 for stability

Note: 𝛼 = −𝑣𝑒, the exact solution is always bounded! Therefore, Euler’s forward/explicit

numerical method is conditionally stable. Example:

𝑑𝑦

𝑑𝑥= −𝑦 (𝑥 = 0, 𝑦 = 1) ⇒ 𝑦 = 𝑒−𝑥

Numerical soln :

𝛼 = −1; 𝛼𝑟 = −1, 𝛼𝐼 = 0

0 > 𝛼𝑟ℎ > −2 for stability

or ℎ < +2

⇒ 𝑦𝑛+1 − 𝑦𝑛 = ℎ𝑓(𝑥𝑛, 𝑦𝑛) = −ℎ𝑦𝑛 ⇒ 𝑦𝑛 = (1 − ℎ)𝑛

Plot to see that oscillations start creeping in h > 2

𝑋 6 4 2 0 10−7

𝑌

𝑙𝑜𝑔 1.0 exact

(bounded)

ℎ = 0.001

ℎ = 0.1 ℎ = 0.8

error increases ⇒

2.0

1.0

0 −2 −1 𝑋

ℎ = 1

ℎ > 5

(unbounded)

exact solution: 𝑌

𝑋

1.0 ′bounded (theroteical)solution′

𝑅(𝛼𝑟ℎ)

Stable region(depends on ℎ and αr)

𝐼(𝛼𝑖ℎ)

−2 −1 0

Page 87: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Backward or Implicit Euler:

𝑑𝑦

𝑑𝑥= 𝑓(𝑥, 𝑦), 𝑦(𝑥0) = 𝑦0

𝑦𝑛+1−𝑦𝑛

ℎ= 𝑓(𝑥𝑛+1, 𝑦𝑛+1) + 0(ℎ

2) (Note this BDS may require iteration)

,maybe NR method; you can not march!

𝑦𝑛+1 − 𝑦𝑛 = ℎ𝑓(𝑥𝑛+1, 𝑦𝑛+1) ⇒ Test it on the model eqn

dy

dx= αy for the stability analysis

𝑦𝑛+1 = 𝑦𝑛 + ℎ(𝛼𝑦𝑛+1)

𝑦𝑛+1 = 𝑦𝑛 (1 − 𝛼ℎ)⁄

= 𝑦0(1 − 𝛼𝑟ℎ − 𝑖𝛼𝑖ℎ)−𝑛

For 𝑓𝑛 to be bounded |(1 − 𝛼𝑟ℎ − 𝑖𝛼𝑖ℎ)| > 1

𝑜𝑟 (1 − 𝛼𝑟ℎ)2 + 𝛼𝑖

2ℎ2 > 1

𝑜𝑟 |(1 − 𝛼𝑟ℎ)| > 1 if 𝛼𝑖 = 0

Clearly, 0 > 𝛼𝑟ℎ > 2

Draw the region:

⇒ {

For all (αrh) in the left half of the plane αr < 0 𝑎𝑛𝑑the method is unconditionally

stable

For all ℎ outside the circle

the method is stable (or αrh > 2)

It is clear the stability region for the implicit Euler is much more larger than that of the explicit

Euler.

Notes: Error decreases with decreasing step sizes (h): 0(ℎ𝑛), however, at the expense of CPU

time. This is not surprising. The actual ‘issue’ is with increasing step sizes. There is a tendency

to speed up computation by taking large step-size. An explicit method like Euler Forward may

not permit or allow you to do so, even if the level of desired accuracy may be acceptable.

Instability may set in at large ‘h’. On the other hand, Euler Backward or an implicit method

permits you to use relatively larger ‘h’ without instability, yielding a bounded solution.

(𝛼𝑖ℎ)

(𝛼𝑟ℎ) 0 1

2

Page 88: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

⇒ ‘Error’ must not be mixed up with the ‘instability’. A method may be relatively higher order

accurate, but may show instability at small step-size. In general, implicit methods are more

stable than explicit methods, but require iterations to compute 𝑦𝑛+1. Examples:

𝑑𝑦

𝑑𝑥= 𝑓(𝑥, 𝑦) = 𝛼𝑦2

Explicit: 𝑦𝑛+1 − 𝑦𝑛 = ℎ𝛼𝑦𝑛2

Implicit: 𝑦𝑛+1 − 𝑦𝑛 = ℎ 𝛼𝑦𝑛+12 (requires iterations or NR method? )

⇒ " A method is stable if it produces a bounded solution when it is supposed to and is unstable

if it does not." Therefore, while solving 𝑑𝑦

𝑑𝑥= −𝑦, if the numerical method produces a stable

solution, it is stable, else unstable. On the other hand, there is no instability ‘issue’ with 𝑑𝑦

𝑑𝑥=

+𝑦 because the exact solution itself is unbounded. Therefore, both Euler Forward(explicit) or

Backward(implicit) will produce an unbounded solutions!

Get back to 𝑑𝑦

𝑑𝑥= −𝑦(𝛼 = −1) and 𝑦𝑛 = (1 + ℎ)−𝑛

Error increases with increasing ‘h’ but the

solution remains stable. Compare to Forward Euler

when 𝛼 < 2 for a stable solution.

⇒ Trapezoidal rule (0(ℎ2)):

𝑦𝑛+1 − 𝑦𝑛 =ℎ

2[𝑓(𝑥𝑛, 𝑦𝑛) + 𝑓(𝑥𝑛+1, 𝑦𝑛+1)]

(Implicit method)

It can also be tested on the model equation:

𝑑𝑦

𝑑𝑥= 𝛼𝑦

𝑜𝑟 𝑦𝑛+1 − 𝑦𝑛 =𝛼ℎ

2[𝑦𝑛 + 𝑦𝑛+1]

𝑦𝑛+1 = 𝑦𝑛(1+𝛼ℎ 2)⁄

(1−𝛼ℎ 2)⁄

𝑜𝑟 𝑦𝑛 = 𝑦0(1 + 𝛼ℎ 2⁄

1 − 𝛼ℎ 2)⁄)𝑛

error

exact

h=1

0.2

0.1 0

y

1.0

X

Page 89: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

|𝑧| < 1

For stability |(1+𝛼ℎ 2)⁄

(1−𝛼ℎ 2)⁄| < 1 𝑜𝑟

Each method has a stability region for 𝛼𝑟ℎ

selecting the step-size, ‘h’ for calculation without instability.

See the textbooks for details. Stability region

.

Page 90: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #17

Single Step Methods

Forward or Backward Euler is the simplest single step method to solve ODEs. The methods

are 1st order accurate. A general higher order method can be derived considering that it is all

about choosing a suitable gradient at (𝑥𝑛, 𝑦𝑛) 𝑜𝑟 (𝑡𝑛, 𝑦𝑛) to calculate 𝑦𝑛+1(𝑥𝑛+1):

𝑑𝑦

𝑑𝑡= 𝑓(𝑡, 𝑦); 𝑦(0) = 𝑦0

𝑦𝑛+1 = 𝑦𝑛 + ℎ𝜙(𝑡𝑛, 𝑦𝑛, ℎ) (ℎ = 𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒 = Δ𝑡)

It is all about finding: 𝜙(𝑡𝑛, 𝑦𝑛, ℎ) = (𝑑𝑦

𝑑𝑡)𝑡𝑛,𝑦𝑛

=?

Propose as

𝑦𝑛+1 = 𝑦𝑛 + ℎ[𝑎𝑘1 + 𝑏𝑘2] 1 ⇒ 𝑔𝑒𝑛𝑒𝑟𝑎𝑙 𝑚𝑒𝑡ℎ𝑜𝑑.

Here, 𝑘1 and 𝑘2 are the slopes with weights a & b respectively ( Forward Euler may be

considered to assume 𝑎 = 1, 𝑏 = 0 and 𝑘1 = 𝑦𝑡𝑛,𝑦𝑛′ , whereas Backward Euler assumes 𝑎 =

0, 𝑏 = 1, 𝑘2 = 𝑦𝑡𝑛+1,𝑦𝑛+1′ )

Here, 𝑘1 = 𝑓(𝑡𝑛, 𝑦𝑛)

𝑘2 = 𝑓(𝑡𝑛 + 𝑝ℎ, 𝑦𝑛 + 𝑞(ℎ𝑘1) }Thus, the model has4 parameters; a, b, p, q.

{

Thus k2(slope)is calculated

at (tn + ph), fraction less than(tn + h) or tn+1, as x − coordinate,

and yn + q(hk1), fraction less

than (yn + hk1) or yn+1, as y −coordinate.

𝑘2 = 𝑓(𝑡𝑛, 𝑦𝑛) + 𝑓𝑡(𝑡𝑛, 𝑦𝑛). 𝑝ℎ + 𝑓𝑌(𝑡𝑛, 𝑦𝑛)𝑞ℎ𝑘1 + 0(ℎ2)

-Taylor multi-variable series applied on 𝑘2(𝑡, 𝑦) with Δ𝑡 = 𝑝ℎ, Δ𝑦 = 𝑞ℎ𝑘1

Substituting in (1)

𝑦𝑛+1 = 𝑦𝑛 + ℎ[𝑎𝑓(𝑡𝑛, 𝑦𝑛) + 𝑏𝑓(𝑡𝑛, 𝑦𝑛)] + ℎ2[𝑏𝑝𝑓𝑡(𝑡𝑛, 𝑦𝑛) + 𝑏𝑞𝑓𝑓𝑦(𝑡𝑛, 𝑦𝑛)] + 0(ℎ

3) − (2)

(𝑠𝑙𝑜𝑝𝑒)

𝑦𝑛+1

𝑦𝑛 + 𝑞(ℎ𝑘1)

𝑦𝑛

𝑡𝑛 𝑡𝑛+1

(𝑡𝑛 + 𝑝ℎ)

𝑞(ℎ𝑘1)

ℎ𝑘1 𝑘2

𝑘1

𝑦

Page 91: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

Also, restart from 𝑑𝑦

𝑑𝑡= 𝑓(𝑡, 𝑦(𝑡)) as a total derivative on t.

or 𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓 +ℎ2

2!𝑓′ + 0(ℎ3): (Single variable(t) Taylor − Series)

where 𝑓′ =𝑑𝑓

𝑑𝑡(𝑡𝑛, 𝑦𝑛) = [

𝜕𝑓

𝜕𝑡+

𝜕𝑓

𝜕𝑦∙𝑑𝑦

𝑑𝑡]𝑡𝑛,𝑦𝑛

= [𝑓𝑡 + 𝑓𝑦𝑓]

On substitution,

𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓 +ℎ2

2𝑓𝑡(𝑡𝑛, 𝑦𝑛) +

ℎ2

2𝑓𝑦𝑓 + 0(ℎ3) (3)

Thus, model equation (2) can be equated with the fundamental equation (3) derived for 𝑦𝑛+1;

(

𝑎 + 𝑏 = 1

𝑏𝑝 = 12⁄

𝑏𝑞 = 1 2⁄

)

Case 1: 𝑎 = 1 2⁄ , 𝑏 = 1 2⁄ , 𝑝 = 𝑞 = 1

𝑦𝑛+1 = 𝑦𝑛 +ℎ

2[𝑓(𝑡𝑛, 𝑦𝑛) + 𝑓(𝑡𝑛 + ℎ, 𝑦𝑛 + ℎ𝑦𝑛

′)] + 0(ℎ3)

Write differently,

𝑦𝑛+1∗ = 𝑦𝑛 + ℎ𝑓(𝑥𝑛, 𝑦𝑛) predictor full step

𝑦𝑛+1 = 𝑦𝑛 +ℎ

2[𝑓(𝑡𝑛, 𝑦𝑛) + 𝑓(𝑡𝑛 + ℎ, 𝑦𝑛+1

∗ )]

} corrector full step

Look at graphically,

𝑦𝑛+1∗

Therefore, first predict 𝑦𝑛+1∗ and then correct as 𝑦𝑛+1 by taking the average of the slopes,

𝑘1 and 𝑘2 ∶ 𝑦𝑛+1 = 𝑦𝑛 + ℎ��

𝑦𝑛

𝑦𝑛+1

𝑡𝑛 𝑡𝑛+1 𝑡

𝑘1

𝑘2

(𝑘1 + 𝑘2)2⁄ = 𝑘

𝑦

𝑘1 𝑘2

𝑘1 𝑘2

Page 92: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

- This method is called Heun’s improved method or modified Euler method or Runga-

Kutta (RK-2) method.

Case 2: 𝑎 = 0 , 𝑏 = 1, 𝑝 = 𝑞 = 1 2⁄

𝑦𝑛+1 = 𝑦𝑛 + ℎ [𝑓 (𝑡𝑛 +ℎ

2, 𝑦𝑛 +

2𝑦𝑛′)]

Write differently,

𝑦𝑛+1 2⁄∗ ≡ 𝑦𝑛 +

12⁄ ℎ𝑦𝑛

′ (Euler predictor 1 2⁄ step)

𝑦𝑛+1 ≡ 𝑦𝑛 + ℎ [𝑓 (𝑡𝑛 +ℎ2⁄ , 𝑦

𝑛+1 2⁄∗ )] : Mid − point corrector full step

Graphically,

}

(1) Start with slope 1

Reach half step.(2) Calculate slope 2

(3)Re − start with the slope2 to reach full step.

- This method is called midpoint method.

3. RK-4

𝑦𝑛+1 = 𝑦𝑛 +ℎ

6[𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4] + 0(ℎ

5)

�� = avg of four slopes withmore weights at mid points.

𝑘1 = 𝑓(𝑥𝑛, 𝑦𝑛)

𝑘2 = 𝑓(𝑥𝑛 +ℎ2⁄ , 𝑦𝑛 + 𝑘1

ℎ2⁄ ) 𝑜𝑟 𝑓(𝑥𝑛+1 2⁄ ,𝑦𝑛+1 2⁄

∗ )

𝑦𝑛+1 2⁄∗ ∶ 𝐸𝑢𝑙𝑒𝑟 𝑝𝑟𝑒𝑑𝑖𝑐𝑡𝑜𝑟 1 2⁄ 𝑠𝑡𝑒𝑝

𝑘3 = 𝑓(𝑥𝑛 +ℎ2⁄ , 𝑦𝑛 + 𝑘2

ℎ2⁄ ) 𝑜𝑟 𝑓(𝑥𝑛+1 2⁄ ,𝑦𝑛+1 2⁄

∗∗ )

𝑦𝑛

𝑌𝑛+1 2⁄∗

𝑌𝑛+1

𝑡𝑛 𝑡𝑛+1 2⁄ 𝑡𝑛+1

(𝑡𝑛 + ℎ)

𝑡

1

2

𝑦

Page 93: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

𝑦𝑛+1 2⁄∗∗ ∶ 𝐵𝑎𝑐𝑘𝑤𝑎𝑟𝑑 𝐸𝑢𝑙𝑒𝑟 1 2⁄ 𝑠𝑡𝑒𝑝 𝑐𝑜𝑟𝑟𝑒𝑐𝑡𝑖𝑜𝑛

𝑘4 = 𝑓(𝑥𝑛 + ℎ, 𝑦𝑛 + 𝑘3ℎ): 𝑀𝑖𝑑 𝑝𝑜𝑖𝑛𝑡 𝑝𝑟𝑒𝑑𝑖𝑐𝑡𝑜𝑟 𝑓𝑢𝑙𝑙 𝑠𝑡𝑒𝑝

𝑦𝑛+1∗∗∗

Write differently,

𝑦𝑛+1 2⁄∗ = 𝑦𝑛 +

ℎ2⁄ 𝑓(𝑥𝑛, 𝑦𝑛) ∶ 𝐸𝑃

12 ⁄ 𝑠𝑡𝑒𝑝

𝑦𝑛+1 2⁄∗∗ = 𝑦𝑛 +

ℎ2⁄ 𝑓 (𝑥𝑛+1 2 ⁄ , 𝑦𝑛+1 2 ⁄

∗ ) ∶ 𝐵𝐸 1 2 ⁄ 𝑠𝑡𝑒𝑝 𝑐𝑜𝑟𝑟𝑒𝑐𝑡𝑜𝑟

𝑦𝑛+1∗∗∗ = 𝑦𝑛 + ℎ𝑓 (𝑥𝑛+1 2 ⁄ , 𝑦𝑛+1 2 ⁄

∗∗ ) :𝑀𝑖𝑑 𝑝𝑜𝑖𝑛𝑡 𝑝𝑟𝑒𝑑𝑖𝑐𝑡𝑜𝑟 𝑓𝑢𝑙𝑙 𝑠𝑡𝑒𝑝.

𝑦𝑛+1 = 𝑦𝑛 +ℎ

6[𝑓(𝑥𝑛, 𝑦𝑛) + 2𝑓(𝑥𝑛+1 2 ⁄ , 𝑦𝑛+1 2 ⁄

∗ ) + 2𝑓 (𝑥𝑛+1 2 ⁄ , 𝑦𝑛+1 2 ⁄∗∗ ) + 𝑓(𝑥𝑛+1, 𝑦𝑛+1

∗∗∗ )]

∶ 𝑆𝑖𝑚𝑝𝑠𝑜𝑛 𝑓𝑢𝑙𝑙 𝑠𝑡𝑒𝑝 𝑐𝑜𝑟𝑟𝑒𝑐𝑡𝑜𝑟.

Graphically,

�� = (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4) 6⁄

Notes: (1) RK-4 is a 4th order accurate method!

(2) The method is explicit (does not require iterations to calculate 𝑦𝑛+1). You can march ahead

from 𝑥𝑛 𝑡𝑜 𝑥𝑛+1. Yet, considering that it makes use of the value 𝑦𝑛+1 at 𝑥𝑛+1 ahead of 𝑥𝑛 via a

predictor step, the method possesses some ‘characteristics’ of an implicit method. Therefore, the

method also produces a stable solution at a relatively larger step size.

(3) Coding (program) is simple.

𝑘4

𝑘3

𝑘2

𝑘3

𝑘2 𝑘1

𝑥𝑛 𝑥𝑛+1 2⁄ 𝑥𝑛+1 ℎ

2⁄

ℎ2⁄

𝑋

𝑌𝑛+1∗∗∗

𝑌𝑛+1 2⁄∗

𝑌𝑛+1 2⁄∗∗

𝑦𝑛

𝑌

𝑦𝑛+1

��

Page 94: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

(4) Even if two or more number of simultaneous ODEs are coupled, the method is explicitly

applied w/o requiring iterations,

(5) Considering that the method is explicit, non-linearity is not an issue.

(6) Considering that the method is explicit, the implementation is identical for a system of

ODEs.

See example below:

Solve: 𝑑𝑦1

𝑑𝑡= −100𝑦1

with choose 𝑦1(0) = 2 ℎ = Δ𝑡 = 0.02

𝑑𝑦2

𝑑𝑡= 2𝑦1 − 𝑦2 𝑦2(0) = 1

Write alternatively, solve 𝑑𝑦

𝑑𝑡= 𝑓(𝑥, 𝑦) ; 𝑦(𝑡, 0) = 𝑦

0

or {𝑦1′

𝑦2′ } = [

−100 02 −1

] { 𝑦1 𝑦2

} ; { 𝑦1 𝑦2

}0= {

21}

or

{𝑦1′

𝑦2′ } = {

−100𝑦12𝑦1 − 𝑦2

}; { 𝑦1 𝑦2

}0= {

21}

(1) ��1 = 𝑓(𝑡𝑛, 𝑦𝑛)

𝑘1 = [𝑘1′

𝑘1′′] = [

−100 × 22 × 2 − 1

] = [−2003

]

(2) 𝑘2 = [𝑘2′

𝑘2′′] ⇒ ��2 = 𝑓(𝑡𝑛+1 2 ⁄ , 𝑦𝑛 +

1

2��1ℎ)

= 𝑓 [0.01, 2 +

1

2(−200) × 0.02

0.01, 1 +1

2(3) × 0.02

] = 𝑓 [0.01, 0.000.01, 1.03

] = [0.00−1.03

]

(3) 𝑘3 = [𝑘3′

𝑘3′′] ⇒ ��3 = 𝑓(𝑡𝑛+1 2 ⁄ , 𝑦𝑛 +

1

2��2ℎ)

= 𝑓 [0.01, 2 + 0 ×

. 02

2

0.01, 1 − 1.03 ×0.02

2

] = 𝑓 [0.01, 2.0000.01, 0.9897

] = [−100 × 2

2 × 2 − 0.9897]

= [−2003.0103

]

Page 95: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

(4) 𝑘4 = [𝑘4′

𝑘4′′] ⇒ ��4 = 𝑓(𝑡𝑛+1, 𝑦𝑛 + ℎ��3)

= 𝑓 [0.02, 2 − 0.02 × 2000.02, 1 + 0.02 × 3.0103

] = 𝑓 [0.02, −20.02, 1.060206

]

= [−100 × −2

2 × −2 − 1.060206] = [

200−5.060206

]

{𝑦1𝑦2} = ⌊

2

1⌋ +

0.02

6[

−200 + 2 × 0 − 2 × 200 + 2003 − 2 × 1.03 + 2 × 3.0103 − 5.060206

]

= [0.666671.00633

] 𝐴𝑛𝑠.

⇒ How to choose h? Choose a reasonable ‘h’ depending on the physics of the problem. Solve

and re-do the calculation for ℎ 2 ⁄ and check the convergence. Sometimes, one may have to

increase the step-size if the accuracy can be relaxed.

⇒ There are R-K-Mersen or R-K-Fehlberg automatic step-size control method where ‘h’ is

adjusted (either h → 2h or h → h2 ⁄ ) depending upon the error in the RK-4 solution relative

to that from error in a higher order method proposed by Mersen or Fehlberg.

In summary, the single step methods to solve 1st order ODE(s) are all about finding a

relatively “accurate” slope or tanӨ to reach the target at “h” step forward. The difference

between the methods is the computation of the slopes, viz.,

(tn, yn) or (tn+1, yn+1) or (tn+1/2, yn+1/2) or a combintation of these?

Thus, the methods are called differently (explicit/implicit) and have different orders

(1st/2nd/4th, etc) of accuracy and different stability regions (smaller or bigger):

𝑦𝑛+1 = 𝑦𝑛 + ℎ 𝜙(𝑡𝑛, 𝑦𝑛): 𝐹𝑜𝑟𝑤𝑎𝑟𝑑 𝐸𝑢𝑙𝑒𝑟

𝑦𝑛+1 = 𝑦𝑛 + ℎ 𝜙(𝑡𝑛+1, 𝑦𝑛+1): 𝐵𝑎𝑐𝑘𝑤𝑎𝑟𝑑 𝐸𝑢𝑙𝑒𝑟

𝑦𝑛+1 = 𝑦𝑛 + ℎ [𝜙(𝑡𝑛, 𝑦𝑛) + (𝑡𝑛+1, 𝑦𝑛+1)]/2: 𝑇𝑟𝑎𝑝𝑒𝑧𝑜𝑖𝑑𝑎𝑙 𝑅𝑢𝑙𝑒

𝑦𝑛+1 = 𝑦𝑛 + ℎ 𝑘: RK-4 predictor-corrector

𝑤ℎ𝑒𝑟𝑒, 𝑘 𝑖𝑠 𝑠𝑜𝑚𝑒 𝑤𝑒𝑖𝑔ℎ𝑡𝑎𝑔𝑒 𝑎𝑣𝑒𝑟𝑎𝑔𝑒 𝑜𝑓 𝑠𝑙𝑜𝑝𝑒𝑠 𝑐𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑒𝑑 𝑎𝑡 𝑠𝑜𝑚𝑒 𝑖𝑛𝑡𝑒𝑟𝑚𝑒𝑑𝑎𝑖𝑡𝑒 𝑙𝑜𝑐𝑎𝑡𝑖𝑜𝑛𝑠.

Note: All methods predict/estimate the functional value, 𝑦𝑛+1 linearly starting with initial

condition, 𝑦𝑛 at 𝑥𝑛.

Page 96: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #18

Example 1 (RK-4)

Consider a special (diameter = 10 cm) ball made of steel k = 40

𝑊 𝑚 − 𝐾, 𝜌 = 8000 𝑘𝑔 𝑚3, 𝐶𝑝 = 400 𝐽 𝑘𝑔 − 𝑘).⁄ ⁄⁄ The initial temperature of the ball is

300 K. It is immersed in a large oil tank at 400 K. The convective heat transfer coefficient, h at

the sphere surface is 3000 𝑊 𝑚2 − 𝑘⁄ . Assume that there is no radial temperature gradient

inside the ball. Use the R-K-4 numerical technique to solve the governing first order energy

balance equation for predicting the temperature of the sphere at 𝑡 = 1 𝑚𝑖𝑛 after it was

immersed in the oil tank. Use Δ𝑡 = 10 𝑠. Repeat calculations for Δ𝑡 = 5 𝑠. Draw graphical

depiction of the slopes comprising all stages of the RK method. Do calculations up to 4 digits

after decimal. Calculate the rate of temperature-decrease at 𝑡 = 0, 0.5 and 1.0 min.

The energy balance (transient/unsteady equation):

𝜌𝐶𝑝𝑑𝑇

𝑑𝑡= −ℎ𝑎(𝑇 − 𝑇0)

(𝑘𝑔 𝑚3⁄ . 𝐽 𝑘𝑔 − 𝑘⁄ .𝐾

𝑠) = 𝐽 𝑠 − 𝑚2 − 𝑘⁄ (400 − 𝑇) 𝐾 (

4𝜋𝑅2

43⁄ 𝜋𝑅3)

𝑚2

𝑚3

8000 × 400 ×𝑑𝑇

𝑑𝑡= +3000 ×

3

0.05(400 − 𝑇)

𝑑𝑇

𝑑𝑡= +0.05625(400 − 𝑇) = 𝑓(𝑡, 𝑇)

Δ𝑇 = ℎ = 10 or 5 𝑠

𝑘1 = 𝑓(0, 300) = +0.05625(400 − 300) = +5.6250

𝑘2 = 𝑓(5, 300 + 5.625 × 5) = +0.05625(400 − 328.125) = 4.0429

𝑘3 = 𝑓(5, 300 + 4.0429 × 5) = 0.05625(400 − 320.2145) = 4.4879

↓ 𝐴𝑠

𝑉𝑠

328.125

320.2145

𝑡 = 0 𝑇 = 300 𝐾 𝑇(𝑡)

𝑅

𝑡

𝑇𝑜 = 400 𝐾

𝑅 = 5.0 𝑐𝑚

Page 97: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

𝑘4 = 𝑓(10, 300 + 4.4879 × 10) = 0.05625(400 − 344.879) = 3.1005

𝑘 = 16⁄ (5.6206 + 2 × 4.0429 + 2 × 4.4879 + 3.1005) = 4.2979

𝑇 = 300 + 4.2979 × 10 = 𝟑𝟒𝟐. 𝟗𝟕𝟗𝟓 𝑲 𝑨𝒏𝒔.

March for the next time steps 𝑡 = 20, 30, 40, 50, 60 𝑠, each time using the calculated

values from the previous time steps (viz. 342.9795, etc). Repeat the entire calculations for Δ𝑡 =

5𝑠.

⇒ In a 20-25 min quiz or examination, such problem can be solved for one time step

using calculator. One requires to write a code to solve such problem for a long time or several

steps calculations.

⇒ Rate at 𝑡 = 0, 0.5 and 1.0 min

𝑑𝑇

𝑑𝑡|

0= 0.05625(400 − 𝑇) = 0.05625 × 100 = 5.6250 𝑘 𝑠⁄

(Note: Once the functional values or temperatures are determined or known, the

derivatives can also be calculated using the formulae you learnt! But, here is the analytical

solution.)

Plot the graph as done in the previous lecture and approximately draw the steps for

𝑘1, 𝑘2, 𝑘3, 𝑘4, 𝑘, and functional values (𝑇𝑛, 𝑇𝑛+1

2⁄∗ , 𝑇

𝑛+12⁄

∗∗ , 𝑇𝑛+1∗∗∗ , 𝑇𝑛+1) on y-axis.

⇒ From the chemical engineering point of view, temperature-gradient in (steel) sphere

was neglected considering a large thermal conductivity of the material, 𝑘 ≫ ℎ′𝑅′ or small Biot

#. Therefore, the lump body approach was used to determine the sphere temperature, and the

resulting energy balance equation is derived to be a 1st order ODE, else.

Ex2. Consider a steady-state 1D reactive flow of a gaseous species, A in a long quartz

tubular reactor (ID = D, length = L) (Re > 5000) radiated by UV light. The average velocity in

the tube is 𝑉. The species 𝐴 is converted to B by the 1st order homogeneous reaction (𝑟 =

𝑘𝐶𝐴), as it flows in the tube. The inlet concentration of A is 𝐶𝐴𝑜 . Determine the axial

concentration profiles of A in the reactor. The reaction is exothermic: (−Δ𝐻; 𝑐𝑎𝑙𝑚𝑜𝑙⁄ ).

Inlet temperature is 𝑇𝑜

344.8790

𝑇𝑜

𝐶𝐴𝑜

�� 𝐶𝐴(𝑥) =? (𝑟 = 𝑘𝐶𝐴)

𝑥 = 𝐿

Page 98: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

A species balance can be derived as follows, neglecting radial concentration profiles (Pe, r>>1)

𝜕𝐶𝐴

𝜕𝑡+ ��

𝜕𝐶𝐴

𝜕𝑥= 𝐷𝑥

𝜕2𝐶𝐴

𝜕𝑥2− 𝑘𝐶𝐴 (𝑚𝑜𝑙

𝑠 − 𝑚3⁄ )

𝑜𝑟, ��𝑑𝐶𝐴

𝑑𝑥= 𝐷𝑥

𝑑2𝐶𝐴

𝑑𝑥2− 𝑘𝐶𝐴 − (1)

Note that the reaction is exothermic and the rate constant is temperature dependent. Write

down the energy-balance eqn:

𝜌𝐶𝑝 (𝜕𝑇

𝜕𝑡+ ��

𝜕𝑇

𝜕𝑥) = 𝑘

𝜕2𝑇

𝜕𝑥2 + 𝑘𝐶𝐴 (−Δ𝐻) (𝑐𝑎𝑙𝑠 − 𝑚3⁄ )

𝑉𝑑𝑇

𝑑𝑥= 𝛼

𝑑2𝑇

𝑑𝑥2 +𝑘

𝜌𝐶𝑝𝐶𝐴 (−Δ𝐻) − (2)

Further approximation can be made if mass/ thermal diffusion terms are neglected

(𝑉∇𝐶𝐴 ≫ 𝐷∇2𝐶𝐴 and 𝑉∇𝑇 ≫ 𝛼∇2𝑇), considering a large axial Pe, x # for mass as well as

thermal transport. The equations (1-2) are modified as

𝑉𝑑𝐶𝐴

𝑑𝑥= −𝑘𝐶𝐴 = −𝑘0 exp(− 𝐸

𝑅𝑇⁄ ) 𝐶𝐴 - (3)

𝑉𝑑𝑇

𝑑𝑥=

𝑘0𝑒𝑥𝑝(−𝐸𝑅𝑇⁄ )

𝜌𝐶𝑝(−Δ𝐻)𝐶𝐴 - (4)

or 𝑑𝑦1

𝑑𝑥= 𝑓1(𝑦1, 𝑦2) = −

𝑘0𝑒𝑥𝑝(−𝐸𝑅𝑦2

⁄ )𝑦1

𝑉= 𝐴𝑒𝑥𝑝 (−

𝐵

𝑦2) 𝑦1

𝑑𝑦2

𝑑𝑥= 𝑓2(𝑦1, 𝑦2) =

𝑘0𝑒𝑥𝑝(−𝐸𝑅𝑦2

⁄ )(−Δ𝐻)𝑦1

𝑉𝜌𝐶𝑝= 𝐶𝑒𝑥𝑝 (−

𝐵

𝑦2) 𝑦1

The two 1st order equations are coupled and the right hand side terms have non-linear

dependence on 𝑦1 and 𝑦2. RK-4 can be applied without any problem, with the conditions:

𝑋 = 0; 𝑦1 = 𝑦10 𝑎𝑛𝑑 𝑦2 = 𝑦20. You can choose a step-size of Δ𝑥 = 𝐿10⁄ .

Notes: - If the axial diffusion terms are not neglected, the governing equations will

assume a form of 2nd order ODE, which will be discussed in the next lecture as Boundary Value

Problems.

- There are higher-order RK methods and even implicit RK method discussed in

literature to solve ODE or initial value problem.

(𝑆𝑆)

Page 99: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

- There are two commonly used multi-step methods for solving ODEs (Note: RK-4 is

a single step multi-stage method): Adams-Bashforth and Adams-Moulten. These

methods use a polynomial on the derivatives of a function, passing through the

single or multi-points.

Adams-Bashforth (Explicit)

𝑑𝑦

𝑑𝑡= 𝑓(𝑦, 𝑡) ≡ 𝑓(𝑦(𝑡), 𝑡)

𝑡 = 0, 𝑦(0) = 𝑦0

Solve for y(t) = ?

{

𝑡0

𝑦0

𝑦0′

𝑡1

𝑦1

𝑦1′

𝑡𝑛

𝑦𝑛

𝑦𝑛′

𝑡𝑛+1

𝑦𝑛+1

𝑦𝑛+1′

: solve : gradient

We have,

𝑦𝑛+1 = 𝑦𝑛 + ∫ 𝑦′𝑑𝑡𝑡𝑛+1

𝑡𝑛

extrapolated value between tn and tn+1

Define 𝛼 =𝑡−𝑡𝑛

ℎ: ⇒ 𝑦𝑛+1 = 𝑦𝑛 + ℎ ∫ 𝑦′(𝛼)𝑑𝛼 (0 ≤ 𝛼 ≤ 1) − (1)

1

0

Fit a jth order polynomial of 𝑦𝑛′ through 𝑋𝑛 and 𝑋𝑛−𝑗 (𝑗 + 1 pts preceding 𝑋𝑛) using backward

difference formula (∇𝑦𝑖 = 𝑦𝑖 − 𝑦𝑖−1).

𝑦′(𝛼) = [1 + 𝛼∇ +𝛼(𝛼 + 1)

2!∇2 + ⋯

𝛼(𝛼 + 1) ⋯ (𝛼 + 𝑗 − 1)

𝑗!∇𝑗] 𝑦𝑛

′ + 𝑅(𝜉)

(Thus, 𝑦′(𝛼) is the polynomial between (𝑋𝑛, 𝑋𝑛−1, 𝑋𝑛−2 ⋯ 𝑋𝑛−𝑗), substituting in (1)

𝑦𝑛+1 = 𝑦𝑛 + ℎ [1 +1

2∇ +

5

12∇2 +

3

8∇3 + ⋯ 𝐶𝑗∇j] 𝑦𝑛

′ + ℎ ∫ 𝑅(𝜉)𝑑𝑥1

0

𝑗 = 0 ∶ you have fitted a constant polynomial of the derivative (𝑦′)

𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑦𝑛′ +

ℎ2

2𝑦′′(𝜉) (𝑦𝑛 < 𝜉 < 𝑦𝑛+1)

(Recognize it as the Euler 1st order formula/explicit)

𝑗 = 1, you have fitted a line (linear polynomial) between 𝑋𝑛 𝑎𝑛𝑑 𝑋𝑛−1

𝑛 𝑛 + 1

𝑦𝑛′ 𝑦𝑛+1

𝑛 + 1 𝑛 − 1 𝑛

𝑦𝑛−1′

𝑦𝑛′

𝑦𝑛+1′

Page 100: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

𝑦𝑛+1 = 𝑦𝑛 + ℎ [𝑦𝑛′ +

1

2∇𝑦𝑛

′ ] +5

12h3𝑓′′(𝜉)

= 𝑦𝑛 +ℎ

2[3𝑓(𝑦𝑛) − 𝑓(𝑦𝑛−1)] − 2𝑛𝑑 𝑜𝑟𝑑𝑒𝑟 (𝐴𝑑𝑎𝑚 − 𝐵𝑎𝑠ℎ𝑓𝑜𝑟𝑡ℎ)

𝑗 = 2, you have a quadratic polynomial between (Xn, Xn−1, Xn−2)

Therefore, by taking different numbers of points preceding 𝑡𝑛 𝑜𝑟 𝑋𝑛 one can get a set of

working formulae having different 0(ℎ𝑛)

𝑦𝑛+1 = 𝑦𝑛 + ℎ ∑ 𝛽𝑘𝑚𝑓𝑛+1−𝑚𝑘𝑚=1

𝛽1𝑚

2𝛽2𝑚

12𝛽3𝑚

𝑚 = 113

23

2

−1−16

3

5

4

1𝑠𝑡 𝑜𝑟𝑑𝑒𝑟2𝑛𝑑 𝑜𝑟𝑑𝑒𝑟3𝑟𝑑 𝑜𝑟𝑑𝑒𝑟

Graphically,

⇒ From the above description, it is clear that the method has a ‘starting’ problem because only

one condition is known: 𝑦(0) = 𝑦0. In practice one starts with the Euler’s forward/explicit approach to

calculate 𝑦1, then use 2nd order method to predict 𝑦2, and then use (𝑦0, 𝑦1, 𝑦2) to calculate 𝑦3. Use of the

preceding ‘3’ data-points gives 3rd order accurate method.

⇒ Similar to the Adams-Bashforth (explicit), there is Adams-Moulton (Implicit) method

based on forward difference interpolation formula. For details, refer the textbooks.

𝑦𝑛−2′

𝑦𝑛−1′

𝑦𝑛′

𝑦𝑛+1′

𝑛 − 2 𝑛 − 1 𝑛 𝑛 + 1

𝑗 = 1 (𝑙𝑖𝑛𝑒𝑎𝑟)

𝑗 = 0 (𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡)

𝑦𝑛′

𝑡𝑛−1 𝑡𝑛+1 𝑡𝑛

𝑦𝑛′

𝑡𝑛−2 𝑡𝑛−1 𝑡𝑛 𝑡𝑛+1

(𝑞𝑢𝑎𝑑𝑟𝑎𝑡𝑖𝑐)

𝑗 = 2

Page 101: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #19

Instability and stiffness for a system of ODEs

In the previous lectures, we have shown that a system of ODEs (IV𝑃𝑠) 𝑦𝑖′ = 𝑓𝑖(𝑦1 ⋯ 𝑦𝑚) 𝑖 =

1,2, ⋯ 𝑚 with 𝑦𝑖(0) = 𝑦0 can be written as the coupled ODEs: 𝑦𝑖

′= 𝐴𝑦, where A is the

Jacobian matrix.

It is also clear that for the 𝑚 × 𝑚 matrix A, there are m eigenvalues: 𝐴𝜙𝑘 = 𝜆𝑘𝜙𝑘, where 𝜙𝑘 is

the eigenvector corresponding to 𝜆𝑘 eigenvalue. Now, make use of linear transformation: one

can construct a matrix, S whose columns are the eigenvectors of A such that 𝑆−1𝐴𝑆 = Λ, where

Λ is the diagonal matrix of the elements which are 𝜆𝑘 of A, as [𝜆1

⋱𝜆𝑘

]. Then one can

write,

𝑧′(defintion) = 𝑆−1��′ = 𝑆−1𝐴�� = (𝑆−1𝐴𝑆)𝑆−1�� = Λz

or 𝑧𝑘′ = 𝜆k𝑧𝑘, 𝑘 = 1,2, ⋯ 𝑛 − cannonical form.

where, 𝑧𝑘′ are uncoupled linear ODEs. Therefore, all (stability) characteristics of single ODE

will also be shown by the system of ODEs.

We have also seen earlier shown that a general solution to the system of ODEs can be written

as 𝐶1𝑒𝜆1𝑡{ } + 𝐶2𝑒𝜆2𝑡{ } +

⋯ , where the terms in the parenthesis are the eigenvectors corresponding to the eignevalues.

In such case, the growth or decay of the function depends on 𝜆𝑚𝑖𝑛 − 𝜆𝑚𝑎𝑥. A large numerical

value of 𝜆𝑚𝑎𝑥 will cause the function to grow or decay at a faster rate than that corresponding

to

𝑦 𝜆𝑚𝑖𝑛

𝜆𝑚𝑎𝑥 𝑡

Page 102: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

𝜆𝑚𝑖𝑛. In other words, small change in ‘t’ will cause a large change/variation in 𝑦(𝜆𝑚𝑎𝑥).

Solving such type of system of ODEs is numerically not trivial because a fine grid or step-size

Δ𝑡 𝑜𝑟 ℎ is required to accurately predict change in 𝑦(𝜆𝑚𝑎𝑥), whereas a coarse grid can be used

to predict 𝑦(𝜆𝑚𝑖𝑛).

- Such equations are called stiff ODEs. In general,

Stiff ratio(𝑆𝑅) =𝜆𝑚𝑎𝑥

𝜆𝑚𝑖𝑛> 10 represents a system

of stiff ODEs.

- Examples:

(1) A common example is the boundary layer problem

in hydrodynamics or heat or mass transport.

Functional value changes sharply within the

boundary layer, from that at the surface to that in

the potential region far from the surface.

Therefore, a numerical computation of the

functional values in the boundary layer (bottom

region), in principle, requires fine grid size, Δ𝑥1,

while that in the potential region (top region)

requires coarse grid size, Δ𝑥2. However, the sets of

the conservation equations in two regions are

coupled through some interfacial boundary

conditions, and therefore, must be solved

simultaneously using Δ𝑥1, which is CPU-wise

extensive!

(2) A combination of series and parallel chemical reactions with low and high rate constants:

ex: 𝑑𝑦

𝑑𝑡= [

−100 02 −1

] 𝑦 ; 𝑦(0) = [2 1]𝑇

on coefficient matrix ‘A’: (−100 − 𝜆)(−1 − 𝜆) = 0 ⇒ 𝜆1 = −100, 𝜆2 = −1

𝜆1 = −100 ∶ [−100 0

2 −1] {

𝑌1

𝑌2} = {

𝑌1

𝑌2} (𝑁𝑜𝑡𝑒: 𝑆𝑅 = 100)

2𝑋1 = −99𝑋2 ⇒ 𝑌(1) = {1

− 299⁄ }

𝜆2 = −1 ∶ [−100 0

2 −1] {

𝑌1

𝑌2} = {

𝑌1

𝑌2}

−100𝑌1 = −𝑌1 and 2𝑌1 − 𝑌2 = −𝑌2 ⇒ 𝑌(2) = {01

}

𝑦

Δ𝑥2

x

Δ𝑥1 𝑓𝑜𝑟 𝑏𝑜𝑡ℎ 𝑟𝑒𝑔𝑖𝑜𝑛𝑠

−1

100

Page 103: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

GS: 𝑌 = 𝐶1𝑒−100𝑡 {1

− 299⁄ } + 𝐶2𝑒−𝑡 {

01

}

or 𝑌1 = 𝐶1𝑒−100𝑡

𝑌2 =−2

99𝐶1𝑒−100𝑡 + 𝐶2𝑒−𝑡}

Apply: 𝑌 =2𝑒−100𝑡

103

99𝑒−𝑡 −

4

99𝑒−100𝑡} 𝐴𝑛𝑎𝑙𝑦𝑡𝑖𝑐𝑎𝑙 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛.

To solve numerically, a fine grid size Δ𝑡 will be initially

required to accurately predict a fast decay in the functional

value of 𝑦1, which can be relaxed or step-size can be

increased only during the later part of calculations.

In other words, time change in 𝑦2 is gradual (slow). Therefore, one would have used a coarse grid size

for 𝑦2 but for a rapid change in 𝑦1 during initial time of calculations which requires fine grid sizes.

⇒ SKG’s book has given one good example of stiff equations

𝑑𝑦1

𝑑𝑡= 77.27(𝑦2 − 𝑦1𝑦2 + 𝑦1 − 8.375 × 10−6𝑦1

2)

𝑑𝑦2

𝑑𝑡=

−𝑦2−𝑦1𝑦2+𝑦3

77.23 𝑦(0) = [4 1.1 4]𝑇

𝑑𝑦3

𝑑𝑡= 0.161(𝑦1 − 𝑦3)

In this case, stiffness changes with time, requiring adaptive mesh sizes: coarse when 𝑓𝑛 values slowly

change and fine when they change rapidly.

𝑦

2.0

1.0 𝑦2

𝑦1

𝑡 1 2

𝑃𝑙𝑜𝑡:

𝑓𝑖𝑛𝑒 𝑚𝑒𝑠ℎ 𝑠𝑡𝑒𝑝 − 𝑠𝑖𝑧𝑒 𝑖𝑠 𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑⁄

𝑓𝑖𝑛𝑒 𝑚𝑒𝑠ℎ 𝑠𝑡𝑒𝑝 − 𝑠𝑖𝑧𝑒 𝑖𝑠 𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑⁄

𝑡

10−2

106

𝑦

Page 104: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

If you use one fixed fine step-size throughout the calculations, it is a wastage of CPU time.

Gear’s Technique: Used to solve stiff ODEs, based on multiple steps but using predictor-corrector

approach:

Predictor(𝑒𝑥𝑝𝑙𝑖𝑐𝑖𝑡):

𝑦𝑛+1 = 𝛼1𝑦𝑛 + 𝛼2𝑦𝑛−1 + ⋯ 𝛼𝑘𝑦𝑛−(𝑘−1) + ℎ𝛽0𝑦𝑛′

Corrector(𝑖𝑚𝑝𝑙𝑖𝑐𝑖𝑡)

: 𝑦𝑛+1 = 𝛼1𝑦𝑛 + 𝛼2𝑦𝑛−1 + ⋯ 𝛼𝑘𝑦𝑛−(𝑘−1) + ℎ𝛽0𝑦𝑛+1′

You should note that this method also has a "starting" problem, similar to the previously discussed

multi-step methods.

Predictor Table

𝑘 𝛼1 𝛼2 𝛼3 ⋯ 𝛼6 𝛽0

123⋮⋮6

10

−32⁄

01

62⁄

00

−12⁄

⋯⋯⋯

000

1 2

62⁄

Corrector Table

𝑘 𝛼1 𝛼2 𝛼3 ⋯ 𝛼6 𝛽0

123⋮⋮6

14

3⁄

1811⁄

0−1

3⁄

−911⁄

00

211⁄

⋯⋯⋯

000

12

3⁄

611⁄

The first row (k = 1) of each table represents j = 0 (no previous data in the interpolating function); the

second row (k = 2) represents j = 1 (one preceding data in the interpolating function or a linear function),

and the third row (k = 3) represents j =2 (two preceding data in the interpolating function or a quadratic

function or parabola), etc.

Quiz II

Page 105: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #20

BVP (Boundary Value Problems)/2nd order ODEs

In this lecture, we will learn how to apply finite difference (direct) methods to solve BVPs. Such

problems are common in 1 D steady-state heat and mass transport in solid or fluid. The general

form of the BVP assumes a 2nd order ODE:

𝑑2𝑦

𝑑𝑥2= 𝑓(𝑥, 𝑦, 𝑦′) with two boundary conditions

required at two ends of the domain (𝑥 = 0 and 𝑥 = 𝐿 𝑜𝑟 (0,1)).

A general form of BVP can also be written as:

𝐴(𝑥)𝑑2𝑦

𝑑𝑥2+ 𝐵(𝑥)

𝑑𝑦

𝑑𝑥+ 𝐶(𝑥)𝑦 + 𝐷(𝑥) + 𝐸 = 0; (𝐴(𝑥) ≠ 0)

The required boundary conditions at two ends of the domain can assume any form: Drichlet or

Danckwarts or Neumann. That is, either functional value or gradient or mixed condition can be

specified:

𝑦 = 𝑐, or 𝑦′ = c, or 𝑎𝑦′ + 𝑏𝑦 = 𝑐.

Let us solve a general BVP equation:

𝐴(𝑥)𝑑2𝑦

𝑑𝑥2+ 𝐵(𝑥)

𝑑𝑦

𝑑𝑥+ 𝐶(𝑥)𝑦 + 𝐷(𝑥) + 𝐸 = 0;

Step1: divide the domain into N equal steps/grids or grids. Therefore, there are (N+1) nodes.

Step 2: discretize the equation or each terms of the equation at ‘ith’ grid. In this course, we will

discretize the terms using 2nd order accurate method (recall numerical differentiation).

𝐴(𝑥𝑖)𝑦𝑖−1 − 2𝑦𝑖 + 𝑦𝑖+1

ℎ2+ 𝐵(𝑥𝑖)

𝑦𝑖+1 − 𝑦𝑖−12ℎ

+ 𝐶(𝑥𝑖)𝑦𝑖 + 𝐷(𝑥𝑖) + 𝐸 = 0

Step3: Arrange the terms:

(𝐴(𝑥𝑖)

ℎ2−𝐵(𝑥𝑖)

2ℎ) 𝑦𝑖−1 − (

2𝐴(𝑥𝑖)

ℎ2− 𝐶(𝑥𝑖)) 𝑦𝑖 + (

𝐴(𝑥𝑖)

ℎ2+𝐵(𝑥𝑖)

2ℎ) 𝑦𝑖+1 = −𝐷(𝑥𝑖) − 𝐸

or 𝑎𝑖𝑦𝑖−1 + 𝑏𝑖𝑦𝑖 + 𝑐𝑖𝑦𝑖+1 = 𝑑𝑖 ← discretized form of equation

0(ℎ2) 0(ℎ2)

0 𝑖 − 1 𝑁 − 1 𝑁 1 2 𝑖 𝑖 + 1

Page 106: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

In principle, this equation should be valid for 𝑖 = 0⋯𝑁. However, there may be problem (!) at

the boundary nodes 𝑖 = 0 and 𝑁, because 𝑦−1 and 𝑦𝑁+1 may not be known or defined or

calculated. You should carefully inspect the given boundary conditions and decide to apply the

discretized equation over (𝑖 = 0⋯𝑁) 𝑜𝑟 (𝑖 = 1⋯𝑁)𝑜𝑟 (𝑖 = 1⋯𝑁 − 1)𝑜𝑟 (𝑖 = 0⋯𝑁 − 1) so

that the number of equations is the same as that many unknowns (𝑦𝑖). For the moment, let us

take the simplest boundary conditions, 𝑦(0) = 𝑦0 and 𝑦(𝑁) = 𝑦𝑁.

Apply the discretized equation over 𝑖 = 1⋯𝑁 − 1 as

𝑖 = 1: 𝑎1𝑦0 + 𝑏1𝑦1 + 𝑐1𝑦2 = 𝑑1 𝑎2𝑦1 + 𝑏2𝑦2 + 𝑐2𝑦3 = 𝑑2

⋮ 𝑎𝑁−2𝑦𝑁−3 + 𝑏𝑁−2𝑦𝑁−2 + 𝑐𝑁−2𝑦𝑁−1 = 𝑑𝑁−2𝑁 − 1: 𝑎𝑁−1𝑦𝑁−2 + 𝑏𝑁−1𝑦𝑁−1 + 𝑐𝑁−1𝑦𝑁 = 𝑑𝑁−1 }

Step 4: Apply the BCs and bring the terms containing y0 and yN to RHS:

𝑏1𝑦1 + 𝑐1𝑦2 = (𝑑1 − 𝑎1𝑦0) = 𝑑1′

𝑎2𝑦1 + 𝑏2𝑦2 + 𝑐2𝑦3 = 𝑑2⋮

𝑎𝑁−2𝑦𝑁−3 + 𝑏𝑁−2𝑦𝑁−2 + 𝑐𝑁−2𝑌𝑁−1 = 𝑑𝑁−2 𝑎𝑁−1𝑦𝑁−2 + 𝑏𝑁−1𝑦𝑁−1 = (𝑑𝑁−1 − 𝑐𝑁−1𝑌𝑁) = 𝑑𝑁−1

′ }

There are exactly (N-1) unknown and (N-1) equations. Notably, set of equations can be written as

𝐴𝑦 = 𝑏 where 𝐴 =

[ 𝑏1 𝑐1 0𝑎2 𝑏2 𝑐2 0 ⋯0 0 𝑎𝑁−2 𝑏𝑁−2 𝑐𝑁−2

0 𝑎𝑁−1 𝑏𝑁−1]

is the tridiagonal matrix.

Step 5: Call Thomas Algorithm (learnt earlier) to invert such matrix:

Tridiagonal (𝑁 − 1, 𝑎, 𝑏, 𝑐, 𝑑, 𝑌)

You should be able to clearly recognize that while preparing to call tridiagonal matrix,

the following coefficients were changed:

𝑑′1 = 𝑑1 − 𝑎1𝑌0 ∶ 1st row (𝑖 = 1)

The other coefficients remained the same: (i = 2, N-2)

𝑎𝑖 =𝐴(𝑥𝑖)

ℎ2−𝐵(𝑥𝑖)

2ℎ; 𝑏𝑖 = 𝐶(𝑥𝑖) −

2𝐴(𝑥𝑖)

ℎ2

# 𝑜𝑓 𝑒𝑞𝑛𝑠 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡𝑠𝑜𝑓 𝑚𝑎𝑡𝑟𝑖𝑥 𝐴

𝑜𝑢𝑡𝑝𝑢𝑡 (𝑖 = 1,⋯𝑁 − 1)

Page 107: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

𝑐𝑖 =𝐴(𝑥𝑖)

ℎ2+𝐵(𝑥𝑖)

2ℎ; 𝑑𝑖 = −𝐷(𝑥𝑖) − 𝐸 ;

Also, dN−1 was changed as d′N−1 = dN−1 − cN−1YN ∶ last row (i = N − 1)

⇒ Let us consider another example where the BVP equation is the same. At boundary, 𝑦(0) =

𝑦0(also same as before). However, at the other boundary, gradient is specified instead of

functional value: 𝑦𝑁′ = 0.

The boundary condition 𝑦𝑁′ can be discretized as

𝑌𝑁+1−𝑌𝑁−1

2ℎ= 0 (0(ℎ2)) 𝑜𝑟 𝑌𝑁+1 = 𝑌𝑁−1

Considering that YN is NOT known in this case, the coefficients (𝑎𝑖 , 𝑏𝑖, 𝑐𝑖, 𝑑𝑖) are extended to the

rows: 𝑖 = 1… . . 𝑁, 𝑖. 𝑒., the matrix A will have ‘N’ rows and the 1st & last row will be modified as

𝑑1 = 𝑑1 − 𝑎1𝑌0 (same as before)

and 𝑎𝑁 = 𝑎𝑁 + 𝑐𝑁; why ?

because the Nth equation

aNYN−1 + bNYN + cNYN+1 = dN is modified as

aNYN−1 + bNYN + cNYN−1 = dN on substitution of the bc.

Finally, call Tridiagonal (𝑁, 𝑎, 𝑏, 𝑐, 𝑑, 𝑌); i = 1, N

⇒ It is recommended that you should do your best to keep consistency between the order of methods

used to discretize the equation and boundary conditions. Also note that, 2nd order discretization method

is reasonably good/accurate for engineering calculations. If you use a higher order method, the

coefficient matrix A will no more be tridiagonal that is easy and fast to invert.

Ex: Consider the steady-state one dimensional heat conduction in a fine (length L, cross-section A,

perimeter P), whose one end is at a constant temperature 𝑇𝑓 and the other end is insulated. The ambient

temperature is 𝑇𝑎 and the convective heat transfer coefficient at the fix surface is ℎ.

Solve the steady-state temperature profiles in the fin.

L

An energy balance over ′𝐴Δ𝑥′ control volume will result in the following differential equation:

ρCp (∂T

∂t+ V. ∇T) = k∇2T + S ∶ cal

s − m3⁄

𝑃 𝐴

𝑥

𝑇𝑓

Δ𝑥 𝑇𝑎 ℎ𝑓

𝑇(𝑥) =?

SS Solid −h(T − Ta)

Cals − m2⁄

. (PΔx)(A Δx)

𝑚3

𝑚2

Page 108: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Note that there is no source or sink of heat as such in the fin. However, considering 1D axial heat

transfer, heat dissipated from the fin surface is homogenously distributed within the 𝐶𝑉: 𝑆 =

−ℎ(𝑇 − 𝑇𝑎)𝑎𝑠 where 𝑎𝑠 is the surface area per unit volume of the fin.

⇒ 𝑘𝑑2𝑇

𝑑𝑥2−ℎ(𝑇−𝑇𝑎)𝑃

𝐴= 0

or d2T

dx2+ BT + C = 0 where B =

−hP

kA; C =

hP

kATa and choose Δh =

L10⁄

BC: 𝑇(𝑥 = 0) = 𝑇𝑓 ; −𝑘∇𝑇 (𝑥 = 𝐿) = 0 𝑜𝑟 𝑑𝑇

𝑑𝑥= 0

Discretize the equation using the 2nd order method.

Soln: (𝑑2𝑇

𝑑𝑥2+ 𝐵𝑇 + 𝐶 = 0)

𝑇𝑖−1−2𝑇𝑖+𝑇𝑖+1

ℎ2 + 𝐵𝑇𝑖 + 𝐶 = 0

𝑇𝑖−1 + (𝐵ℎ2 − 2)𝑇𝑖 + 𝑇𝑖+1 = −𝐶ℎ

2 𝑖 = 1,𝑁

Prepare the tridiagonal matrix

𝑎𝑖 = 1, 𝑏𝑖 = (𝐵ℎ2 − 2), 𝑐𝑖 = 1, 𝑑𝑖 = −𝐶ℎ

2, 𝑖 = 1,𝑁

Apply BC/discretize BC:

𝑇0 = 𝑇𝑓(𝑖 = 0), 𝑇𝑁+1 = 𝑇𝑁−1 (𝑖 = 𝑁)

Therefore, 1st & last row will be modified as

𝑑1 = 𝑑1 − 𝑎1𝑇𝑓

𝑎𝑁 = 𝑎𝑁 + 𝑐𝑁

How? 1st row is modified as (𝐵ℎ2 − 2)𝑇1 + 𝑇2 = −𝐶ℎ2 − 𝑇𝑓

Last row is modified as 𝑇𝑁−1 + (𝐵ℎ2 − 2)𝑇𝑁 + 𝑇𝑁−1 = −𝐶ℎ

2

Therefore, you have the tridiagonal matrix A. Call the subroutine as:

Tridiagonal (𝑁, 𝑎, 𝑏, 𝑐, 𝑑, 𝑦) (Note that the total number of equations is N)

As an example, take the fin-problem of heat transfer: L = 1 cm, width of the fin = 0.1 cm, 𝑇𝑓 =

1000 𝐶, 𝑇𝑎 = 300 𝐶, ℎ = 100𝑤 𝑚2𝐾, 𝑘 = 20𝑊 𝑚−𝐾.⁄ ⁄ Take Δℎ = 0.1 𝑐𝑚, write a programming

code to obtain the solution and plot the temperature profiles:

𝐿 = 1 𝑐𝑚 𝑥 30𝑜𝐶

100𝑜𝐶

𝑇

1 𝑖 + 1 𝑖 0 𝑖 − 1 𝑁 − 1 𝑁

(𝑖𝑛𝑠𝑢𝑙𝑎𝑡𝑖𝑜𝑛)

Page 109: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

Calculate the rate of heat-loss/dissipation to atmosphere from the fin.

Note: Q (cal/s) = ∫h As (T(x) - Ta) dx = ∑ h A (Ti – Ta) ∆x, i =0, n, where n is the number of nodes of

the computational domain. Use Simpson’s 1/3 integration or Trapezoidal formula. Recall your

knowledge of heat transfer. Q can also be calculated by determining the heat leaking into the fin at x =

0, viz. Q = -k Ac 𝑑𝑇

𝑑𝑥. You can calculate the derivative by the 2nd order FDS using i =0, 1 and 2 nodes.

With a sufficient number of nodes or grids, two computations must produce the same results (cal/s).

You should revisit Heat Transfer taught at the UG level. You can also calculate the fin-efficiency.

Ex: Consider the catalytic oxidation of 𝑆𝑂2 into 𝑆𝑂3 under the constant temperature and pressure

conditions, over a spherical (diameter 𝑑𝑝 = 1 mm) pt-dispersed porous carbon catalyst. 𝑆𝑂2 in air (1%)

diffuses (𝐷 = 1 × 10−9 m2 s⁄ ) into the pores of the catalyst and is oxidized to 𝑆𝑂3 by a pseudo-zeroth

order reaction, 𝑟 = 0.01moles

s−m3. The convective film mass transfer coefficient is 𝑘𝑚 = 0.1m s⁄ .

Determine the steady-state concentration profiles of 𝑆𝑂2 within the pellet.

Soln:

𝜕𝐶𝐴

𝜕𝑡 + 𝑉. ∇𝐶𝐴 = 𝐷𝑝𝑜𝑟𝑒∇

2𝐶𝐴 − 𝑘

𝑜𝑟 Dpore

r2d

dr(r2

dCA

dr) − k = 0 (0 ≤ r ≤ rp)

continue in the next lecture………

𝑆𝑜𝑙𝑖𝑑 , 𝑆𝑆

𝐶(𝑟) =?

𝑟𝑝

𝑘𝑚

𝑆𝑂2(1%)𝐶𝑏 = 1%

𝑃, 𝑇 = constant

Page 110: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #21

(continued…..from the previous lecture)

𝑜𝑟 𝐷𝑝𝑑2𝐶𝐴

𝑑𝑟2+2𝐷𝑝

𝑟

𝑑𝐶𝐴

𝑑𝑟− 𝑘 = 0

𝑜𝑟 𝑑2𝑦

𝑑𝑟2+2

𝑟

𝑑𝑦

𝑑𝑟+ 𝐴 = 0 ; 𝐴 = (

−𝑘

𝐷𝑝)

(h =rp

N)

BCs. 𝑟 = 0

𝑑𝐶𝐴

𝑑𝑟= 0 (symmetric)

𝑟 = 𝑟𝑝 − 𝐷𝑝𝑑𝐶𝐴

𝑑𝑟= 𝑘𝑚(𝐶𝐴 − 𝐶𝑏)

Discretized eqn:

𝑦𝑖+1−2𝑦𝑖+𝑦𝑖−1

ℎ2+

2

𝑟𝑖

𝑦𝑖+1−𝑦𝑖−1

2ℎ+ 𝐴 = 0 − (1)

(𝑟𝑖 = 𝑖ℎ)

Discretized BCs:

𝑟𝑖 = 0

(𝑖 = 0)

𝑦1−𝑦−1

2ℎ= 0

𝑦−1 = 𝑦1

𝑟𝑖 = 𝑟𝑝 − 𝐷𝑝𝑦𝑁+1−𝑦𝑁−1

2ℎ= 𝑘𝑚(𝑦𝑁 − 𝐶𝑏)

𝑦𝑁+1 = (𝑦𝑁−1 −2ℎ

𝐷𝑝𝑘𝑚𝑦𝑛 +

2ℎ𝑘𝑚

𝐷𝑝𝐶𝑏)

Before you re-arrange the terms, you should realize that there is a clear discontinuity at 𝑟𝑖 =

0 (or 1st node). Therefore, you cannot proceed without removing discontinuity. One way of

doing this is to approximate 1

𝑟

𝑑𝑦

𝑑𝑟|𝑖=0

as 𝑑2𝑦

𝑑𝑟2|𝑖=0 because ∇y = 0 at r = 0

or 𝑦+1−2𝑦0+𝑦−1

ℎ2 + 2

𝑦1−2𝑦0+𝑦−1

ℎ2 + 𝐴 = 0

or (3𝑑2𝑦

𝑑𝑟2+ 𝐴) = 0

or 3𝑦1−2𝑦0+𝑦−1

ℎ2 + 𝐴 = 0 at 𝑖 = 0

Eq. (1) is applied over the next nodes, i.e., 𝑖 = 1⋯𝑁 without any discontinuity

0 1 2 𝑖 − 1 𝑖 𝑖 + 1 𝑁 − 1 𝑁

(𝑖 = 𝑁)

Page 111: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

Arrange the terms now,

{

𝑦−1 + (𝐴

ℎ23⁄ − 2) 𝑦0 + 𝑦1 = −𝐴 𝑟 = 0

(1

ℎ2−

1

𝑟1ℎ) 𝑦0 −

2

ℎ2𝑦1 + (

1

ℎ2+

1

𝑟1ℎ) 𝑦2 = −𝐴 𝑟 = 1

(1

ℎ2−

1

𝑟2ℎ) 𝑦1 −

2

ℎ2𝑦2 + (

1

ℎ2+

1

𝑟2ℎ) 𝑦3 = −𝐴 𝑟 = 2

(1

ℎ2−

1

𝑟𝑁ℎ) 𝑦𝑁−1 −

2

ℎ2𝑦𝑁 + (

1

ℎ2+

1

𝑟𝑁ℎ) 𝑦𝑁+1 = −𝐴 𝑟 = 𝑁

Apply the BCs (𝑖 = 0 and 𝑖 = 𝑁)

1𝑠𝑡 𝑟𝑜𝑤: (𝐴 ℎ2

3⁄ − 2) 𝑦0 + 2𝑦1 = −𝐴

𝐿𝑎𝑠𝑡 𝑟𝑜𝑤: 2

ℎ2𝑦𝑁−1 − (

2

ℎ2+2ℎ𝑘𝑚

𝐷𝑝× (

1

ℎ2+

1

𝑟𝑁ℎ))𝑌𝑁 = −𝐴 −

2ℎ𝑘𝑚

𝐷𝑝(1

ℎ2+

1

𝑟𝑁ℎ)𝐶𝑏

From the ‘preparation of tridiagonal matrix’ point of view,

𝑎0 = 1, 𝑏0 = (𝐴ℎ2

3⁄ − 2) , 𝑐0 = 1, 𝑑0 = −𝐴

and

𝑎𝑖 =1ℎ2⁄ −

1

𝑟𝑖ℎ , 𝑏𝑖 =

−2

ℎ2 , 𝑐𝑖 =

1

ℎ2+

1

𝑟𝑖 ℎ; 𝑑𝑖 = −𝐴 ; 𝑖 = 1 − 𝑁

However, on the substitution of BCs,

𝑐0 = 𝑐0 + 𝑎0 (1st row @ i = 0)

𝑎𝑁 = 𝑎𝑁 + 𝑐𝑁, 𝑏𝑁 = 𝑏𝑁 − 𝑐𝑁2ℎ𝑘𝑚

𝐷𝑝,

𝑑𝑁 = 𝑑𝑁 − 𝑐𝑁 .2ℎ𝑘𝑚

𝐷𝑝. 𝐶𝑏

} 𝑙𝑎𝑠𝑡 𝑟𝑜𝑤

Therefore, 𝐴�� = 𝐵. There are (𝑁 + 1) equations to solve (𝑁 + 1) unknown (𝑌0⋯𝑌𝑁) and A is

the tridiagonal matrix.

call Tridiagonal (𝑵 + 𝟏, 𝒂, 𝒃, 𝒄, 𝒅, 𝒚) |

𝑏0 𝑐0 0

0 𝑎𝑁 𝑏𝑁

|

Write a programming code to solve the SS profiles of CA(r) for different rp = 0.25,

0.5 and 1 mm, km = 0.01, 0.1, 0.5 m s⁄ and Dp = 10−7, 10−9, 10−11 m2

s⁄ .

Plot the profiles and interpret the results.

𝑖 = 0⋯𝑁

Page 112: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

Recall the course on chemical reaction engineering. Once SS CA(r) is calculated, you can

calculate the (total) effectiveness factor considering both inter- and intraphase diffusion

resistances by computing the total rate of the consumption of the species, A within the catalyst

and that corresponding to the bulk (gas) phase concentration. The computations may require

numerical integration (maybe, Simpson’s 1/3rd method) to calculate the volume-average

quantities and/or numerical differentiation (may be, 2nd order BDS) to calculate the flux at the

surface of the sphere.

Ex. Consider the steady-state 1D reactive flow (Re > 5000) of a gaseous species A in a 1ong

quartz tubular reactor (1D = D, length = L) radiated by UV light. Velocity in the tube is 𝑉.

The species A is converted into B by the 1st order homogeneous reaction (𝑟 = 𝑘𝐶𝐴), 𝑎𝑠 it flows

in the tube. The inlet concentration of A is 𝐶𝐴𝑜 . Determine the axial concentration profiles

𝐶𝐴(𝑋) =?. The reaction takes place under isothermal conditions and Δ𝐻 ≈ 0.

Soln: 𝜕𝐶𝐴

𝜕𝑡+ 𝑉. ∇𝐶𝐴 = 𝐷∇2𝐶𝐴 + (𝑟𝐴)

��𝑑𝐶𝐴

𝑑𝑋= 𝐷

𝑑2𝐶𝐴

𝑑𝑋2 − 𝑘𝐶𝐴

BC. 𝑋 = 0 𝐶𝐴 = 𝐶𝐴𝑜 , 𝑋 = 𝐿 ∇𝐶𝐴 = 0 or 𝑑𝐶𝐴

𝑑𝑋= 0 (long tube approximation)

𝑑𝐶𝐴

𝑑𝑋+ 𝐵

𝑑2𝐶𝐴

𝑑𝑋2+ 𝐶𝐶𝐴 = 0, 𝐵 = −𝐷

��⁄ ; 𝐶 =

𝑘

��, Δℎ = 𝐿

𝑁⁄

for increasingDp

𝐶𝐴𝑜 �� 𝑋

𝐿 𝑋

Δ𝑋

CA(𝑋) =?

(r = kCA)

𝑆𝑆

0 1 2 𝑖 − 1 𝑖 𝑖 + 1 𝑁 − 1 𝑁

Page 113: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

𝑦𝑖+1 − 𝑦𝑖−12ℎ

+ 𝐵𝑦𝑖+1 − 2𝑦𝑖 + 𝑦𝑖−1

ℎ2 + 𝐶𝑦𝑖 = 0, 𝑖 = 1,𝑁

Discretize BCs 𝑦0 = 𝐶𝐴𝑜; 𝑦𝑁+1−𝑦𝑁−1

2ℎ= 0 ⇒ 𝑦𝑁+1 = 𝑦𝑁−1

Collect the terms

(𝐵

ℎ2−

1

2ℎ) 𝑦𝑖−1 − (

2𝐵

ℎ− 𝐶)𝑦𝑖 + (

𝐵

ℎ2+

1

2ℎ) 𝑦𝑖+1 = 0, 𝑖 = 1, 𝑁

Prepare the tridiagonal matrix:

𝑎𝑖 = (𝐵

ℎ2−

1

2ℎ), , 𝑏𝑖 = (

2𝐵

ℎ− 𝐶) , 𝑐𝑖 = (

𝐵

ℎ2+

1

2ℎ), 𝑑𝑖 = 0; 𝑖 = 1, 𝑁

On substitution of BCs,

𝑑1 = 𝑑1 − 𝑎1𝐶𝐴𝑜 (i = 1, 1

st row) 𝑎𝑁 = 𝑎𝑁 + 𝑐𝑁 (i = N, last row)

You have 𝐴�� = ��, where A is the tridiagonal matrix.

𝑦 = 1,𝑁

call Tridiagonal (𝑵, 𝒂, 𝒃, 𝒄, 𝒅, 𝒚)

Plot (numerical solutions using reasonable values for 𝐷, ��, 𝑘, 𝐶𝐴𝑜 , 𝐿)

𝐿 𝑋 0

𝐶𝐴𝑜

Page 114: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

𝐏𝐚𝐫𝐭𝐢𝐚𝐥 𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐭𝐢𝐚𝐥 𝐄𝐪𝐮𝐚𝐭𝐢𝐨𝐧𝐬 (𝐏𝐃𝐄𝐬)

- Parabolic equations

1D ∶ A𝜕𝑦

𝜕𝑡+ B

𝜕2𝑦

𝜕𝑋2(or

𝐵

𝑟

𝜕

𝜕𝑟(𝑟𝜕𝑦

𝜕𝑟) or

𝐵

𝑟2

𝜕

𝜕𝑟(𝑟2

𝜕𝑦

𝜕𝑟)) + C

𝜕𝑦

𝜕𝑋+ Dy + E = 0

Such time dependent 1D (spatial) equations are common in heat/mass/momentum

transport. The PDE representing conservation of transport variables usually contains a

convective term (𝑉. ∇𝑇 or 𝑉. ∇𝐶 or 𝑉. ∇𝑉) and a diffusion term,

(𝛼∇2𝑇 or 𝐷∇2𝐶 or 𝜈∇2�� ), besides the unsteady-state or transient term

(𝜌𝐶𝑝𝜕𝑇

𝜕𝑡 or

𝜕𝐶

𝜕𝑡 or 𝜌

𝜕��

𝜕𝑡). Therefore,

𝜕𝐶𝐴𝜕𝑡

+ 𝑉𝑋𝜕𝐶𝐴𝜕𝑋

= 𝐷𝜕2𝐶𝐴𝜕𝑋2

− 𝑘𝐶𝐴

or 𝜌𝐶𝑝 (𝜕𝑇

𝜕𝑡+ 𝑉𝑋

𝜕𝑇

𝜕𝑋) = 𝑘

𝜕2𝑇

𝜕𝑋2 + (𝑘𝐶𝐴)(−Δ𝐻)

or 𝜌 (𝜕𝑉𝑋𝜕𝑡

+ 𝑉𝑋𝜕𝑉𝑋𝜕𝑋

) = 𝜇𝜕2𝑉𝑋𝜕𝑋2

− (𝑑𝑝

𝑑𝑋) + 𝜌𝑔𝑋

or 𝜌𝐶𝑝𝜕𝑇

𝜕𝑡=𝑘

𝑟2𝜕

𝜕𝑟(𝑟2

𝜕𝑇

𝜕𝑟)

or 𝜕𝐶𝐴𝜕𝑡

=𝐷

𝑟

𝜕

𝜕𝑟(𝑟𝜕𝐶𝐴𝜕𝑟) − 𝑘𝐶𝐴 }

1 DParabolicPDE

equation.

are all examples of the time-dependent 1D parabolic PDE. You may refer the book by Ferziger

for the exact mathematical definition of different types of PDE including parabolic, elliptic or

hyperbolic.

⇒ Why ‘Parabolic’? Because we march on time ‘endlessly’ covering the space.

⇒ Note: If you drop the time-dependent equation (or the unsteady-state or transient term),

what do you get? A boundary value problem (BVP), which we covered in the previous lectures.

⇒ Message is clear. Solving 1D parabolic PDE is not different from solving BVP. The procedure

for discretization in the space remains the same as before; it is to be repeated on every time step

as you march by refreshing the numerical values from the previous step. In fact, you may like to

copy and paste the programming code for BVP and nest it within the time loop. The graphical

representation of the numerical calculation is as follows.

March on time

𝑡 = 2

𝑡 = 1

𝑡 = 0 0 1

𝑋

𝑖 𝑖 − 1 𝑖 + 1

𝑖 + 1

𝑖 + 1

𝑖 − 1

𝑖 − 1

𝑖

𝑖

Page 115: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

Take a general case:

𝐴𝜕𝑦

𝜕𝑡+ 𝐵

𝜕𝑦

𝜕𝑋= 𝐶

𝜕2𝑦

𝜕𝑋2+ 𝐷 (or 𝐴

𝜕𝑦

𝜕𝑡= 𝑓(𝑦𝑋 , 𝑦𝑋𝑋 , 𝐷))

𝑡 = 0 𝑦 = 0 for all 𝐿 > 𝑋 > 0

𝑡 = 0+ 𝑋 = 0 𝑦 = 𝑦0 ; 𝑋 = 𝐿 𝜕𝑦

𝜕𝑋= 0

}

Steps

(1) Discretize ‘X’ -terms as before. On time, apply trapezoidal rule for integration:

𝐴𝑦𝑖𝑡+1 − 𝑦𝑖

𝑡

Δ𝑡=1

2[−𝐵 (

𝑦𝑖+1 − 𝑦𝑖−12Δℎ

)𝑡

− 𝐵 (𝑦𝑖+1 − 𝑦𝑖−1

2Δℎ)𝑡+1

+𝐶 (𝑦𝑖+1 − 2𝑦𝑖 + 𝑦𝑖−1

ℎ2)𝑡

+ 𝐶 (𝑦𝑖+1 − 2𝑦𝑖 + 𝑦𝑖−1

ℎ2)𝑡+1

] + 𝐷

(Note: ‘D’ is a const. 𝐷𝑡+𝐷𝑡+1

2= 𝐷!) – This method is better known as Crank-Nicolson.

Also note that you have used a 2nd order accurate scheme on both time and X.

(2) Collect all terms on (𝑡 + 1) on the LHS and 𝑡 on the RHS as

𝐴𝑦(𝑡+1) = 𝑑(𝑡)

1

2(−

𝐶

ℎ2−

𝐵

2Δℎ)𝑦𝑖−1

𝑡+1 + (𝐴

Δ𝑡+2𝐶

ℎ2) 𝑦𝑖

𝑡+1 +1

2(−

𝐶

ℎ2+

𝐵

2Δℎ)𝑦𝑖+1

𝑡+1

=1

2(𝐶

ℎ2+

𝐵

2Δℎ)𝑦𝑖−1

𝑡 + (𝐴

Δ𝑡−𝐶

ℎ2) 𝑦𝑖

𝑡 +1

2(𝐶

ℎ2−

𝐵

2Δℎ)𝑦𝑖+1

𝑡 +𝐷 𝑖 = 1, 𝑁

Note: All terms on RHS are known/calculated from the previous time step.

0

𝑖 − 1

𝑁 − 1 𝑁

𝑖 + 1

𝑖 + 1 𝑖 − 1 𝑖

𝑖 𝑁 − 1 𝑁

𝑡 + 1

𝑡 0 1

1 𝑀𝑎𝑟𝑐ℎ

𝑒𝑥𝑝𝑙𝑖𝑐𝑖𝑡 𝑖𝑚𝑝𝑙𝑖𝑐𝑖𝑡

𝑖𝑚𝑝𝑙𝑖𝑐𝑖𝑡 𝑒𝑥𝑝𝑙𝑖𝑐𝑖𝑡

Page 116: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #22

(… . . 𝒄𝒐𝒏𝒕𝒊𝒏𝒖𝒆)

(3) Apply BCs on both sides (𝑡 + 1) 𝑎𝑛𝑑 (𝑡):

𝑖 = 0 𝑦(𝑜) = 𝑦𝑜 for all 𝑡𝑠 (𝑡 + 1 𝑎𝑛𝑑 𝑡)

𝑖 = 𝑁 𝑦𝑁+1 = 𝑦𝑁−1 for all 𝑡𝑠 (𝑡 + 1 𝑎𝑛𝑑 𝑡)

1st row will change as:

(

𝐴

Δ𝑡+

𝐶

ℎ2) 𝑦1𝑡+1 +

1

2(−

𝐶

ℎ2 +𝐵

2Δℎ) 𝑦2

𝑡+1 =

(𝐶

ℎ2 +𝐵

2Δℎ) 𝑦0 + (

𝐴

Δ𝑡−

𝐶

ℎ2) 𝑦1𝑡 +

1

2(

𝐶

ℎ2 −𝐵

2Δℎ) 𝑦2

𝑡 + 𝐷} (𝑖 = 1)

Last row will change as:

−𝐶

ℎ2 𝑦𝑁−1𝑡+1 + (

𝐴

Δ𝑡+

𝐶

ℎ2) 𝑦𝑁𝑡+1 =

𝐶

ℎ2 𝑦𝑁−1𝑡 + (

𝐴

Δ𝑡−

𝐶

ℎ2) 𝑦𝑁𝑡 + 𝐷 (i = N)

The other rows (2 ⋯ 𝑁 − 1) will remain the same. Again the coefficient matrix is a

tridiagonal one:

𝐴𝑦(𝑡+1) = 𝑑(𝑡)

You have prepared the tridiagonal matrix as follows:

𝑎𝑖 = −1

2(

𝐶

ℎ2 +𝐵

2Δℎ) , 𝑏𝑖 = (

𝐴

Δ𝑡+

𝐶

ℎ2) , 𝑐𝑖 =1

2(−

𝐶

ℎ2 +𝐵

2Δℎ) , 𝑑𝑖 =

1

2(

𝐶

ℎ2 +𝐵

2Δℎ) 𝑦𝑖−1

𝑡 +

(𝐴

Δ𝑡−

𝐶

ℎ2) 𝑦𝑖 𝑡 +

1

2(

𝐶

ℎ2 −𝐵

2Δℎ) 𝑦𝑖+1

𝑡 + 𝐷; 𝑖 = 1, 𝑁

on application of BCs 𝑑1 = 𝑑1 − 𝑎1𝑦0 (1st row , 𝑖 =

1) Note that y0is substituted for yi−1t before applying BC.

𝑎𝑁 = 𝑎𝑁 + 𝑐𝑁 (last row, i = N)

𝑑𝑛 =𝐶

ℎ2𝑦𝑁−1

𝑡 + (𝐴

Δ𝑡−

𝐶

ℎ2) 𝑦𝑁

𝑡 + 𝐷

Page 117: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

(4) Start calculations: RHS is known from 𝑡 = 0 (initial condition

March on timeand call

𝐴𝑦(1) = 𝑏(0)

𝐴𝑦(2) = 𝑏(1)

⋮ 𝐴𝑦(𝑡+1) = 𝑏(𝑡)

Tridiagonal subroutine at every time step, & update 𝑦0 → 𝑦(1) → 𝑦(2) → ⋯

Tridiagonal (𝑁, 𝑎, 𝑏, 𝑐, 𝑑𝑡, 𝑦𝑡+1)

Convince yourself that the SS values will be the same as solving the corresponding BVP

by dropping the transient or unsteady-state term.

Ex:

Consider the SS flow of a liquid through a long tube. Reynolds number is 5000 and a

radially flat velocity profile may be assumed. At certain time a tracer is injected into the liquid

at the inlet. The dispersion coefficient of the tracer in the liquid may be assumed to be

𝐷 𝑐𝑚2 𝑠.⁄ Radial peclet number is large. Determine unsteady-state or transient axial

concentration profiles, 𝐶𝐴(𝑡, 𝑋) = ?

Soln:

𝜕𝐶𝐴

𝜕𝑡+ 𝑉. ∇𝐶𝐴 = 𝐷∇2𝐶𝐴 + 𝑟

𝜕𝐶𝐴

𝜕𝑡+ 𝑉𝑋

𝜕𝐶𝐴

𝜕𝑋= 𝐷

𝜕2𝐶𝐴

𝜕𝑋2 ; (neglecting radial term)

𝑡 = 0, 𝐶𝐴 = 0 for all 𝐿 > 𝑥 > 0

0+, 𝑋 = 0; 𝐶𝐴 = 𝐶𝐴,𝑖𝑛 (Inlet concentration of tracer)

𝑖 = 1, 𝑁

1 𝐷 𝑃𝑎𝑟𝑎𝑏𝑜𝑙𝑖𝑐

𝐵𝑉𝑃

𝑡

𝑦2

��0

Δ𝑋

CAo

t = 0 L

X V

(no − reaction)

(Pure liquid)

Page 118: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

𝑋 = 𝐿, ∇𝐶𝐴 = 0 (long − tube approximation) 𝑜𝑟 𝜕𝐶𝐴

𝜕𝑋= 0

𝜕𝐶𝐴

𝜕𝑡+ 𝑉𝑋

𝜕𝐶𝐴

𝜕𝑋= 𝐷

𝜕2𝐶𝐴

𝜕𝑋2 ; 𝑉𝑋 = ��

𝐶𝐴𝑖

𝑡+1 − 𝐶𝐴𝑖

𝑡

Δ𝑡=

1

2[𝐷 (

𝐶𝐴,𝑖+1 − 2𝐶𝐴,𝑖 + 𝐶𝐴,𝑖−1

ℎ2 )

𝑡+1

+ 𝐷 (𝐶𝐴,𝑖+1 − 2𝐶𝐴,𝑖 + 𝐶𝐴,𝑖−1

ℎ2 )

𝑡

− �� (𝐶𝐴,𝑖+1 − 𝐶𝐴,𝑖−1

2ℎ)

𝑡+1

− �� (𝐶𝐴,𝑖+1 − 𝐶𝐴,𝑖−1

2ℎ)

𝑡

]

(𝐷

2ℎ2+

��

4ℎ) 𝐶𝐴,𝑖−1

𝑡+1 − (1

Δ𝑡+

𝐷

ℎ2) 𝐶𝐴,𝑖

𝑡+1 + (𝐷

2ℎ2−

��

4ℎ) 𝐶𝐴,𝑖+1

𝑡+1

= − (𝐷

2ℎ2+

��

4ℎ) 𝐶𝐴,𝑖−1

𝑡 − (1

Δ𝑡−

𝐷

ℎ2) 𝐶𝐴,𝑖

𝑡 − (𝐷

2ℎ2−

��

4ℎ) 𝐶𝐴,𝑖+1

𝑡

𝑖 = 1, 𝑁

𝑖 = 0: 𝐶𝐴,0𝑡 = 𝐶𝐴,0

𝑡+1 = 𝐶𝐴,𝑖𝑛 (Inlet BC)

𝑖 = 𝑁: 𝐶𝐴,𝑁+1𝑡+1 = 𝐶𝐴,𝑁−1

𝑡+1 and 𝐶𝐴,𝑁+1𝑡 = 𝐶𝐴,𝑁−1

𝑡

* Prepare the tridiagonal matrix

𝑎𝑖 = (𝐷

2ℎ2+

��

4ℎ), 𝑏𝑖 = − (

𝐷

ℎ2+

1

Δ𝑡) , 𝑐𝑖 = (

𝐷

2ℎ2−

𝑉

4ℎ) , 𝑑𝑖

= − (𝐷

2ℎ2+

𝑉

4ℎ) 𝐶𝐴,𝑖−1

𝑡 − (1

Δ𝑡−

𝐷

ℎ2) 𝐶𝐴,𝑖

𝑡 − (𝐷

2ℎ2−

��

4ℎ) 𝐶𝐴,𝑖+1

𝑡

Apply BCs:

𝑑1 = 𝑑1 − 𝑎1𝐶𝐴,𝑖𝑛 : Note that 𝐶𝐴,𝑖𝑛 is substituted for 𝐶𝐴,𝑖−1𝑡 in 𝑑1.

𝑎𝑁 = 𝑎𝑁 + 𝑐𝑁

𝑑𝑁 = − (1

Δ𝑡−

𝐷

ℎ2) 𝐶𝐴,𝑁

𝑡 − (𝐷

ℎ2) 𝐶𝐴,𝑁−1

𝑡

You have 𝐴𝑦(𝑡+1) = 𝑑(𝑡) ; A ≡ Tridiagonal matrix with i = 1, N rows

𝑖 = 0

𝑖 = 0

𝑖 − 1 𝑖 𝑖 + 1 ℎ

𝑁

𝑁 𝑡 + 1

𝑡

′Δ𝑡′

Page 119: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Call Tridiagonal (N, a, b, c, d, y)

Start with 𝑡 = 0: 𝐶𝐴(𝑖 = 0, 𝑁) = 0 (pure solvent) or use a small concentration, 𝐶𝐴𝑖 ≪ 𝐶𝐴,𝑖𝑛𝑙𝑒𝑡.

Solve for 𝑦(1) 𝑜𝑟 𝐶𝐴(1)

𝑎𝑡 𝑡 = 1, recalculate RHS 𝑑(2) and keep on marching on time till a

steady-state solution or at 𝑡 = 𝑡𝑓𝑖𝑛𝑎𝑙 is reached.

Plot (use L = 10 cm, CA,i = 0.001, CA,inlet = 1.0, V = 0.1 cm s⁄ , D = 0.01 cm2 s⁄ )

} ⇒ 𝜕𝐶

𝜕𝑋= 0|

𝛼=𝐿

Note that

Tridiagonal matrix is called at every time-step.

�� vector is updated with the recent most 𝐶𝐴 values.

gradient at the exit must be flat (consistent with BC)

There are two steps (ℎ & Δ𝑡). How do you choose them?

No one knows! In general Δ𝑡 <Δ𝑋

𝑉,

Δ𝑋2

𝐷. Why? ?

One should choose a fixed Δ𝑋, and then refine ′Δ𝑡′ till there is a convergence in the solution.

Again, use Δ𝑋 = Δ𝑋2⁄ , adjust ′Δ𝑡′ till the solution converges, and so forth!

Ex. Repeat the previous problem, assuming that some solute is irreversibly adsorbed at the

tube-wall @ 𝑘𝐶𝐴 rate.

Species balance equation:

𝜕𝐶𝐴

𝜕𝑡+ 𝑉. ∇𝐶𝐴 = 𝐷∇2𝐶𝐴 − (𝑘𝐶𝐴)𝑎, where a is the specific surface area per unit

volume of the tube.

or 𝜕𝐶𝐴

𝜕𝑡+ ��

𝜕𝐶𝐴

𝜕𝑋= 𝐷

𝜕2𝐶𝐴

𝜕𝑋2 − 𝑘′𝐶𝐴;

1.0

0.001

0 𝑥 𝐿

𝑡

𝐶𝐴,𝑖𝑛 �� 𝐶𝐴(𝑡, 𝑋) =?

r = -kCA

Δ𝑋 L

X

Page 120: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

𝐼𝐶: 𝑡 = 0 𝐶𝐴 = 𝐶𝐴,𝑖 ,

𝐵𝐶 0+, 𝑋 = 0; 𝐶𝐴 = 𝐶𝐴,𝑖𝑛, 𝑋 = 𝐿, ∇𝐶𝐴 = 0 ⇒𝜕𝐶𝐴

𝜕𝑋= 0

𝐶𝐴𝑖𝑡+1−𝐶𝐴𝑖

𝑡

Δ𝑡=

1

2[𝐷 (

𝐶𝐴,𝑖+1−2𝐶𝐴,𝑖+𝐶𝐴,𝑖−1

ℎ2 )

𝑡+1

+ 𝐷 (𝐶𝐴,𝑖+1−2𝐶𝐴,𝑖+𝐶𝐴,𝑖−1

ℎ2 )

𝑡

− �� (𝐶𝐴,𝑖+1−𝐶𝐴,𝑖−1

2ℎ)

𝑡+1

�� (𝐶𝐴,𝑖+1−𝐶𝐴,𝑖−1

2ℎ)

𝑡

− (𝑘′𝐶𝐴,𝑖𝑡+1 + 𝑘′𝐶𝐴,𝑖

𝑡 )] Note: This is the extra term.

Re-arrange,

(𝐷

2ℎ2+

��

4ℎ) 𝐶𝐴,𝑖−1

𝑡+1 − (1

Δ𝑡+

𝐷

ℎ2+

𝑘′

2) 𝐶𝐴,𝑖

𝑡+1 + (𝐷

2ℎ2−

��

4ℎ) 𝐶𝐴,𝑖+1

𝑡+1

= − (𝐷

2ℎ2+

��

4ℎ) 𝐶𝐴,𝑖−1

𝑡 − (1

Δ𝑡−

𝐷

ℎ2−

𝑘′

2) 𝐶𝐴,𝑖

𝑡 − (𝐷

2ℎ2−

��

4ℎ) 𝐶𝐴,𝑖+1

𝑡

𝑖 = 1, 𝑁

𝐵𝐶𝑠: {𝑖 = 0, 𝐶𝐴,𝑜

𝑡 = 𝐶𝐴,𝑜𝑡+1 = 𝐶𝐴,𝑖𝑛 (for all time steps)

𝑖 = 𝑁, 𝐶𝐴,𝑁+1𝑡+1 = 𝐶𝐴,𝑁−1

𝑡+1 𝑎𝑛𝑑 𝐶𝐴,𝑁+1𝑡 = 𝐶𝐴,𝑁−1

𝑡

Prepare tridiagonal matrix:

𝑎𝑖 = (𝐷

2ℎ2+

��

4ℎ), 𝑏𝑖 = − (

1

Δ𝑡+

𝐷

ℎ2+

𝑘′

2) , 𝑐𝑖 = (

𝐷

2ℎ2−

��

4ℎ) , 𝑑𝑖

= − (𝐷

2ℎ2+

��

4ℎ) 𝐶𝐴,𝑖−1

𝑡 − (1

Δ𝑡−

𝐷

ℎ2−

𝑘′

2) 𝐶𝐴,𝑖

𝑡 − (𝐷

2ℎ2−

��

4ℎ) 𝐶𝐴,𝑖+1

𝑡

Apply BCs.

𝑑1 = − (𝐷

ℎ2+

��

2ℎ) 𝐶𝐴,𝑖𝑛 − (

1

Δ𝑡−

𝐷

ℎ2−

𝑘′

2) 𝐶𝐴,1

𝑡 − (𝐷

2ℎ2−

��

4ℎ) 𝐶𝐴,2

𝑡 : i =1 (1st row)

(Note that this step is the same as 𝑑1 = 𝑑1 − 𝑎1𝐶𝐴,𝑖𝑛)

𝑎𝑁 = 𝑎𝑁 + 𝑐𝑁

𝑑𝑁 = −𝐷

ℎ2 𝐶𝐴,𝑁−1𝑡 − (

1

Δ𝑡−

𝐷

ℎ2 −𝑘′

2) 𝐶𝐴,𝑁

𝑡 } 𝑖 = 𝑁 (𝑙𝑎𝑠𝑡 𝑟𝑜𝑤)

𝐴𝑦(𝑡+1) = 𝑑(𝑡); A is the tridiagonal matrix.

𝑖 = 0

0

𝑖 − 1 𝑖 𝑖 + 1 𝑁 − 1 𝑁

𝑡 + 1

𝑡

𝑖 − 1 𝑖 + 1 𝑁

1

Page 121: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

Proceed as before with initial condition CA(i = 1, N) = CA,i. Evaluate d(t), solve for

y(t+1), evaluate d(t+1), solve for y(t+2) ⋯ etc. Subroutine Tridiagonal (N, a, b, c, d, y) is called

at every time step. Plot qualitatively for the same conditions as before, use k = 0.1 s−1.

The axial concentration profiles for different ′ts′ will be the similar as before; however increase

in concentration with ‘t’ will be less than before because of the reactive/adsorptive wall.

𝐶𝐴,𝑖𝑛

𝐶𝐴

𝑡2 𝑡1

𝑡1

𝑡2

(non − reactive wall)

(reactive wall)

𝑋

Page 122: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #23

Example: Consider a spherical (𝑑𝑝 = 0.1 cm) steel pellet (𝑘 = 40W m− K ⁄ , ρ =

8000 kg m3 , Cp⁄ = 400 J kg − K.⁄ The initial temperature of the pellet is 300 𝐾. It is

immersed in a large oil tank at 400 K. The corrective heat transfer coefficient, ℎ𝑓 at the sphere

surface is 3000 𝑊 𝑚2𝐾.⁄ Solve for unsteady- state temperature profiles in the sphere. Choose

Δ𝑡 = 1 𝑠. Determine the average temperature in the sphere and the rate of which the surface

temperature decreases at 𝑡 = 20 𝑠.

* Recall: There is a discontinuity at 𝑖 = 0 (𝑟 = 𝑖ℎ)

However, the grad ∇𝑇 = 0 at 𝑟 = 0. Therefore, 1

𝑟

𝜕𝑇

𝜕𝑟≈

𝜕2𝑇

𝜕𝑟2

Energy balance equation:

𝜌𝐶𝑝𝜕𝑇

𝜕𝑡= 𝑘∇2𝑇 + 𝑆 (𝛼 = 𝑘

𝜌𝐶𝑝⁄ )

𝜕𝑇

𝜕𝑡=

𝛼

𝑟2𝜕

𝜕𝑟(𝑟2

𝜕𝑇

𝜕𝑟) 𝑟𝑝 > 𝑟 ≥ 0

𝐼𝐶: 𝑡 = 0 𝑇 = 300 𝐾(𝑇𝑜) for all 𝑟𝑝 ≥ 𝑟 ≥ 0

𝐵𝐶: 0+ 𝑟 = 0 ∇𝑇 = 0 𝑜𝑟 𝜕𝑇

𝜕𝑟= 0

𝑟 = 𝑟𝑝 − 𝑘𝜕𝑇

𝜕𝑟= ℎ(𝑇 − 𝑇𝑓)

or 𝑘𝜕𝑇

𝜕𝑟= ℎ(𝑇𝑓 − 𝑇)

𝑡

𝑡 = 0 300 𝐾

400 (𝑇𝑓) 𝑟

Δ𝑟 hf

rp

𝑑𝑞

Page 123: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

The equation is re-written as 𝜕𝑇

𝜕𝑡= 𝛼

𝜕2𝑇

𝜕𝑟2 +2𝛼

𝑟

𝜕𝑇

𝜕𝑟

Apply Crank-Nicholson discretization scheme:

𝑇𝑖𝑡+1 − 𝑇𝑖

𝑡

Δ𝑡=1

2[𝛼 (

𝑇𝑖+1 − 2𝑇𝑖 + 𝑇𝑖−1ℎ2

)𝑡+1

+ 𝛼 (𝑇𝑖+1 − 2𝑇𝑖 + 𝑇𝑖−1

ℎ2 )𝑡

+2𝛼

𝑟𝑖(𝑇𝑖+1 − 𝑇𝑖−1

2ℎ)𝑡+1

+2𝛼

𝑟𝑖(𝑇𝑖+1 − 𝑇𝑖−1

2ℎ)𝑡

]

Arrange: (𝛼

2ℎ2−

𝛼

2𝑟𝑖ℎ)𝑇𝑖−1

𝑡+1 − (1

Δ𝑡+

𝛼

ℎ2)𝑇𝑖

𝑡+1 + (𝛼

2ℎ2+

𝛼

2𝑟𝑖ℎ)𝑇𝑖+1

𝑡+1 = (𝛼

2𝑟𝑖ℎ−

𝛼

2ℎ2)𝑇𝑖−1

𝑡 +

(𝛼

ℎ2−

1

Δ𝑡)𝑇𝑖

𝑡 − (𝛼

2ℎ2−

𝛼

2𝑟𝑖ℎ)𝑇𝑖+1

𝑡 𝑖 = 1, 𝑁

Note 𝑖 = 0 requires a modified equation as (why?): 𝜕𝑇

𝜕𝑡= 3𝛼

𝜕2𝑇

𝜕𝑟2

The modified equation is discretized:

𝑇0𝑡+1 −𝑇0

𝑡

Δ𝑡=

3𝛼

2[(𝑇1−2𝑇0+𝑇−1

ℎ2 )𝑡+1

+ (𝑇1−2𝑇0+𝑇−1

ℎ2)𝑡

]: i = 0

(3𝛼

2ℎ2)𝑇−1

𝑡+1 − (3𝛼

ℎ2+

1

Δ𝑡) 𝑇0

𝑡+1 + (3𝛼

2ℎ2) 𝑇1

𝑡+1 = −(3𝛼

2ℎ2)𝑇−1

𝑡 + (3𝛼

ℎ2−

1

Δ𝑡)𝑇0

𝑡 − (3𝛼

2ℎ2)𝑇1

𝑡; i =0

Prepare tridiagonal matrix:

𝑎0 =3𝛼

2ℎ2 , 𝑏0 = −(

3𝛼

ℎ2+1

Δ𝑡) , 𝑐0 =

3𝛼

2ℎ2

𝑑0 = −(3𝛼

2ℎ2) 𝑇−1

𝑡 + (3𝛼

ℎ2−1

Δ𝑡) 𝑇0

𝑡 − (3𝛼

2ℎ2) 𝑇1

𝑡

} 𝑖 = 0

𝑎𝑖 = (𝛼

2ℎ2−

𝛼

2𝑟𝑖ℎ), 𝑏𝑖 = −(

𝛼

ℎ2+1

Δ𝑡) , 𝑐𝑖 = (

𝛼

2ℎ2+

𝛼

2𝑟𝑖ℎ) , 𝑑𝑖

= (𝛼

2𝑟𝑖ℎ−

𝛼

2ℎ2) 𝑇𝑖−1

𝑡 + (𝛼

ℎ2−1

Δ𝑡) 𝑇𝑖

𝑡 − (𝛼

2ℎ2+

𝛼

2𝑟𝑖ℎ)𝑇𝑖+1

𝑡

𝑖 = 1, 𝑁

Discretize BCs (1) 𝑟 = 0 𝜕𝑇

𝜕𝑟= 0 ⇒ 𝑖 = 0; 𝑇−1 = 𝑇+1

(2) 𝑟 = 𝑟𝑝 𝑘𝜕𝑇

𝜕𝑟= ℎ𝑓(𝑇𝑓 − 𝑇) 𝑖 = 𝑁;

0 1 𝑖 + 1

𝑖

𝑁 − 1 𝑁

(𝑟𝑖 = 𝑖ℎ) 0 1

𝑖 − 1

𝑁 𝑁 − 1

𝑡 + 1

𝑖 − 1

𝑖

𝑖 + 1

Page 124: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

𝑇𝑁+1 −𝑇𝑁−1

2h=

ℎ𝑓

𝑘(𝑇𝑓 − 𝑇𝑁)

or, 𝑇𝑁+1 = 𝑇𝑁−1 +2ℎ𝑓ℎ

𝐾(𝑇𝑓 − 𝑇𝑁)

Apply BC

𝑐0 = 𝑐0 + 𝑎0

𝑑0 = (3𝛼

ℎ2−

1

Δ𝑡)𝑇0

𝑡 −3𝛼

ℎ2𝑇1𝑡} 𝑖 = 0

𝑎𝑁 = 𝑎𝑁 + 𝑐𝑁

𝑑𝑁 = −𝛼

ℎ2𝑇𝑁−1𝑡 + (

𝛼

ℎ2−

1

Δ𝑡)𝑇𝑁

𝑡 + (𝛼

2ℎ2−

𝛼

2𝑟𝑖ℎ)2ℎ𝑓ℎ

𝑘𝑇𝑁𝑡 − (

𝛼

2ℎ2+

𝛼

2𝑟𝑖ℎ)2ℎ𝑓ℎ

𝑘𝑇𝑓

Call Tridiagonal(N+1, a,b,c,d,y)

Solve 𝐴𝑦(𝑡+1) = 𝑑(𝑡) , 𝑖 = 0, 𝑁 with initial condition: 𝑇 = 𝑇𝑖𝑛𝑖 = 300

𝐴𝑦(1) = 𝑑(0) ⇒ 𝐴𝑦(2) = 𝑑(1) ⇒ 𝐴𝑦(3) = 𝑑(2), 𝑒𝑡𝑐.

Once the functional values or y(t,r) or yit, i = 0, N are computed, the average

temperature of the sphere at any time, t can be calculated as the volume-average quantity

(why?), as follows:

3 ∑yiri2∆r/R3, i = 0, N and ri = ih (assuming the constant or average thermophysical properties

i,.e., ρ, Cp of the material). You can use the Simpson’s 1/3rd or Trapezoidal rule of integration.

Similarly, the rate of decrease of the surface temperature, viz. 𝜕𝑇

𝜕𝑡 @ 𝑟 = 𝑅 at any

time, t can be calculated using CDS as 𝑦(𝑡𝑖+1)−𝑦(𝑡𝑖−1)

2∆𝑡 or BDS as

4𝑦(𝑡𝑖+1)−3𝑦(𝑡𝑖)−𝑦(𝑡𝑖+2)

2∆𝑡 or FDS

as −4𝑦(𝑡𝑖−1)+3𝑦(𝑡𝑖)+𝑦(𝑡𝑖−2)

2∆𝑡 , depending upon the time, t. Therefore, you must use FDS at the

initial time, t = 0, etc.

Page 125: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Example: Consider the catalytic oxidation of 𝑆𝑂2 into 𝑆𝑂3 over a spherical Pt-dispersed porous

carbon catalyst (radius = 𝑟𝑝). The atmospheric concentration of 𝑆𝑂2 is 1%. The rate of

reaction is 𝑟 = 𝑘 (= 0.1) 𝐶𝐴mole s − m3⁄ . The film mass transfer coefficient is 𝑘𝑚(𝑚 𝑠).⁄

Determine the time-development of concentration profiles within the catalyst. The pore

diffusion coefficient of 𝑆𝑂2 is estimated to be 𝐷𝑚2 𝑠⁄ .

𝜕𝐶𝐴

𝜕𝑡=

𝐷

𝑟2𝜕

𝜕𝑟(𝑟2

𝜕𝐶𝐴

𝜕𝑟) − 𝑘𝐶𝐴 (1)

𝑡 = 0 𝐶𝐴 = 𝐶𝐴𝑖 ≪< 𝐶𝑏 for all 𝑟𝑝 ≥ 𝑟 ≥ 0

0+ ∇𝐶𝐴 = 0 @ 𝑟 = 0

−𝐷𝜕𝐶𝐴

𝜕𝑟= 𝑘𝑚(𝐶𝐴 − 𝐶𝑏) @ 𝑟 = 𝑟𝑝

Before you solve, two clarifications follow:

(1) The steady-state solution of eq(1) is the same as that of the equation solved in the

previous lectures for BVP. Therefore, one way of checking the present code for this

unsteady-state 1D parabolic equation is to compare its SS solution with that from the

BVP-code. In the latter lectures you will see that very often it is better to artificially

introduce the transient term (𝑣𝑖𝑧.𝜕𝑇

𝜕𝑡 ,𝜕𝐶

𝜕𝑡 ,𝜕𝑉

𝜕𝑡) in the BVPs and solve the entire time-

profiles, even when one is asked to solve the SS solution only. This strategy is often

followed for solving elliptic PDE.

(2) You should also compare this mass transport example with the previous example on

heat transfer. But for the non-homogenous term (𝑘𝐶𝐴), two equations are identically the

same, including the IC and BCs.

Recall:

𝐶𝑏 = 0.01 𝐶(𝑡, 𝑟) =?

𝑆𝑆

𝑘𝑚

𝑟𝑝

Page 126: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

𝜕𝑇

𝜕𝑡=

𝛼

𝑟2𝜕

𝜕𝑟(𝑟2

𝜕𝑇

𝜕𝑟)

𝐼𝐶 ∶ 𝑡 = 0 𝑇 = 𝑇𝑜

𝐵𝐶 1 ∶ 𝑟 = 0 𝜕𝑇

𝜕𝑟= 0

2 ∶ 𝑟 = 𝑟𝑝 − 𝑘𝜕𝑇

𝜕𝑟= ℎ𝑓(𝑇 − 𝑇𝑓)

𝜕𝐶𝐴

𝜕𝑡=

𝐷

𝑟2𝜕

𝜕𝑟(𝑟2

𝜕𝐶𝐴

𝜕𝑟)

𝐶𝐴 = 𝐶𝐴𝑖 for all 𝑟𝑝 > 𝑟 > 0𝜕𝐶𝐴

𝜕𝑟= 0

−𝐷𝜕𝐶𝐴

𝜕𝑟= 𝑘𝑚(𝐶𝐴 − 𝐶𝑏)

All it means is that their non-dimensionalized forms are identically the same:

𝜕𝜃

𝜕𝜏=1

𝜉2𝜕

𝜕𝜉(𝜉2

𝜕𝜃

𝜕𝜉)

where,

{

𝜃 =

𝑇 − 𝑇𝑜𝑇𝑓 − 𝑇𝑜

, 𝐶𝐴 − 𝐶𝐴𝑖𝐶𝐴,𝑏 − 𝐶𝐴𝑖

𝜉 = 𝑟𝑟𝑝⁄

𝜏 = 𝑡 𝑡𝑐 ⁄ ; 𝑡𝑐 =𝑟𝑝2

𝛼 ,

𝑟𝑝2

𝐷

𝐼𝐶. 𝜏 = 0 𝜃 = 0

𝐵𝐶 1. 𝜉 = 0 𝜕𝜃

𝜕𝜉= 0

2. 𝜉 = 1 −𝜕𝜃

𝜕𝜉= 𝐴(𝜃 − 1) , where A = Nu or Sh

Therefore, it is clear that their (non-dimensional) solutions will also be the same.

It also follows that one should non-dimensionalize the transport equations, as a good practice,

before solving the equations. Apart from learning about transport phenomena from the analogy

between heat, mass and momentum, there is a possibility that the non-dimensional forms of the

conservation equations & the respective bcs being the same, the non-dimensionalized solutions

will also be the same. In such cases or similar cases, the programming code written for one

problem will be the same or similar, requiring small modifications.

Let us continue with the non-dimensionalized form of the present mass transport problem:

𝜕𝜃

𝜕𝜏=

1

𝜉2𝜕

𝜕𝜉(𝜉2

𝜕𝜃

𝜕𝜉) − 𝐵𝜃 − 𝐶 , where 𝐵 = 𝑘𝑡𝑐 , 𝐶 = 𝑘𝑡𝑐

𝐶𝐴𝑖

𝐶𝐴,𝑏−𝐶𝐴𝑖

Discretize:

𝑖 = 0 𝑖 − 1 𝑖 + 1 𝑖 𝑁

𝑁 𝜏 + 1

𝜏

Page 127: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

𝜃𝑖𝜏+1 − 𝜃𝑖

𝜏

Δ𝜏=1

2[(𝜃𝑖+1 − 2𝜃𝑖 + 𝜃𝑖−1

Δ𝜉2 )𝜏+1

+ (𝜃𝑖+1 − 2𝜃𝑖 + 𝜃𝑖−1

Δ𝜉2 )𝜏

+2

𝜉𝑖(𝜃𝑖+1 − 𝜃𝑖−12Δ𝜉

)𝜏+1

+2

𝜉𝑖(𝜃𝑖+1 − 𝜃𝑖−12Δ𝜉

)𝜏

− 𝐵(𝜃𝑖𝜏+1 + 𝜃𝑖

𝜏)] − 𝐶

𝑖 = 0,𝑁

@𝑖 = 0 there is a discontinuity in the equation. Therefore,

𝜃0𝜏+1 −𝜃0

𝜏

Δ𝜏=

3

2[(𝜃1−2𝜃0+𝜃−1

Δ𝜉2 )𝜏+1

+ (𝜃1−2𝜃0+𝜃−1

Δ𝜉2 )𝜏

+𝐵

2(𝜃0

𝜏+1 + 𝜃0𝜏)] − 𝐶 for i = 0

Apply BCs

𝑖 = 0 𝜃−1 = 𝜃1

𝑖 = 𝑁 −𝜃𝑁+1−𝜃𝑁−1

2Δ𝜉 = 𝐴(𝜃𝑁 − 1)

𝑜𝑟 𝜃𝑁+1 = 𝜃𝑁−1 − 2𝐴Δ𝜉(𝜃𝑁 − 1)

}

𝑖 = 0: (1

Δ𝜏+

3

Δ𝜉2−𝐵

2)𝜃0

𝜏+1 −3

Δ𝜉2𝜃1𝜏+1 = (

1

Δ𝜏−

3

Δ𝜉2+𝐵

2)𝜃0

𝜏 +3

2Δ𝜉2𝜃1𝜏 − 𝐶

𝑖 = 𝑁: (1

Δ𝜉2) 𝜃𝑁−1

𝜏+1 − (1

Δ𝜉2+𝐵

2+1

Δ𝜏) 𝜃𝑁

𝜏+1 = −(1

Δ𝜉2) 𝜃𝑁−1

𝜏 − (1

Δ𝜏−

1

Δ𝜉2−𝐵

2)𝜃𝑁

𝜏 + 𝐶

𝑖 = 1, 𝑁 − 1 (1

2Δ𝜉2−

1

2Δ𝜉𝜉𝑖) 𝜃𝑖−1

𝜏+1 − (1

Δ𝜏+

1

Δ𝜉2−𝐵

2)𝜃𝑖

𝜏+1 + (1

2Δ𝜉2−

1

2𝜉Δ𝜉) 𝜃𝑖+1

𝜏+1

= (−1

2Δ𝜉2+

1

2Δ𝜉𝜉) 𝜃𝑖−1

𝜏 − (1

Δ𝜏−

1

Δ𝜉2−𝐵

2)𝜃𝑖

𝜏 + (−1

2Δ𝜉2−

1

2Δ𝜉𝜉) 𝜃𝑖+1 + 𝐶

d

Solve 𝐴𝜃𝜏+1 = 𝑑𝜏 , 𝑖 = 0, 𝑁 with 𝐼𝐶 𝜃 = 0 @ 𝜏 = 0 (same as before, 𝐴 ≡ Tridiagonal matrix)

Here, we skipped the steps for preparing tridiagonal matrix and directly substituted

discretized BCs into the discretized equations! As an exercise, prepare tridiagonal matrix and

see if you get the same discretized equations post substitution of BCs, as before.

Quiz III

Page 128: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #24-25

Elliptic PDE (Method of Lines)

The model equations may be recognized by the following examples:

(1) 𝑘 (𝜕2𝑇

𝜕𝑋2+

𝜕2𝑇

𝜕𝑦2) + 𝑆 = 0 ; 𝑆 ≡ 𝐼

2𝑅∀⁄ 𝑐𝑎𝑙

𝑠 − 𝑚3⁄

(2) 𝑘 (𝜕2𝑇

𝜕𝑋2+1

𝑟

𝜕

𝜕𝑟(𝑟

𝜕𝑇

𝜕𝑟)) + 𝑆 = 0

--- SS 2D temperature profiles in a (1) rectangular plate and (2) cylindrical wire because of

uniform heating

(3) 𝑉𝑋𝜕𝐶

𝜕𝑋= 𝐷

𝜕2𝐶

𝜕𝑋2+𝐷

𝑟(𝜕

𝜕𝑟(𝑟

𝜕𝐶

𝜕𝑟)) − 𝑘𝐶

---- SS 2D concentration distributions of a solute in the reactive flow in a tube

(4) 𝑉𝑋𝜕𝑇

𝜕𝑋= 𝛼

𝜕2𝑇

𝜕𝑋2+ 𝛼

𝜕2𝑇

𝜕𝑦2

- SS 2D temperature distributions in a flow through rectangular channel.

(5) 𝜌𝑉𝑋𝜕𝑉𝑋

𝜕𝑋= 𝜇 (

𝜕2𝑉𝑋

𝜕𝑋2+1

𝑟

𝜕

𝜕𝑟(𝑟

𝜕𝑉𝑋

𝜕𝑟)) −

𝑑𝑝

𝑑𝑥

- SS 2D velocity profiles of an incompressible NF in a pressure-driven horizontal flow.

By now, you must have realized that we are referring to an elliptic PDE which describes a SS

2D (no time-dependent term) heat/mass/momentum transport. Why is the equation called

elliptic? Because one has to solve the entire 2D space. Considering that there is the SS

consideration, there is no ‘marching’ on time as such and the updating of the solutions from the

previous time-step, as we earlier discussed for the parabolic PDEs. The solution in this case

must be sought one-time only under SS conditions. You will see later that solving elliptic

equations is computational extensive requiring iterations.

- The best way of understanding the numerical technique for solving an elliptic PDE is to

directly take the example (1) above.

Page 129: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

Ex: A rectangular plate (𝐿 × 𝑤 × 𝑡ℎ) fabricated from stainless steel (𝑘 = 40 𝑊 𝑚 − 𝑘⁄ , 𝜌 =

8000 𝑘𝑔 𝑚3,⁄ 𝐶𝑝 = 400 𝐽 𝑘𝑔 𝐾)⁄ is uniformly heated using an electric power source (100 𝑊).

The top and bottom ends are insulated, whereas the side surfaces are exposed to atmosphere

(𝑇𝑎 = 300 𝐶, ℎ = 100𝑊 𝑚2𝑘⁄ ). Determine the SS temperature profiles in the plate.

2D energy balance over ′Δ𝑥Δ𝑦𝑡ℎ′𝐶𝑉 under SS:

𝜌𝐶𝑝 (𝜕𝑇

𝜕𝑡+ 𝑉. ∇𝑇) = 𝑘∇2𝑇 + 𝑆: 𝑊 𝑚3⁄

𝑘 (𝜕2𝑇

𝜕𝑥2+

𝜕2𝑇

𝜕𝑦2) + 𝑆 = 0; S = 100 W/m3 of the plate volume

BCs: 𝑥 = 0 𝑓or 𝑤 > 𝑦 > 0 ; −𝑘𝜕𝑇

𝜕𝑥= −ℎ𝑓(𝑇 − 𝑇𝑎)

= 𝐿 for 𝑤 > 𝑦 > 0 ; −𝑘𝜕𝑇

𝜕𝑥= ℎ𝑓(𝑇 − 𝑇𝑎)

𝑦 = 0 and 𝑤 for 𝐿 > 𝑥 > 0, − 𝑘𝜕𝑇

𝜕𝑦= 0(insulation)

𝑦

𝑀

𝑤 ℎ𝑓

(𝑇𝑎)300𝐶

𝑂

30 0𝐶(𝑇𝑎)

ℎ𝑓 𝐿

−𝑘𝜕𝑇

𝜕𝑦= 0

ℎ𝑓

−𝑘𝜕𝑇

𝜕𝑦= 0

(𝑖, 𝑗 + 1)

(𝑖 + 1, 𝑗) (𝑖, 𝑗) (𝑖 − 1, 𝑗)

(𝑖, 𝑗 − 1)

Δ𝑥

Δ𝑦

N X

S (𝑊 𝑚3)⁄ = (100 𝑊

𝐿 ×𝑊 × 𝑡ℎ)

(ℎ𝑒𝑎𝑡 𝑠𝑜𝑢𝑟𝑐𝑒)

𝑆𝑆 0, 𝑠𝑜𝑙𝑖𝑑

Page 130: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

Computational molecule:

Discretize equations over (𝑖, 𝑗). Note that it is a 2D problem. Therefore, one will have to

discretize in both directions (𝑥, 𝑦) using steps Δ𝑥 and Δ𝑦, respectively. They need not be equal.

𝑘 [(𝜕2𝑇

𝜕𝑋2)𝑖,𝑗+ (

𝜕2𝑇

𝜕𝑦2)𝑖,𝑗] + 𝑆𝑖,𝑗 = 0

(𝑇𝑖−1,𝑗 − 2𝑇𝑖,𝑗 + 𝑇𝑖+1,𝑗

Δ𝑥2) + (

𝑇𝑖,𝑗−1 − 2𝑇𝑖,𝑗 + 𝑇𝑖,𝑗+1

Δ𝑦2) +

𝑆𝑖,𝑗

𝑘= 0

(As expected, when discretizing 𝜕2𝑇

𝜕𝑋2, 𝑗 is constant, and when discretizing

𝜕2𝑇

𝜕𝑦2, 𝑖 is constant)

There are two ways to arrange the discretized terms to

𝐴�� = 𝑏 form ∶

(1)1

Δ𝑥2(𝑇𝑖−1,𝑗 − 2𝑇𝑖,𝑗 + 𝑇𝑖+1,𝑗) = −

1

Δ𝑦2(𝑇𝑖,𝑗−1 − 2𝑇𝑖,𝑗 + 𝑇𝑖,𝑗+1) −

𝑆𝑖,𝑗

𝑘

(2) 1

Δ𝑦2(𝑇𝑖,𝑗−1 − 2𝑇𝑖,𝑗 + 𝑇𝑖,𝑗+1) = −

1

Δ𝑥2(𝑇𝑖−1,𝑗 − 2𝑇𝑖,𝑗 + 𝑇𝑖+1,𝑗) −

𝑆𝑖,𝑗

𝑘

Notes: 1. Although the linear algebraic equations have taken the form of 𝐴�� = 𝑏 in both cases,

𝑏 or RHS terms are not known. Therefore, in principle �� 𝑜𝑟 �� cannot be solved by inverting

the ‘matrix’ formed on LHS, the way we did in the previous cases. In other words, there is no

way one can march in 𝑥 𝑜𝑟 𝑦 direction and solve the unknown variables, because marching in

either direction (𝑖 𝑜𝑟 𝑗) creates unknown variables in the other direction (𝑗 𝑜𝑟 𝑖). In fact, one

has to solve the ‘entire space’ at one time (without marching). This is the problem in solving an

elliptic PDE!

(2) The only way to solve an elliptic PDE or 𝐴�� = 𝑏 , where 𝐴 is the tridiagonal matrix, is by

making guess for all variables (𝑇𝑖,𝑗) to start with, so that 𝑏 (RHS term) is known. Then, ��

(which is similar to 𝑏 ) can be solved. Next, compare the newly calculated values with the guess

values and iterate till there is the convergence:

(𝑖 − 1)

(𝑗 + 1)

(𝑖 + 1)

(𝑗 − 1)

(𝑖, 𝑗)

Δ𝑥 = 𝐿 𝑁⁄

Δ𝑦 = 𝑊 𝑀⁄

𝑖 = 0… 𝑁𝑗 = 0… 𝑀

}

Page 131: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

𝐴𝑦𝑘+1 = 𝑏𝑘 b0 = initial guess for (Ti,j)

k = # of iterations.

(3) Either of the two discretized schemes (1) & (2) can be used to solve 𝑇𝑖,𝑗. In general, one

should sweep the discretized set of equations in the direction the expected solution (functional

value) is lesser stiff than in the other direction. In the present example, 𝑤 ≪ 𝐿 and the y-ends

are insulated. One should use scheme (1). The convergence will be relatively faster.

1

Δ𝑥2(𝑇𝑖−1,𝑗 − 2𝑇𝑖,𝑗 + 𝑇𝑖+1,𝑗) = −

1

Δ𝑦2(𝑇𝑖,𝑗−1 − 2𝑇𝑖,𝑗 + 𝑇𝑖,𝑗+1)

𝑔−𝑆𝑖,𝑗

𝐾 (1)

Prepare tridiagonal matrix:

𝑎(𝑖, 𝑗) =1

Δ𝑥2 ; 𝑏(𝑖, 𝑗) = −

2

Δ𝑥2, 𝑐(𝑖, 𝑗) =

1

Δ𝑥2

𝑑(𝑖, 𝑗) = −1

Δ𝑦2(𝑇𝑖,𝑗−1 − 2𝑇𝑖,𝑗 + 𝑇𝑖,𝑗+1)

𝑔−𝑆𝑖,𝑗

𝑘 }

𝑖 = 0,𝑁𝑗 = 0,𝑀

The superscript "g" stands for the guess values. Once the initial guess is made, one can now

march along ‘𝑗’ direction, solving 𝑇𝑖,𝑗 at every ‘𝑗𝑡ℎ ’ step as 𝐴��𝑗 = 𝑏,where 𝐴 is the

tridiagonal matrix containing the discretized ‘𝑦’ along ‘𝑖’ direction for a fixed 𝑗, and 𝑏 is known

from the guess.

Discretize BCs

{

(𝑖 = 0), 𝑗: − 𝑘

𝑇1,𝑗 − 𝑇−1,𝑗

2Δ𝑥= −ℎ𝑓(𝑇0,𝑗 − 𝑇𝑎)

or 𝑇−1,𝑗 = 𝑇1,𝑗 −2ℎ𝑓Δ𝑥

𝑘 (𝑇0,𝑗 − 𝑇𝑎)

(𝑖 = 𝑁), 𝑗: 𝑇𝑁+1,𝑗 = 𝑇𝑁−1,𝑗 −2ℎ𝑓Δ𝑥

𝑘 (𝑇𝑁,𝑗 − 𝑇𝑎)

(𝑗 = 0), 𝑖: 𝑇𝑖,−1 = 𝑇𝑖,1

(𝑗 = 𝑀), 𝑖: 𝑇𝑖,𝑀+1 = 𝑇𝑖,𝑀−1

Apply BCs

𝑗 = 0

𝑖 = 0 1 𝑖 − 1 𝑖 𝑖 + 1 𝑁 − 1 𝑁

Page 132: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

𝑐(0,0) = 𝑐(0,0) + 𝑎(0,0)

𝑏(0,0) = 𝑏(0,0) −2ℎ𝑓Δ𝑥

𝑘𝑎(0,0)

𝑑(0,0) =2

Δ𝑦2(𝑇0,0 − 𝑇0,1)

𝑔−𝑆0,0𝑘−2ℎ𝑓Δ𝑥

𝑘. 𝑇𝑎. 𝑎(0,0)}

𝑖 = 0

𝑑(𝑖, 0) =2

Δ𝑦2(𝑇𝑖,0 − 𝑇𝑖,1)

𝑔−𝑆𝑖,0

𝑘; 𝑖 = 1, 𝑁 − 1

𝑎(𝑁, 0) = 𝑎(𝑁, 0) + 𝑐(𝑁, 0)

𝑏(𝑁, 0) = 𝑏(𝑁, 0) −2ℎ𝑓Δ𝑥

𝑘𝑐(𝑁, 0)

𝑑(𝑁, 0) =2

Δ𝑦2(𝑇𝑁,0 − 𝑇𝑁,1)

𝑔−𝑆𝑁,0𝑘−2ℎ𝑓Δ𝑥

𝑘𝑇𝑎 𝑎(𝑁, 0)}

𝑖 = 𝑁

Tridiag(𝑁 + 1, 𝑎, 𝑏, 𝑐, 𝑑, 𝑇𝑖,0) (𝑖 = 0,𝑁)

𝑗 = 1,𝑀 − 1

𝑐(0, 𝑗) = 𝑐(0, 𝑗) + 𝑎(0, 𝑗)

𝑏(0, 𝑗) = 𝑏(0, 𝑗) −2ℎ𝑓Δ𝑥

𝑘𝑎(0, 𝑗)

𝑑(0, 𝑗) = 𝑑(0, 𝑗) − (2ℎ𝑓Δ𝑥

𝑘)𝑇𝑎𝑎(0, 𝑗)

}

𝑖 = 0

⇒ No coefficients will change for the rows, 𝒊 = 𝟏,𝑵 − 𝟏, because all of these

correspond to interior nodes:

𝑀 − 1

𝑀

𝐽

𝑁 − 1

𝑁 𝑖 0,0

Page 133: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

𝑎(𝑁, 𝑗) = 𝑎(𝑁, 𝑗) + 𝑐(𝑁, 𝑗)

𝑏(𝑁, 𝑗) = 𝑏(𝑁, 𝑗) − (2ℎ𝑓Δ𝑥

𝑘) 𝑐(𝑁, 𝑗)

𝑑(𝑁, 𝑗) = 𝑑(𝑁, 𝑗) − (2ℎ𝑓Δ𝑥

𝑘)𝑇𝑎 𝑐(𝑁, 𝑗)

}

𝑖 = 𝑁

Tridiag(𝑁 + 1, 𝑎, 𝑏, 𝑐, 𝑑, 𝑇𝑖,𝑗) (𝑖 = 0, 𝑁)

𝑗 = 𝑀

𝑐(0, 𝑗) = 𝑐(0, 𝑗) + 𝑎(0, 𝑗)

𝑏(0, 𝑗) = 𝑏(0, 𝑗) −2ℎ𝑓Δ𝑥

𝑘𝑎(0, 𝑗)

𝑑(0, 𝑗) =2

Δ𝑦2(−𝑇0,𝑀−1 + 𝑇0,𝑀)

𝑔−𝑆0,𝑀𝑘

− (2ℎ𝑓Δ𝑥

𝑘)𝑇𝑎𝑎(0, 𝑗)

}

𝑖 = 0

𝑑(𝑖, 𝑗) = −2

Δ𝑦2(−𝑇𝑖,𝑀−1 + 𝑇𝑖,𝑀)

𝑔−𝑆𝑖,𝑀

𝑘; 𝑖 = 1, 𝑁 − 1

𝑎(𝑁, 𝑗) = 𝑎(𝑁, 𝑗) + 𝑐(𝑁, 𝑗)

𝑏(𝑁, 𝑗) = 𝑏(𝑁, 𝑗) −2ℎ𝑓Δ𝑥

𝑘𝑐(𝑁, 𝑗)

𝑑(𝑁, 𝑗) =2

Δ𝑦2(−𝑇𝑁,𝑀−1 + 𝑇𝑁,𝑀)

𝑔−𝑆𝑁,𝑀𝑘

−2ℎ𝑓Δ𝑥

𝑘𝑇𝑎𝑐(𝑁, 𝑗)}

𝑖 = 𝑁

Tridiag(𝑁 + 1, 𝑎, 𝑏, 𝑐, 𝑑, 𝑇𝑖,𝑗) (𝑖 = 0, 𝑁)

You have, therefore, called Tridiagonal subroutine ‘𝑀 + 1’ times as you marched along ‘𝑗’

direction. At the end, entire ‘𝑥 − 𝑦’ grids have been solved for 𝑇𝑖,𝑗(𝑖 = 0,𝑁; 𝑗 = 0,𝑀).

Compare solved values with the guess values and keep iterating till there is a convergence.

⇒ Solving an elliptic PDE is indeed computational extensive because there is a convergence

issue using the guesses.

⇒ There is another twist in solving an elliptic PDE. Do you update your guess values of ��

(RHS terms) at ‘𝑗’ with the ones solved at ‘𝑗 − 1’ as you march in y-direction, or do you wait till

you have solved till ‘𝑀’ (the last boundary)? This question should remind you of the G-S and

Jacobi iterations. Choice is yours. A fast convergence is the criterion. Also, the relaxation

factor, ‘𝑤’ can be used to update the functional values in either case: 𝑇𝑖,𝑗 = 𝑤𝑇′𝑖,𝑗 + (1 − 𝑤)𝑇𝑖,𝑗

, where T’ and T are the new and old values, respectively.

Page 134: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #25-26

Ex 2: Consider the fully developed SS flow (Re = 200) of an incompressible NF in a long

horizontal tube (L, D). The inlet temperature of the liquid is 𝑇𝑜 . The heat is supplied to the

flowing liquid at constant flux 𝑞𝑤(𝑊 𝑚2⁄ ) through the tube walls. Determine the 2D (𝑟, 𝑥) SS

temperature profiles in the tube.

Energy balance over ′2𝜋𝑟Δ𝑟Δ𝑋′ 𝐶𝑉:

𝜌𝐶𝑝𝑉𝑋. ∇𝑇 = 𝑘∇2𝑇 + 𝑆 ( 𝐽 𝑜𝑟 𝑐𝑎𝑙 𝑠 − 𝑚3⁄ )

𝑉(𝑟)𝜕𝑇

𝜕𝑋= 𝛼 (

𝜕2𝑇

𝜕𝑋2+1

𝑟

𝜕

𝜕𝑟(𝑟

𝜕𝑇

𝜕𝑟)) 𝛼 =

��

���� ;

BC. 𝑋 = 0 𝑇(𝑟) = 𝑇𝑜 𝑅 ≥ 𝑟 ≥ 0

𝑋 = 𝐿 +𝜕𝑇

𝜕𝑋= 0 (long tube approximation)

𝑟 = 0 𝜕𝑇

𝜕𝑟= 0 (symmetric BC)

𝑟 = 𝑅 − 𝑘𝜕𝑇

𝜕𝑟= −𝑞𝑊 (𝑊 𝑚2)⁄

𝑜𝑟 𝑘𝜕𝑇

𝜕𝑟= 𝑞𝑊 }

𝐿 ≥ 𝑧 ≥ 0

Let us non-dimensionalize the equation & BC

𝜃 =𝑇

To, 𝑧 =

𝑋

Lc 𝑤here Lc = RPe where Pe(radial) =

Umax R

α, ξ =

r

R

𝑈𝑚𝑎𝑥(1 − 𝜉2)

Lc

𝜕𝜃

∂z= α(

1

Lc2𝜕2𝜃

∂z2+1

R2𝜕2𝜃

∂ξ2+1

R21

ξ

𝜕𝜃

∂ξ)

𝑟

Δ𝑟

𝑋

𝑞𝑤 𝑊 𝑚2⁄

𝑟 Δ𝑟

Δ𝑋 𝑞𝑤 𝑊 𝑚2⁄

𝐿

𝑅 𝑇𝑜

𝑢(𝑟) = 𝑈𝑚𝑎𝑥 (1 −𝑟2

𝑅2) (𝑅𝑒 = 200); 𝜌 , 𝐶𝑝, 𝑘 ≡ 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡

T(r, X) = ?

Page 135: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

or

(1 − 𝜉2)𝜕𝜃

∂z=

1

𝑃𝑒2𝜕2𝜃

∂z2+𝜕2𝜃

∂ξ2+1

ξ

𝜕𝜃

∂ξ

BCs:

𝑧 = 0 𝜃 = 1

𝑧 = 𝐿 𝐿𝑐⁄ +

𝜕𝜃

𝜕𝑧= 0}1 > 𝜉 > 0

𝜉 = 0 𝜕𝜃

𝜕𝜉= 0

𝜉 = 1 𝜕𝜃

𝜕𝜉= (

𝑞𝑊𝑅

𝑘𝑇𝑜) = 𝐻(constant) for 𝐿 𝐿𝑐

⁄ > 𝑧 > 0

Before solving, let us consider another example on mass transport.

Ex. Consider the fully developed SS flow (𝑅𝑒 = 200) of an incompressible NF in a long

horizontal tube (𝐿, 𝐷). The inlet concentration of the species A in the liquid is 𝐶𝐴𝑜 .The species

are catalytically destroyed at the tube walls by the zeroth order chemical reaction

(𝑘 𝑚𝑜𝑙𝑒 𝑠 − 𝑚3).⁄ Determine the 2D (𝑟, 𝑋)𝑆𝑆 concentration profiles in the tube.

Species balance over (2𝜋𝑟Δ𝑟Δ𝑋) 𝐶, 𝑉.

𝑉𝑋𝜕𝐶𝐴𝜕𝑋

= 𝐷 (𝜕2𝐶𝐴𝜕𝑋2

+1

𝑟

𝜕

𝜕𝑟(𝑟𝜕𝐶𝐴𝜕𝑟)) moles s − m3⁄

𝑈𝑚𝑎𝑥 (1 −𝑟2

𝑅2)𝜕𝐶𝐴𝜕𝑋

= 𝐷 (𝜕2𝐶𝐴𝜕𝑋2

+1

𝑟

𝜕

𝜕𝑟(𝑟𝜕𝐶𝐴𝜕𝑟))

= 𝐷 (𝜕2𝐶𝐴

𝜕𝑋2+𝜕2𝐶𝐴

𝜕𝑟2+1

𝑟

𝜕𝐶𝐴

𝜕𝑟)

BCs. 𝑋 = 0 𝐶𝐴 = 𝐶𝐴𝑜 , 𝑋 = 𝐿 𝜕𝐶𝐴

𝜕𝑥= 0 (𝑅 > 𝑟 > 0)

𝑟 = 0 𝜕𝐶𝐴

𝜕𝑟= 0 𝑟 = 𝑅 , − 𝐷

𝜕𝐶𝐴

𝜕𝑟= 𝑘 (𝐿 > 𝑋 > 0)

Let us non-dimensionalize the equation & BCs:

𝑋 𝐶𝐴𝑜 𝐶(𝑟, 𝑋) 𝑟 = −𝑘 Δ𝑟

𝑟

Δ𝑋

𝑅

𝑢(𝑟) = 𝑈𝑚𝑎𝑥 (1 −𝑟2

𝑅2)

Page 136: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

𝜃 =𝐶𝐴

𝐶𝐴𝑜⁄ , 𝑧 =

𝑥

𝐿𝑐 , 𝜉 =

𝑟

𝑅; 𝐿𝑐 = 𝑅𝑃𝑒 , where Pe(radial) =

𝑈𝑚𝑎𝑥𝑅

𝐷

(Note that this ′𝑃𝑒′ is based on mass transport)

(1 − 𝜉2)𝜕𝜃

𝜕𝑧=1

𝑃𝑒2𝜕2𝜃

𝜕𝑧2+𝜕2𝜃

𝜕𝜉2+1

𝜉

𝜕𝜃

𝜕𝜉

BC. 𝑧 = 0, 𝜃 = 1 ; 𝑧 = 𝐿𝐿𝑐⁄ ,

𝜕𝜃

𝜕𝑧= 0

𝜉 = 0, 𝜕𝜃

𝜕𝜉= 0 ; 𝜉 = 1 −

𝜕𝜃

𝜕𝜉= (

𝑘𝑅

𝐷𝐶𝐴𝑜) = 𝑀′ (constant)

⇒ It is clear that the non-dimensionalized equations and BCs of this (mass transport)

and previous (heat transport) examples are the same. Therefore, you need to solve only one of

the two. The dimensionless solutions will be the same. This situation should remind you of the

recommendation that one should non-dimensionalize the equation before solving it. Several

such analogous heat, mass, and momentum transport scenarios exist in chemical engineering

applications.

⇒In most cases, radial Pe(mass or heat) number in laminar flow regime is of the order

of 10 or higher. In such cases, the axial diffusion term can be neglected. In other words,

𝛼𝜕2𝑇

𝜕𝑋2<< 𝑉𝑋

𝜕𝑇

𝜕𝑋 𝑜𝑟 𝐷

𝜕2𝐶𝐴

𝜕𝑋2<< 𝑉𝑋

𝜕𝐶𝐴

𝜕𝑋 (See BSL book)

If you neglect the axial diffusion term, the 2D elliptic PDE is modified/simplified to 1D

parabolic PDE:

𝑉𝑋𝜕𝑇

𝜕𝑋=

𝛼

𝑟

𝜕

𝜕𝑟(𝑟

𝜕𝑇

𝜕𝑟) 𝑜𝑟 𝑉𝑋

𝜕𝐶𝐴

𝜕𝑋=

𝐷

𝑟

𝜕

𝜕𝑟(𝑟

𝜕𝐶𝐴

𝜕𝑟)

This simplified PDE can be solved using the Crank-Nicholson technique described in the

preceding lecture. In other words, one can numerically march in ‘X’ direction and solve in ‘r’

direction using Thomas Algorithm for the tridiagonal matrix built from the discretized ‘r’

terms. For now, let us revert to the original (full) non-dimensionalized elliptic PDE:

(1 − 𝜉2)𝜕𝜃

𝜕𝑧=1

𝑃𝑒2𝜕2𝜃

𝜕𝑧2+𝜕2𝜃

𝜕𝜉2+1

𝜉

𝜕𝜃

𝜕𝜉

At 𝜉 = 0, there is a discontinuity and you are solving an approximation:

(1 − 𝜉2)𝜕𝜃

𝜕𝑧=1

𝑃𝑒2𝜕2𝜃

𝜕𝑧2+2𝜕2𝜃

𝜕𝜉2

Page 137: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Discretize the main conservation equation:

(1 − 𝜉𝑗2)

𝜃𝑖+1,𝑗 −𝜃𝑖−1,𝑗

2Δ𝑧=

1

𝑃𝑒2

𝜃𝑖+1,𝑗−2𝜃𝑖,𝑗+𝜃𝑖−1,𝑗

Δ𝑧2 +𝜃𝑖,𝑗+1−2𝜃𝑖,𝑗+𝜃𝑖,𝑗−1

Δ𝜉2 +

1

𝜉𝑗

𝜃𝑖,𝑗+1−𝜃𝑖,𝑗−1

2Δ𝜉

or

((1−𝜉𝑗

2)

2Δ𝑧+

1

𝑃𝑒2Δ𝑧2

)𝜃𝑖−1,𝑗 −2𝜃𝑖,𝑗

𝑃𝑒2Δ𝑧2

− ((1−𝜉𝑗

2)

2Δ𝑧−

1

𝑃𝑒2Δ𝑧2

)𝜃𝑖+1,𝑗 = (1

2Δ𝜉𝜉𝑗−

1

Δ𝜉2) 𝜃𝑖,𝑗−1 +

2𝜃𝑖,𝑗

Δ𝜉2− (

1

2Δ𝜉𝜉𝑗+

1

Δ𝜉2) 𝜃𝑖,𝑗+1

- (1)

Discretize the approximated conservation equation at the line of symmetry:

((1−𝜉𝑗

2)

2Δ𝑧+

1

𝑃𝑒2Δ𝑧2

)𝜃𝑖−1,0 −2𝜃𝑖,0

𝑃𝑒2Δ𝑧2

− ((1−𝜉𝑗

2)

2Δ𝑧−

1

𝑃𝑒2Δ𝑧2

)𝜃𝑖+1,0 = −2𝜃𝑖,−1

Δ𝜉2+4𝜃𝑖,0

Δ𝜉2−2𝜃𝑖,+1

Δ𝜉2

Note that RHS terms for all rows contain guess values for all 𝜃𝑖,𝑗to begin with

Discretize BCs:

𝑖 = 0, 𝑗 = 0,𝑀; 𝜃0,𝑗 = 1; 𝑖 = 𝑁, 𝑗 = 0,𝑀; 𝜃𝑁+1,𝑗 = 𝜃𝑁−1,𝑗

𝑗 = 0, 𝑖 = 1,𝑁; 𝜃𝑖,−1 = 𝜃𝑖,1 ; 𝑗 = 𝑀, 𝑖 = 0,𝑁; 𝜃𝑖,𝑀+1 = 𝜃𝑖,𝑀−1 − 2𝑀′Δ𝜉

𝑗 = 0

1st row of Tridiagonal matrix,

𝑖 = 1 −2𝜃1,0𝑃𝑒2Δ𝑧2

− (1 − 𝜉0

2

2Δ𝑧−

1

𝑃𝑒2Δ𝑧2)𝜃2,0 = −

4𝜃1,0Δ𝜉2

+4𝜃1,0Δ𝜉2

− (1 − 𝜉0

2

2Δ𝑧+

1

𝑃𝑒2Δ𝑧2)𝜃0,0

=1

0 Δ𝑧2 i − 1 i + 1 i N 𝑖 = 1,𝑁𝑗 = 1,𝑀

𝑖 = 1, 𝑁𝑗 = 0 (𝑛𝑜𝑡𝑒 𝜉0 = 0)

Δ𝑧 = 1𝑁⁄ , Δ𝜉 =

𝐿 𝐿𝑐⁄

𝑀

i − 1 i + 1 i N − 1 N 1 0

Page 138: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

middle rows,

𝑖 = 2,𝑁 − 1: ((1 − 𝜉0

2)

2Δ𝑧+

1

𝑃𝑒2Δ𝑧2)𝜃𝑖−1,0 −

2𝜃𝑖,0𝑃𝑒2Δ𝑧2

− ((1 − 𝜉0

2)

2Δ𝑧−

1

𝑃𝑒2Δ𝑧2)𝜃𝑖+1,0

= −4𝜃𝑖,1Δ𝜉2

+4𝜃𝑖,0Δ𝜉2

last row, 𝑖 = 𝑁: 2

𝑃𝑒2Δ𝑧2

𝜃𝑁−1,0 −2𝜃𝑁,0

𝑃𝑒2Δ𝑧2

= −4𝜃𝑁,1

Δ𝜉2+4𝜃𝑁,0

Δ𝜉2

You have a tridiagonal matrix A in (𝐴𝜃𝑖,0𝑘+1 = 𝑏𝑖,0

𝑘 ) to invert

𝑗 = 1,𝑀 − 1 (Visit the main conservation equation)

1st row,

𝑖 = 1: −2𝜃1,𝑗

𝑃𝑒2Δ𝑧2− (

1 − 𝜉𝑗2

2Δ𝑧−

1

𝑃𝑒2Δ𝑧2)𝜃2,𝑗 = −(

1 − 𝜉𝑗2

2Δ𝑧+

1

𝑃𝑒2Δ𝑧2)𝜃0,𝑗

(1

2Δ𝜉𝜉𝑗−

1

Δ𝜉2) 𝜃1,𝑗−1 +

2𝜃1,𝑗

Δ𝜉2− (

1

2Δ𝜉𝜉𝑗+

1

Δ𝜉2)𝜃1,𝑗+1

middle rows:

𝑖 = 2, 𝑁 − 1 : These are middle grids unaffected by BCs.

last row

𝑖 = 𝑁 2

𝑃𝑒2Δ𝑧2𝜃𝑁−1,𝑗 −

2𝜃𝑁,𝑗

𝑃𝑒2Δ𝑧2= (

1

2Δ𝜉𝜉𝑗−

1

Δ𝜉2)𝜃𝑁,𝑗−1 +

2𝜃𝑁,𝑗

Δ𝜉2− (

1

2Δ𝜉𝜉𝑗+

1

Δ𝜉2)𝜃𝑁,𝑗+1

Again, 𝐴𝜃𝑖,𝑗𝐾+1 = 𝑏𝑖,𝑗

𝐾 ; 𝑖 = 1, 𝑁

𝑗 = 1,𝑀 − 1

𝑗 = 𝑀

1st row,

𝑖 = 1 −2𝜃1,𝑀𝑃𝑒2Δ𝑧2

− ((1 − 𝜉𝑀

2)

2Δ𝑧−

1

𝑃𝑒2Δ𝑧2)𝜃2,𝑀 = −(

(1 − 𝜉𝑀2)

2Δ𝑧+

1

𝑃𝑒2Δ𝑧2)𝜃0,𝑀

−2

Δ𝜉2𝜃1,𝑀−1 +

2𝜃1,𝑀

Δ𝜉2+ 2𝑀′Δ𝜉 (

1

2Δ𝜉𝜉𝑀+

1

Δ𝜉2)

middle rows, LHS (same as that of eq1), unaffected by BC =

i = 2, N-1 −2

Δ𝜉2𝜃𝑖,𝑀−1 +

2𝜃𝑖,𝑀

Δ𝜉2+ 2𝑀′Δ𝜉 (

1

2Δ𝜉𝜉𝑀+

1

Δ𝜉2)

1

1

Page 139: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

last row,

𝑖 = 𝑁 2𝜃𝑁−1,𝑀𝑃𝑒2Δ𝑧2

−2𝜃𝑁,𝑀𝑃𝑒2Δ𝑧2

= −2

Δ𝜉2𝜃𝑁,𝑀−1 +

2𝜃𝑁,𝑀Δ𝜉2

+ 2𝑀′Δ𝜉 (1

2Δ𝜉𝜉𝑀+

1

Δ𝜉2)

Again, 𝐴𝜃𝑖,𝑀𝑘+1 = 𝑏𝑖,𝑀

𝑘

You have called the Thomas Algorithm (M+1) times to invert the tridiagonal A matrix to solve

𝜃𝑖,𝑗 , 𝑖 = 1, 𝑁

𝑗 = 0,𝑀} using the guess values on the RHS of the tridiagonal matrix .

You must have noted that we did not prepare the tridiagonal matrix, and instead directly

substituted the BCs in the discretized equations! As an exercise, prepare the tridiagonal matrix

by defining individuals elements of rows for every ‘j’ viz a(i, j), b(i, j)⋯⋯, substitute BCs and

see if you get the same equations for different ′𝑗𝑠′.

Now, this is the time to compare the solved 𝜃𝑖,𝑗 values with the guess values you made at the

beginning of the iterations before starting the iterations.

⇒ From the programming point of view, you should be able to choose reasonable values of all

variables including, D, Vmax, M and Pe,mass transport, or H and Pe,heat transport .

⇒ As earlier noted, solving elliptic PDE is computational extensive, requiring guess values,

iterations and convergence. Very often, one artificially inserts a transient term

(𝜕𝐶𝐴

𝜕𝑡 or 𝜌𝐶𝑝

𝜕𝑇

𝜕𝑡 or 𝜌

𝜕��

𝜕𝑡) and seeks SS solutions, which is the focus of the last two lectures.

Page 140: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #26-27

𝑇𝑖𝑚𝑒 − 𝑑𝑒𝑝𝑒𝑛𝑑𝑒𝑛𝑡 2𝐷 𝑝𝑎𝑟𝑎𝑏𝑜𝑙𝑖𝑐 𝑃𝐷𝐸: 𝐴𝐷𝐼 𝑀𝑒𝑡ℎ𝑜𝑑

We are solving, for examples:

𝜕𝐶𝐴

𝜕𝑡+ 𝑉. ∇𝐶𝐴 = 𝐷∇2𝐶𝐴 + (−𝑟𝐴) ; 𝐶𝐴(𝑡, 𝑟, 𝑥)

or

𝜌𝐶𝑝 (𝜕𝑇

𝜕𝑡+ 𝑉. ∇𝑇) = 𝑘∇2𝑇 + (−𝑟𝐴)(Δ𝐻) ; 𝑇(𝑡, 𝑟, 𝑥)

Note: SS solution must be the same as that of the converged solution of the analogous

2D elliptic PDE (𝜕𝐶𝐴

𝜕𝑡=

𝜕𝑇

𝜕𝑡= 0) discussed in the previous lectures.

Let us take a general case of the time-dependent 2D PDE:

𝜕𝜙

𝜕𝑡= 𝜙𝑋𝑋 + 𝜙𝑋 + 𝜙𝑌𝑌 + 𝜙𝑌 ; 𝜙(𝑡, 𝑥, 𝑦)

with necessary IC and BCs.

Apply Crank-Nicholson method/scheme to discretize 𝜙𝑋𝑋 , 𝜙𝑌𝑌, 𝜙𝑋 , 𝑎𝑛𝑑 𝜙𝑌 terms, in

the similar fashion solved the time-dependent 1D PDE on 𝜙(𝑡, 𝑥):

(𝜙𝑡+1 − 𝜙𝑡

Δ𝑡)

𝑖,𝑗

=1

2[(

𝜙𝑖+1,𝑗 − 2𝜙𝑖,𝑗 + 𝜙𝑖−1,𝑗

Δ𝑋2 )

𝑡+1

+ (𝜙𝑖+1,𝑗 − 𝜙𝑖−1,𝑗

2ΔX )

𝑡+1

+ (𝜙𝑖,𝑗+1 − 2𝜙𝑖,𝑗 + 𝜙𝑖,𝑗−1

Δ𝑌2 )

𝑡

+ (𝜙𝑖,𝑗+1 − 𝜙𝑖,𝑗−1

2ΔY )

𝑡

]

- This way the X-derivatives have been discretized implicitly on time, whereas the Y-

derivatives have been discretized explicitly.

- Alternatively, one can discretize Y-derivatives implicitly on time, whereas X-

derivatives can be discretized explicitly.

- Re-arranging the terms as 𝐴∅𝑥𝑡+1 = ∅𝑦

𝑡 𝑜𝑟 𝐴∅𝑦𝑡+1 = ∅𝑥

𝑡 from either scheme, it

is clear that ‘A’ will be a tridiagonal matrix, and one can proceed on time-step by

solving 𝜙 on X-Y plane:

Page 141: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

(1

2Δ𝑋2−

1

4Δ𝑋) 𝜙𝑖−1,𝑗

𝑡+1 − (1

Δ𝑡+

1

Δ𝑋2) 𝜙𝑖,𝑗

𝑡+1 + (1

2Δ𝑋2+

1

4Δ𝑋) 𝜙𝑖+1,𝑗

𝑡+1

= (1

4Δ𝑌−

1

2Δ𝑌2) 𝜙𝑖,𝑗−1

𝑡 − (1

Δ𝑡−

1

Δ𝑌2) 𝜙𝑖,𝑗

𝑡 − (1

4Δ𝑌+

1

2Δ𝑌2) 𝜙𝑖,𝑗+1

𝑡

- This way you are ‘marching’ in ‘𝑗’ direction and ‘sweeping’ in ‘i’ direction.

By the second scheme, if you ‘march’ in ‘i’ direction and ‘sweep’ in ‘𝑗’-direction, you will

get the following equation:

(1

4Δ𝑌−

1

2Δ𝑌2) 𝜙𝑖,𝑗−1𝑡+1 + (

1

Δ𝑡+

1

Δ𝑌2) 𝜙𝑖,𝑗𝑡+1 − (

1

4Δ𝑌+

1

2Δ𝑌2) 𝜙𝑖,𝑗+1𝑡+1

= (1

2Δ𝑋2−

1

4Δ𝑋) 𝜙𝑖−1,𝑗

𝑡 + (1

Δ𝑡−

1

Δ𝑋2) 𝜙𝑖,𝑗

𝑡 + (1

2Δ𝑋2+

1

4Δ𝑋) 𝜙𝑖+1,𝑗

𝑡

Both schemes will work and the Crank-Nicholson method will produce 2nd order

accuracy.

- Alternate Direct Implicit (ADI) method is an improved method producing 4th

order accuracy without any extra computational cost (for more, refer the book by

Ferziger):

First discretize 𝜙𝑋 and 𝜙𝑋𝑋 terms implicitly and 𝜙𝑌 and 𝜙𝑌𝑌 terms explicitly to solve 𝜙

over half step (Δ𝑡 2⁄ ) and then discretize 𝜙𝑌 and 𝜙𝑌𝑌 terms implicitly and 𝜙𝑋 and 𝜙𝑋𝑋 terms

explicitly over the next half step:

Step1:

(𝜙𝑡+1

2⁄ − 𝜙𝑡

Δ 𝑡 2⁄)

𝑖,𝑗

=1

2[(𝜙𝑋𝑋 + 𝜙𝑋)𝑡+1

2⁄ + (𝜙𝑌𝑌 + 𝜙𝑌)𝑡]

Step2:

(𝜙𝑡+1 − 𝜙𝑡+1

2⁄

Δ 𝑡 2⁄)

𝑖,𝑗

=1

2[(𝜙𝑋𝑋 + 𝜙𝑋)𝑡+1

2⁄ + (𝜙𝑌𝑌 + 𝜙𝑌)𝑡+1]

or 𝐴𝜙𝑥

𝑡+12⁄

= 𝜙𝑦𝑡

and 𝐵𝜙𝑦𝑡+1 = 𝜙𝑥

𝑡+12⁄

}

The procedure can also be understood by the following illustration:

𝑖𝑚𝑝𝑙𝑖𝑐𝑖𝑡 𝑒𝑥𝑝𝑙𝑖𝑐𝑖𝑡

𝑒𝑥𝑝𝑙𝑖𝑐𝑖𝑡 𝑖𝑚𝑝𝑙𝑖𝑐𝑖𝑡

Page 142: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

Ex: Consider 2D diffusion in a rectangular shaped solid porous carbon block. The block is

initially soaked with moisture, say at concentration 𝐶𝑜 (𝑚𝑜𝑙𝑒𝑠 𝑚3)⁄ . At 𝑡 = 0+ all four sides of

the block are exposed to dry air (moisture concentration = 𝐶𝑖 ≪ 𝐶𝑜). We are interested in

calculating the unsteady-state concentration profiles of moisture within the block, ie. 𝐶(𝑡, 𝑥, 𝑦) =

?. Pore diffusion coefficient for moisture in solid is 𝐷𝑝𝑜𝑟𝑒.

Ans:

A species balance over ′Δ𝑋Δ𝑦. 1′ 𝐶𝑉 will yield the following conservation equation:

𝜕𝐶𝐴

𝜕𝑡+ 𝑉. ∇𝐶𝐴 = 𝐷𝑝𝑜𝑟𝑒∇2𝐶𝐴 + (−𝑟𝐴)

𝜕𝐶𝐴

𝜕𝑡= 𝐷𝑝𝑜𝑟𝑒 (

𝜕2𝐶𝐴

𝜕𝑋2+

𝜕2𝐶𝐴

𝜕𝑦2)

𝑡 = 0 𝐶 = 𝐶𝑜 𝑓𝑜𝑟 𝐿 ≥ 𝑥 ≥ 0 ; 𝑤 ≥ 𝑦 ≥ 0

0+ 𝐶 = 𝐶𝑖

∗ @ 𝑥 = 0 & 𝐿 for 𝑤 > 𝑦 > 0

and @ 𝑦 = 0 & 𝑤 for 𝐿 > 𝑥 > 0}

(𝐶𝑖∗ is the solid phase moisture concentration at the surface of the block in equilibrium with

𝐶𝑖 in atmoshphere).

𝑖, 𝑗 + 1

𝑖 + 1, 𝑗 𝑖 − 1, 𝑗

𝑖, 𝑗 − 1

𝑖, 𝑗

𝑡

𝑖 − 1, 𝑗 𝑖 + 1, 𝑗

𝑖, 𝑗 + 1

𝑖, 𝑗 − 1

𝑖, 𝑗

𝑡 + 12⁄

𝑡 + 12⁄

𝑡 + 1

𝑖 − 1, 𝑗

𝑖, 𝑗 + 1

𝑖, 𝑗 − 1

𝑖, 𝑗 𝑖 + 1, 𝑗

𝑡 + 12⁄

𝑠𝑤𝑒𝑒𝑝 ′𝑖′

𝑚𝑎𝑟𝑐ℎ ′𝑖′

𝑠𝑤𝑒𝑒𝑝 ′𝑗′

𝑚𝑎𝑟𝑐ℎ ′𝑗′

𝐶𝑖 𝑚𝑜𝑙𝑒𝑠 𝑚3⁄

𝐿

𝑦

𝑤

Δ𝑋

Δ𝑦

X

C(t, x, y) =?

Page 143: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

Step1: discretize ‘𝑖’ implicitly and ‘𝑗’ explicitly over (𝑡 & 𝑡 + 12⁄ )

𝐶𝑖,𝑗

𝑡+12⁄

− 𝐶𝑖,𝑗𝑡

Δ𝑡2⁄

=𝐷𝑝𝑜𝑟𝑒

2[(

𝐶𝑖+1,𝑗 − 2𝐶𝑖,𝑗 + 𝐶𝑖−1,𝑗

Δ𝑋2 )

𝑡+12⁄

+ (𝐶𝑖,𝑗+1 − 2𝐶𝑖,𝑗 + 𝐶𝑖,𝑗−1

Δ𝑦2 )

𝑡

]

(Δ𝑋 = L𝑁⁄ , Δ𝑦 = w

𝑀⁄ )

Arrange:

𝐷𝑝𝑜𝑟𝑒

2Δ𝑋2 𝐶𝑖−1,𝑗

𝑡+12⁄

− (𝐷𝑝𝑜𝑟𝑒

Δ𝑋2 +2

Δ𝑡 ) 𝐶

𝑖,𝑗

𝑡+12⁄

+𝐷𝑝𝑜𝑟𝑒

2Δ𝑋2 𝐶𝑖+1,𝑗

𝑡+12⁄

= −𝐷𝑝𝑜𝑟𝑒

2Δ𝑦2 𝐶𝑖,𝑗−1𝑡 + (

𝐷𝑝𝑜𝑟𝑒

Δ𝑦2 −2

Δ𝑡 ) 𝐶𝑖,𝑗

𝑡 −

𝐷𝑝𝑜𝑟𝑒

2Δ𝑦2 𝐶𝑖,𝑗+1𝑡

𝑖 = 1, 𝑁 − 1𝑗 = 1, 𝑀 − 1

Step-2:

Discretize BCs: 𝐶𝑜,𝑗 = 𝐶𝑁,𝑗 = 𝐶∗; 𝑗 = 0, 𝑀

𝐶𝑖,0 = 𝐶𝑖,𝑀 = 𝐶∗; 𝑖 = 0, 𝑁

Prepare the tridiagonal matrix:

𝑎(𝑖, 𝑗) = 𝐷𝑝𝑜𝑟𝑒

2Δ𝑋2 ; 𝑏(𝑖, 𝑗) = − (𝐷𝑝𝑜𝑟𝑒

Δ𝑋2 +2

Δ𝑡 ) ; 𝑐(𝑖, 𝑗) =

𝐷𝑝𝑜𝑟𝑒

2Δ𝑋2 ; 𝑑(𝑖, 𝑗) = −𝐷𝑝𝑜𝑟𝑒

2Δ𝑦2 𝐶𝑖,𝑗−1𝑡 +

(𝐷𝑝𝑜𝑟𝑒

Δ𝑦2−

2

Δ𝑡 ) 𝐶𝑖,𝑗

𝑡 −𝐷𝑝𝑜𝑟𝑒

2Δ𝑦2 𝐶𝑖,𝑗+1

𝑡

𝑖 = 1, 𝑁 − 1𝑗 = 1, 𝑀 − 1

}

M

M − 1

(i, j + 1)

0 𝑖 − 1, j 1 (𝑖, j) 𝑖 + 1, j 𝑁 − 1 𝑁

(𝑖, j − 1)

− 1 1

0

Page 144: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

Substitute BCs and the following coefficients will be modified:

𝑑(1, 𝑗) = 𝑑(1, 𝑗) − 𝑎(1, 𝑗)𝐶∗

𝑑(𝑁 − 1, 𝑗) = 𝑑(𝑁 − 1, 𝑗) − 𝑐(𝑁 − 1, 𝑗)𝐶∗} 𝑗 = 1, 𝑀 − 1

Convince yourself that no other coefficients will change. This was actually an easy

problem, when all four boundary conditions were simple, i.e., functional values were prescribed.

Problems are complicated when you have ‘flux’/gradient or mixed boundary conditions; for

example,

−𝐷𝜕𝐶

𝜕𝑋= 𝑘𝑚(𝐶 − 𝐶𝑎𝑡𝑚)

𝑜𝑟 = Flux (known)

and/or −𝐷𝜕𝐶

𝜕𝑦= 𝑘𝐶 𝑜𝑟 𝑘𝑚(𝐶 − 𝐶𝑎𝑡𝑚)

In such cases the other coefficients may also change. Revert to the previous step.

Tridiagonal (𝑁 − 1, 𝑎, 𝑏, 𝑐, 𝑑, 𝑦(𝑖, 𝑗)) 𝑖 = 1, 𝑁 − 1

You will be calling the subroutine ′𝑀 − 1′ times as you ‘march’ along ′𝑗′ direction. Now, you

have the values for 𝐶𝑖,𝑗

𝑡+12⁄

, 𝑖 = 1, 𝑁 − 1𝑗 = 1, 𝑀 − 1

Step3:

Now march along ′𝑖′ direction and ‘sweep’ along ′𝑗′ direction to solve for

𝐶𝑖,𝑗𝑡+1 from 𝐶

𝑖,𝑗

𝑡+12⁄.

𝐶𝑖,𝑗𝑡+1 −𝐶

𝑖,𝑗

𝑡+12⁄

Δ𝑡2⁄

=𝐷𝑝𝑜𝑟𝑒

2[(

𝐶𝑖−1,𝑗−2𝐶𝑖,𝑗+𝐶𝑖+1,𝑗

Δ𝑋2 )

𝑡+12⁄

+ (𝐶𝑖,𝑗−1−2𝐶𝑖,𝑗+𝐶𝑖,𝑗+1

Δ𝑦2 )

𝑡+1

]

Arrange:

𝐷𝑝𝑜𝑟𝑒

2Δ𝑦2 𝐶𝑖,𝑗−1

𝑡+1 − (𝐷𝑝𝑜𝑟𝑒

Δ𝑦2+

2

Δ𝑡 ) 𝐶𝑖,𝑗

𝑡+1 +𝐷𝑝𝑜𝑟𝑒

2Δ𝑦2 𝐶𝑖,𝑗+1

𝑡+1 = −𝐷𝑝𝑜𝑟𝑒

2Δ𝑋2 𝐶

𝑖−1,𝑗

𝑡+12⁄

+ (𝐷𝑝𝑜𝑟𝑒

Δ𝑋2−

2

Δ𝑡 ) 𝐶

𝑖,𝑗

𝑡+12⁄

−𝐷𝑝𝑜𝑟𝑒

2Δ𝑋2 𝐶𝑖+1,𝑗

𝑡+12⁄ ;

𝑗 = 1, 𝑀 − 1𝑖 = 1, 𝑁 − 1

}

𝑒𝑥𝑝𝑙𝑖𝑐𝑖𝑡 𝑖𝑚𝑝𝑙𝑖𝑐𝑖𝑡

Page 145: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

Step-4:

Discretize the BCs: Same as before.

Prepare the tridiagonal matrix:

𝑎(𝑖, 𝑗) = 𝐷𝑝𝑜𝑟𝑒

2Δ𝑦2 ; 𝑏(𝑖, 𝑗) = − (𝐷𝑝𝑜𝑟𝑒

Δ𝑦2 +2

Δ𝑡 ) ; 𝑐(𝑖, 𝑗) =

𝐷𝑝𝑜𝑟𝑒

2Δ𝑦2 ; 𝑑(𝑖, 𝑗) = −𝐷𝑝𝑜𝑟𝑒

2Δ𝑋2 𝐶𝑖−1,𝑗

𝑡+12⁄

+

(𝐷𝑝𝑜𝑟𝑒

Δ𝑋2 −2

Δ𝑡 ) 𝐶

𝑖,𝑗

𝑡+12⁄

−𝐷𝑝𝑜𝑟𝑒

2Δ𝑋2 𝐶𝑖+1,𝑗

𝑡+12⁄ ;

𝑖 = 1, 𝑁 − 1𝑗 = 1, 𝑀 − 1

}

Substitute the discretized BCs, and only the following coefficients will be modified:

𝑑(𝑖, 1) = 𝑑(𝑖, 1) − 𝑎(𝑖, 1)𝐶∗

𝑑(𝑖, 𝑀 − 1) = 𝑑(𝑖, 𝑀 − 1) − 𝑐(𝑖, 𝑀 − 1)𝐶∗} 𝑖 = 1, 𝑁 − 1

Tridiagonal (𝑀 − 1, 𝑎, 𝑏, 𝑐, 𝑑, 𝑦(𝑖, 𝑗)) 𝑗 = 1, 𝑀 − 1

You will be calling the subroutine ′𝑁 − 1′ times as you ‘march’ along ′𝑖′ direction. Thus, you

have solved for 𝐶𝑖,𝑗𝑡+1,

𝑖 = 1, 𝑁 − 1𝑗 = 1, 𝑀 − 1

Recap (solving 2nd order ODE and PDEs at a glance)

BVP: 𝐴𝜙𝑖 = 𝑏 (Direct Method)

1D parabolic: 𝐴𝜙𝑖𝑡+1 = 𝜙𝑖

𝑡 (Crank-Nicholson Method)

2D Elliptic: 𝐴𝜙𝑖,𝑗 = 𝜙𝑗,𝑖𝑔𝑢𝑒𝑠𝑠

or 𝐴𝜙𝑗,𝑖 = 𝜙𝑖,𝑗𝑔𝑢𝑒𝑠𝑠

(Method of Lines)

2D parabolic: (ADI Method)

𝐴𝜙𝑖

𝑡+12⁄

= 𝜙𝑗𝑡

and 𝐵𝜙𝑗𝑡+1 = 𝜙

𝑖

𝑡+12⁄

} or 𝐴𝜙

𝑗

𝑡+12⁄

= 𝜙𝑖𝑡

and 𝐵𝜙𝑖𝑡+1 = 𝜙

𝑗

𝑡+12⁄

}

where, A and B are the Tridiagonal matrices.

Page 146: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

1

Lecture #28

Example: Consider the SS flow of a liquid through a long tube. Reynolds number is 180. At

time 𝑡 = 0, a tracer is injected into the liquid at inlet to the tube. Diffusion coefficient of tracer

in the liquid is 𝐷 𝑐𝑚2 𝑠⁄ . Determine the time profiles of the tracer concentrations (𝑟, 𝑥) in the

tube, ie. 𝐶(𝑡, 𝑟, 𝑥) =?

Soln.

A species balance over ′2𝜋𝑟Δ𝑟Δ𝑥′ 𝐶𝑉 yields the following eqn

𝜕𝐶

𝜕𝑡+ 𝑉. ∇𝐶 = 𝐷∇2𝐶 + (−𝑟𝐴)

or

𝜕𝐶

𝜕𝑡+ 𝑉(𝑟)

𝜕𝐶

𝜕𝑋= 𝐷 (

𝜕2𝐶

𝜕𝑋2+1

𝑟

𝜕

𝜕𝑟(𝑟

𝜕𝐶

𝜕𝑟))

𝐿 > 𝑋 > 0𝑅 > 𝑟 > 0

or 𝜕𝐶

𝜕𝑡= (−𝑉(𝑟)

𝜕𝐶

𝜕𝑋+ 𝐷

𝜕2𝐶

𝜕𝑋2) + 𝐷 (

1

𝑟

𝜕𝐶

𝜕𝑟+𝜕2𝐶

𝜕𝑟2)

𝑡 = 0 𝐶 = 0 𝐿 ≥ 𝑥 ≥ 0 and 𝑅 ≥ 𝑟 ≥ 0

0+ 𝐶 = 𝐶𝑜 @ 𝑥 = 0

𝜕𝐶

𝜕𝑋= 0 @ 𝑋 = 𝐿

} for all 𝑅 > 𝑟 > 0

(long tube approximation)

𝜕𝐶

𝜕𝑟= 0 @𝑟 = 0 (𝑠𝑦𝑚𝑚𝑒𝑡𝑟𝑖𝑐)

= 0 @𝑟 = 𝑅 (𝑛𝑜𝑛 − 𝑟𝑒𝑎𝑐𝑡𝑖𝑣𝑒 𝑤𝑎𝑙𝑙𝑠)} 𝑓𝑜𝑟 𝑎𝑙𝑙 𝐿 > 𝑋 > 0

𝐶𝑜 𝑅

𝑂

𝐿

Δ𝑟 𝑟

Δ𝑋

𝑅

𝑟

Δ𝑟 X

C(t,r,x)=?

V(r) = Umax (1 −𝑟2

𝑅2)

Page 147: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

2

Note: You will encounter discontinuity at 𝑟 = 0 in the radial diffusion terms while discretizing.

Considering ∇𝐶 = 0, you will be solving the approximated equation instead.

𝜕𝐶

𝜕𝑡= (−𝑉(𝑟)

𝜕𝐶

𝜕𝑋+𝐷

𝜕2𝐶

𝜕𝑋2) + 2𝐷

𝜕2𝐶

𝜕𝑟2 𝑎𝑡 𝑟 = 0 𝑓𝑜𝑟 𝑎𝑙𝑙 𝐿 > 𝑋 > 0

Discretize the approximated equation:

𝐶𝑖,𝑗

𝑡+1 2⁄ − 𝐶𝑖,𝑗𝑡

Δ𝑡2⁄

=1

2[((−𝑉𝑗)

𝐶𝑖+1,𝑗 − 𝐶𝑖−1,𝑗

2Δ𝑋 + 𝐷

𝐶𝑖+1,𝑗 − 2𝐶𝑖,𝑗 + 𝐶𝑖−1,𝑗

Δ𝑋2 )

𝑡+1 2⁄

+ 2𝐷 (𝐶𝑖,𝑗+1 − 2𝐶𝑖,𝑗 + 𝐶𝑖,𝑗−1

Δ𝑟2 )𝑡

] ; 𝑗 = 0𝑖 = 1,𝑁

}

Arrange;

(𝑉𝑗

4Δ𝑋+

𝐷

2Δ𝑋2) 𝐶

𝑖−1,𝑗

𝑡+1 2⁄ − (2

Δ𝑡+

𝐷

Δ𝑋2) 𝐶

𝑖,𝑗

𝑡+1 2⁄ − (𝑉𝑗

4Δ𝑋−

𝐷

2Δ𝑋2) 𝐶

𝑖+1,𝑗

𝑡+1 2⁄

= −(𝐷

Δ𝑟2)𝐶𝑖,𝑗−1

𝑡 − (2

Δ𝑡−2𝐷

Δ𝑟2)𝐶𝑖,𝑗

𝑡 − (𝐷

Δ𝑟2)𝐶𝑖,𝑗+1

𝑡 ; 𝑗 = 0𝑖 = 1,𝑁

}

(𝑖, M)

(𝑖, M − 1)

(i, j + 1)

𝑖 = 0 𝑖 − 1, j 1 (𝑖, j) 𝑖 + 1, j 𝑁 − 1 𝑁

(𝑖, j − 1)

− 1

implicit

0 j =

explicit

1

Page 148: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

3

Similarly, discretize the main equation:

𝐶𝑖,𝑗

𝑡+1 2⁄ − 𝐶𝑖,𝑗𝑡

Δ𝑡2⁄

=1

2[((−𝑉𝑗)

𝐶𝑖+1,𝑗 − 𝐶𝑖−1,𝑗

2Δ𝑋 + 𝐷

𝐶𝑖+1,𝑗 − 2𝐶𝑖,𝑗 + 𝐶𝑖−1,𝑗

Δ𝑋2 )

𝑡+1 2⁄

+ 𝐷 (1

𝑟𝑗

𝐶𝑖,𝑗+1 − 𝐶𝑖,𝑗−1

2Δ𝑟 +𝐶𝑖,𝑗+1 − 2𝐶𝑖,𝑗 + 𝐶𝑖,𝑗−1

Δ𝑟2 )

𝑡

] 𝑗 = 1,𝑀𝑖 = 1,𝑁

}

Arrange,

(𝑉𝑗

4Δ𝑋+

𝐷

2Δ𝑋2) 𝐶

𝑖−1,𝑗

𝑡+1 2⁄ − (2

Δ𝑡+

𝐷

Δ𝑋2) 𝐶

𝑖,𝑗

𝑡+1 2⁄ − (𝑉𝑗

4Δ𝑋−

𝐷

2Δ𝑋2) 𝐶

𝑖+1,𝑗

𝑡+1 2⁄

= (𝐷

4𝑟𝑗Δ𝑟−

𝐷

2Δ𝑟2)𝐶𝑖,𝑗−1

𝑡 − (2

Δ𝑡−

𝐷

Δ𝑟2)𝐶𝑖,𝑗

𝑡

− (𝐷

4𝑟𝑗Δ𝑟+

𝐷

2Δ𝑟2)𝐶𝑖,𝑗+1

𝑡 ; 𝑗 = 1,𝑀𝑖 = 1,𝑁

}

Note: 𝑉𝑗 = 𝑈𝑚𝑎𝑥 (1 −𝑟𝑗2

𝑅2) ; 𝑟𝑗 = 𝑗Δ𝑟

Discretize BCs & IC

𝑡 = 0, 𝐶(𝑖, 𝑗) = 0 𝑜r a small number 𝐶𝑖𝑛𝑡 ≪ 𝐶𝑜 (𝑁 ≥ 𝑖 ≥ 0 𝑎𝑛𝑑 𝑀 ≥ 𝑗 ≥ 0)

0+ 𝐶(0, 𝑗) = 𝐶𝑜 𝐶(𝑁+1,𝑗)−𝐶(𝑁−1,𝑗)

Δ𝑋= 0

𝑜𝑟 𝐶(𝑁 + 1, 𝑗) = 𝐶(𝑁 − 1, 𝑗)

} 𝑀 > 𝑗 > 0

𝐶(𝑖, −1) = 𝐶(𝑖, +1)

𝐶(𝑖, 𝑀 + 1) = 𝐶(𝑖,𝑀 − 1)}𝑁 > 𝑖 > 0

Prepare tridiagonal matrix

𝑗 = 0: 𝑎(𝑖, 0) = (𝑉0

4Δ𝑋+

𝐷

2Δ𝑋2) ; 𝑏(𝑖, 0) = −(

2

Δ𝑡+

𝐷

Δ𝑋2) ; 𝑐(𝑖, 0) = −(

𝑉0

4Δ𝑋−

𝐷

2Δ𝑋2) ; 𝑑(𝑖, 0) =

− (𝐷

Δ𝑟2)𝐶𝑖,−1

𝑡 − (2

Δ𝑡−

2𝐷

Δ𝑟2)𝐶𝑖,0

𝑡 − (𝐷

Δ𝑟2)𝐶𝑖,+1

𝑡 ; 𝑖 = 1,𝑁

Substitute BCs,

𝑑(1,0) = −(2𝐷

Δ𝑟2)𝐶1,1

𝑡 − (2

Δ𝑡−2𝐷

Δ𝑟2) 𝐶1,0

𝑡 − 𝑎(1,0)𝐶𝑜

𝑎(𝑁, 0) = 𝑎(𝑁, 0) + 𝑐(𝑁, 0)

implicit

explicit

Page 149: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

4

𝑑(𝑁, 0) = −(2𝐷

Δ𝑟2)𝐶𝑁,1

𝑡 − (2

Δ𝑡−

2𝐷

Δ𝑟2)𝐶𝑁,0

𝑡

Tridiagonal (𝑁, 𝑎, 𝑏, 𝑐, 𝑑, 𝑦𝑡+12⁄ (𝑖, 0)) ; 𝑖 = 1, 𝑁

Preparation of tridiagonal matrix… continue….

𝑎(𝑖, 𝑗) = (𝑉𝑗

4Δ𝑋+

𝐷

2Δ𝑋2) ; 𝑏(𝑖, 𝑗) = − (

2

Δ𝑡+

𝐷

Δ𝑋2) ; 𝑐(𝑖, 𝑗) = −(

𝑉𝑗

4Δ𝑋−

𝐷

2Δ𝑋2) ; 𝑑(𝑖, 𝑗)

= (𝐷

4𝑟𝑗Δ𝑟−

𝐷

2Δ𝑟2)𝐶𝑖,𝑗−1

𝑡 − (2

Δ𝑡−

𝐷

Δ𝑟2)𝐶𝑖,𝑗

𝑡

− (𝐷

4𝑟𝑗Δ𝑟+

𝐷

2Δ𝑟2)𝐶𝑖,𝑗+1

𝑡 𝑗 = 1,𝑀𝑖 = 1,𝑁

}

Sbustitute BC (𝑗 = 1,𝑀 − 1)

𝑑(1, 𝑗) = 𝑑(1, 𝑗) − 𝑎(1, 𝑗)𝐶𝑜

𝑎(𝑁, 𝑗) = 𝑎(𝑁, 𝑗) + 𝑐(𝑁, 𝑗)

Tridiagonal (𝑁, 𝑎, 𝑏, 𝑐, 𝑑, 𝑦𝑡+12⁄ (𝑖, 𝑗)) ;

𝑖 = 1, 𝑁𝑗 = 1,𝑀 − 1

}

You have called the tridiagonal subroutine ′𝑀 − 1′ times for the interior nodes.

Substitute BC @ 𝑗 = 𝑀

𝑑(1,𝑀) = −(𝐷

Δ𝑟2)𝐶𝑖,𝑀−1

𝑡 − (2

Δ𝑡−

𝐷

Δ𝑟2)𝐶𝑖,𝑀

𝑡 − a(1, N). Co

𝑑(𝑖,𝑀) = −(2

Δ𝑟2)𝐶𝑖,𝑀−1

𝑡 − (2

Δ𝑡−

𝐷

Δ𝑟2)𝐶𝑖,𝑀

𝑡

𝑎(𝑁,𝑀) = 𝑎(𝑁,𝑀) + 𝑐(𝑁,𝑀)

𝑑(𝑁,𝑀) = −(𝐷

Δ𝑟2)𝐶𝑁,𝑀−1

𝑡 − (2

Δ𝑡−

𝐷

Δ𝑟2)𝐶𝑁,𝑀

𝑡

Tridiagonal (𝑁, 𝑎, 𝑏, 𝑐, 𝑑, 𝑦𝑡+12⁄ (𝑖,𝑀)) ; 𝑖 = 1,𝑁

(Therefore, you have called the Thomas Algorithm (𝑀 + 1) times while sweeping 𝑗 =

0,𝑀 rows)

Page 150: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

5

For the last time in this course, let us write down complete eqn

𝐴𝑦𝑡+12⁄ = 𝑑𝑡 𝑓𝑜𝑟 𝑗 = 0, 𝑖 = 1,𝑁

[ − (

2

Δ𝑡+

𝐷

Δ𝑥2) − (

𝑉04Δ𝑋

+𝐷

2Δ𝑋2) ⋯ ⋯ ⋯

⋯ (𝑉04Δ𝑋

+𝐷

2Δ𝑋2) −(

2

Δ𝑡+

𝐷

Δ𝑥2) −(

𝑉04Δ𝑋

−𝐷

2Δ𝑋2) ⋯

⋮ ⋮ ⋮ ⋮ ⋮

⋯ ⋯ ⋯ (𝐷

Δ𝑥2) −(

2

Δ𝑡+

𝐷

Δ𝑥2)]

{

𝑌𝑖

}

𝑡+1 2⁄

=

{

𝑑(1,0)⋮

𝑑(𝑖, 0)𝑖 = 2, 𝑁 − 1

⋮⋮

𝑑(𝑁, 0) }

𝑡

Similarly, you can write a set of equations for 𝑗 = 1,𝑀 − 1 and 𝑗 = 𝑀 using the coefficient as

above:

𝑗 = 1,𝑀 − 1

[ − (

2

Δ𝑡+

4

Δ𝑥2) − (

𝑉𝑗

4Δ𝑋+

𝐷

2Δ𝑋2) ⋯ ⋯ ⋯

⋯ (𝑉𝑗

4Δ𝑋+

𝐷

2Δ𝑋2) −(

2

Δ𝑡+

𝐷

Δ𝑥2) −(

𝑉𝑗

4Δ𝑋−

𝐷

2Δ𝑋2) ⋯

⋮ ⋮ ⋮ ⋮ ⋮

⋯ ⋯ ⋯ (𝐷

Δ𝑥2) −(

2

Δ𝑡+

𝐷

Δ𝑥2)]

{

𝑌𝑖

}

𝑡+1 2⁄

=

{

𝑑(𝑖, 𝑗)⋮

𝑑(𝑖, 𝑗)𝑖 = 2, 𝑁 − 1

⋮⋮

𝑑(𝑁, 𝑗) }

𝑡

Page 151: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

6

𝑗 = 𝑀

[ − (

2

Δ𝑡+

4

Δ𝑥2) − (

𝑉𝑀4Δ𝑋

−𝐷

2Δ𝑋2) ⋯ ⋯ ⋯

⋯ (𝑉𝑀4Δ𝑋

+𝐷

2Δ𝑋2) −(

2

Δ𝑡+

𝐷

Δ𝑥2) −(

𝑉𝑀4Δ𝑋

−𝐷

2Δ𝑋2) ⋯

⋮ ⋮ ⋮ ⋮ ⋮

⋯ ⋯ ⋯ (𝐷

Δ𝑥2) −(

2

Δ𝑡+

𝐷

Δ𝑥2)]

{

𝑌𝑖

}

𝑡+1 2⁄

=

{

𝑑(1,𝑀)⋮

𝑑(𝑖,𝑀)𝑖 = 2, 𝑁 − 1

⋮⋮

𝑑(𝑁,𝑀) }

𝑡

Now, sweep in ′𝑗′ direction and march in ′𝑖′ direction for (𝑡 + 1) based on the 𝑦(𝑖, 𝑗) values you

determined at (𝑡 + 1 2⁄ ) step (above)

𝐴𝑦𝑡+1(𝑖, 𝑗) = 𝑑𝑡+12 ⁄

𝑖 = 1,𝑁𝑗 = 0,𝑀

}

Discretize 𝑗 = 0

𝐶𝑖,𝑗𝑡+1 − 𝐶

𝑖,𝑗

𝑡+1 2⁄

Δ𝑡2⁄

=1

2[((−𝑉𝑗)

𝐶𝑖+1,𝑗 − 𝐶𝑖−1,𝑗

2Δ𝑋 + 𝐷

𝐶𝑖+1,𝑗 − 2𝐶𝑖,𝑗 + 𝐶𝑖−1,𝑗

Δ𝑋2 )

𝑡+1 2⁄

+ 2𝐷 (𝐶𝑖,𝑗+1 − 2𝐶𝑖,𝑗 + 𝐶𝑖,𝑗−1

Δ𝑟2 )𝑡+1

] (𝑖 = 1,𝑁)

𝑗 = 1,𝑀

implicit

explicit

Page 152: Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books: 1) Numerical Methods for Engineers (SKG) 2) Numerical Methods for Engineering Application

7

𝐶𝑖,𝑗𝑡+1 − 𝐶

𝑖,𝑗

𝑡+1 2⁄

Δ𝑡2⁄

=1

2[((−𝑉𝑗)

𝐶𝑖+1,𝑗 − 𝐶𝑖−1,𝑗

2Δ𝑋 + 𝐷

𝐶𝑖+1,𝑗 − 2𝐶𝑖,𝑗 + 𝐶𝑖−1,𝑗

Δ𝑋2 )

𝑡+1 2⁄

+ 𝐷 (1

𝑟𝑗

𝐶𝑖,𝑗+1 − 𝐶𝑖,𝑗−1

2Δ𝑟 +𝐶𝑖,𝑗+1 − 2𝐶𝑖,𝑗 + 𝐶𝑖,𝑗−1

Δ𝑟2 )

𝑡+1

] (𝑖 = 1, 𝑁)

In this last lecture of the course, I leave it here for you to do the remaining part (arranging the

terms and applying BCs for 𝑖 = 1, (2⋯𝑁 − 1), 𝑁 rows to invert the matrix) as you sweep in

′𝑗′ direction, as an exercise. The topic on ADI stops here.

Note: (1) The SS solution 𝑦(𝑡, 𝑥, 𝑟) 𝑎𝑠 𝑡 → ∞ of the time-dependent 2D parabolic equation

must be the same as that of the corresponding 2D elliptic PDE you have learnt how to solve in

the preceding lecture, using ‘Method of Lines’, i.e. for

𝜕𝐶

𝜕𝑡+ 𝑉. ∇𝐶 = 𝐷∇2𝐶 + (−𝑟𝐴) ;

𝐶(𝑡, 𝑥, 𝑟) 𝑎𝑠 𝑡 → ∞ must be the same as that of

𝑉. ∇𝐶 = 𝐷∇2𝐶 + (−𝑟𝐴) ⇒ 𝐶(𝑥, 𝑟)

(2) A question arises. When asked to solve the elliptic (2D) PDE, should not or cannot we

artificially insert the transient term 𝜕𝐶

𝜕𝑡 and seek the SS solution to the corresponding time-

dependent 2D parabolic equation? Very often, yes. Recall that, solving elliptic PDE requires

iterations and there is always a convergence issue. How many iterations? On the other hand,

the parabolic equation does not require iterations, and you march on ′𝑡′ axis solving 𝑦(𝑥, 𝑟) at

every time step without iterations. Therefore, more than often the ADI method is preferred

over ‘Method of Lines’ for solving an elliptic (2D) PDE. Insert the transient term and solve till

you have SS solution.

(3) Before closing this chapter, let us answer how we address non-linearity in the differential

term, for example, V𝜕𝑉

𝜕𝑥 of the NS equation? The answer is simple. By iterations! Guess velocity

fields (Vg). Discretize the derivative term as before. Solve for velocity fields as before. Iterate

till there is convergence. Alternatively, Taylor’s series can also be used to approximate velocity

fields by linearlization, in which case guesses are required for the velocity gradients.

End – Semester Exam These lectures are usually covered in approximately 42 one-hour or 28 1hr 15min lectures.

All comments including suggestions and corrections may be sent to [email protected] .