+ All Categories
Home > Documents > Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books:...

Lecture #01...Finite Difference-based Numerical Methods in Chemical Engineering . Recommended Books:...

Date post: 26-Mar-2021
Category:
Upload: others
View: 24 times
Download: 0 times
Share this document with a friend
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:
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] .


Recommended