Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers...

76
Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES

Transcript of Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers...

Page 1: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 3 Solution of Algebraic

Equations

1

ChE 401: Computational Techniques for Chemical Engineers

Fall 2009/2010

DRAFT SLIDES

Page 2: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

1. Basic definitions

2. Consistency of equations and existence of solutions

3. Gaussian Elimination

4. LU Factorization

5. Gauss-Seidel Method

Ch

apte

r 1

Lecture Outline

2

Ch

apte

r 3

DRAFT SLIDES

Page 3: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Basic definitions

3

Ch

apte

r 3

Representation of linear systems

DRAFT SLIDES

Page 4: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

4

Ch

apte

r 3

Matrix rank

The rank r of matrix A is defined as the order of the largest nonsingular square matrix within A. OR

The rank of a matrix is the maximum number of independent rows (or, the maximum number of independent columns).

Singular matrix is a

matrix that has zero

determinant

DRAFT SLIDES

Page 5: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

5

Ch

apte

r 3

Matrix rank

Example 1: consider the following (34) matrix:

8426

3125

4213

There are four sub-matrices of order (33):

426

125

213

826

325

413

846

315

423

842

312

421

det = 0

r = 2DRAFT SLIDES

Page 6: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

6

Ch

apte

r 3

DRAFT SLIDES

Page 7: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

7

Ch

apte

r 3

Consistency of equations and existence of solutions

The solution of a system of linear equations may or may not exist, and it may or may not be unique. Consider the following general system.

M

2

1

MN2M1M

N22221

N11211

b

b

b

,

aaa

aaa

aaa

bA

N unknowns are related by M equationsDRAFT SLIDES

Page 8: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

8

Ch

apte

r 3

Consistency of equations and existence of solutions

M = N has unique solution if - no row is a linear combination of the others (row degeneracy), or

- no column is a linear combination of the others (column degeneracy)

Nonsingular matrix has a unique solution

Mathematically these statements are exact,

but, Numerically…..

DRAFT SLIDES

Page 9: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

9

Ch

apte

r 3

Consistency of equations and existence of solutions: numerical issues

If a system is too close to linear dependence …

an algorithm may fail altogether to get a solution round off errors can produce apparent linear

dependence at some point in the solution process

-1000 -500 0 500 1000-1000

-500

0

500

1000

1500

t

f(t)

f1 = t+1f2 = 0.95t +1.01

The numerical procedure will fail totally

DRAFT SLIDES

Page 10: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

10

Ch

apte

r 3

Consistency of equations and existence of solutions: numerical issues

If a system is too close to linear dependence …

an algorithm may still work but produce nonsense accumulated round of errors can swamp the solution - particularly in close-to-singular systems - particularly if N is too large

not algorithmic failure, but answer is (wildly) incorrect

Error can be confirmed by direct substitution in original equations

How can we check for the error in answers in this case?

DRAFT SLIDES

Page 11: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

11

Ch

apte

r 3

Consistency of equations and existence of solutions

Under-determined systems…..

M<N OR M = N with degenerate equations Fewer equations than unknowns

May be no solution, OR

May be an infinite number of solutions i.e. subspaces of solutions - arbitrary values must be assigned to (N-M) unknowns. - changing the values of (N-M) unknowns, results in new

values for the rest of unknowns. - singular value decomposition is a powerful technique

DRAFT SLIDES

Page 12: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

12

Ch

apte

r 3

Consistency of equations and existence of solutions

Over-determined systems…..

M>N AND no degenerate More equations than unknowns Generally there is no solution The best compromise solution is sought - closest to satisfy all equations - requires quantification of “closeness” to correct

solution - most often: sum of squares of differences between left and right hand sides is minimized linear least squares problem

DRAFT SLIDES

Page 13: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

13

Ch

apte

r 3

Consistency of equations and existence of solutions: second approach…

The solution of a system of linear equations may or may not exist, and it may or may not be unique. Existence of solutions can be determined by comparing the rank of the Matrix A with the rank of the augmented matrix Aa.

NMN2M1M

2N22221

1N11211

M

2

1

MN2M1M

N22221

N11211

baaa

baaa

baaa

b

b

b

,

aaa

aaa

aaa

aAbA

N unknowns are related by M equationsDRAFT SLIDES

Page 14: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

14

Ch

apte

r 3

Consistency of equations and existence of solutions

The set of equations has a solution if, and only if, the rank of the augmented matrix is equal to the rank of the coefficient matrix.

If in addition:

rank (A) = N unique solution

rank (A) < N & rank (A) = rank (Aa) Infinite number of solutions

rank (A) < N & rank (A) < rank (Aa) No solution

DRAFT SLIDES

Page 15: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

15

Ch

apte

r 3

Some examples

Solve the following set of 2 equations in 2 unknowns for x and y.

2y6x2

23y15x5

No Solution

DRAFT SLIDES

Page 16: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

16

Ch

apte

r 3

DRAFT SLIDES

Page 17: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

17

Ch

apte

r 3

Some examples

Solution

No Solution

DRAFT SLIDES

Page 18: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Direct methods:

It consists of techniques that do not require iterations to find the solution. Most direct methods involve manipulations of the matrix (A)and vector b to obtain easy to solve equations.

Ch

apte

r 1

Solution of Algebraic Equations

18

Ch

apte

r 3

Indirect (Iterative) methods:

These methods start with initial approximation (guess) xo to the solution x and generate a sequence of vectors xk that converge to the solution vector. These techniques are efficiently used to solve large systems where computer storage and computational time are important considerations.

DRAFT SLIDES

Page 19: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

- It systematically eliminates unknowns from the problem till only one equation and unknown are left.

- The value of this unknown is determined and the remaining unknowns are calculated in turn.

Ch

apte

r 1

Gaussian Elimination (GE)

19

Ch

apte

r 3

Gaussian elimination is very efficient method in solving large sets of linear equations. For large n, it requires n3/2 calculations to get the solution.

DRAFT SLIDES

Page 20: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Consider:

Ch

apte

r 1

Gaussian Elimination

20

Ch

apte

r 3

We use row operations to simplify the system. e.g. eliminate element A21 by subtracting A21/A11 = d21 times row 1 from row 2.

Pivot row

Pivot element

0 0

0

DRAFT SLIDES

A’22 A’

23

A’32 A’

33A”33

Page 21: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gaussian Elimination (A21)

21

Ch

apte

r 3

DRAFT SLIDES

Page 22: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gaussian Elimination (A31)

22

Ch

apte

r 3

DRAFT SLIDES

Page 23: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gaussian Elimination (A32)

23

Ch

apte

r 3

DRAFT SLIDES

Page 24: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Backsubstitutation

24

Ch

apte

r 3

DRAFT SLIDES

Page 25: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

25

Ch

apte

r 3

Example

9211

2224

8323

9x2xx

2x3x2x4

8x3x2x3

321

321

321

9211

2224

8323-4/3*

92113

266

3

140

8323-4 8/3 -4 32/3

DRAFT SLIDES

Page 26: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

26

Ch

apte

r 3

Example

9211

2224

8323

-1/3*

3

191

3

50

3

266

3

140

8323

92113

266

3

140

8323-1 2/3 -1 -8/3

DRAFT SLIDES

Page 27: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

3

191

3

50

3

266

3

140

8323

Ch

apte

r 1

27

Ch

apte

r 3

Example

-5/14*

43.914

4400

3

266

3

140

8323

0 -5/3 30/14 130/42

DRAFT SLIDES

Page 28: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

28

Ch

apte

r 3

Example

43.914

4400

3

266

3

140

8323

1)2*23*38(*)31(x

2)3/263*6(*)143(x

3)1444/(43.9x

1

2

3

DRAFT SLIDES

Page 29: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

29

Ch

apte

r 3

DRAFT SLIDES

Page 30: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

30

Ch

apte

r 3

Example 2.1 in the textbook to be discussed….

DRAFT SLIDES

Page 31: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

31

Ch

apte

r 3

Example: 2.2

1221

4321

2320

1x2x2x

4x3x2x

2x2x2

321

321

32

01x2x2x

2x2x2

4x3x2x

321

32

321

PIVOTINGPARTIAL

There is no restriction upon which equation is placed first or which variable is eliminated first….

DRAFT SLIDES

Page 32: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

32

Ch

apte

r 3

Use Gaussian elimination to solve the following set of equations

0.101.00.1

0.10.101.0

2-digit arithmetic

d21 = 100a21 = 0a22 = 0.01+ 100 100b2 = 1-100 -100x2 = -1x1 = (1.0-1.0)/0.01 = 0

Exact solution…x2 = -0.9899x1 = 1.0099 1.0 % error

100 % error

DRAFT SLIDES

Page 33: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

33

Ch

apte

r 3

Try this……

0.10.101.0

0.101.00.1

2-digit arithmetic

d21 = 0.01a22 = -1-0.0001 -1.0b2 = 1-0.01 -1.0x2 = -1x1 = 1+0.01 1. 0

Exact solution…x2 = -0.9899x1 = 1.0099 1.0 % error

1.0 % error

USE PIVOTING

What did you learn ?

DRAFT SLIDES

Page 34: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

34

Ch

apte

r 3

What about this???

0.101.00.1

0.10.101.0

Multiply the first equation by 200, what do you find?TRY IT BY YOURSELF . . . . . .

DRAFT SLIDES

Page 35: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

LU factorization (without pivoting)

Let:

A = L.U

with L unit lower triangular, U upper triangular, i.e.

Ch

apte

r 1

LU Factorization

35

Ch

apte

r 3

333231

232221

131211

aaa

aaa

aaa

A

DRAFT SLIDES

Page 36: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

LU factorization (without pivoting)

This factorization can be used to solve the following linear set A.x = (L.U).x = L.(U.x) = L.y = b

Such that

L.y = b (forward substitution)U.x = y (backward substitution)

Ch

apte

r 1

LU Factorization

36

Ch

apte

r 3

How many set of linear equations do we have now?

What is the advantage of breaking up one linear set into two successive ones?

DRAFT SLIDES

Page 37: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Algorithm….

This method is called Doolittle’s factorization

Partition A, L, U as block matrices:

with L22 unit-lower triangle and U22 upper triangle

Ch

apte

r 1

LU Factorization

37

Ch

apte

r 3

333231

232221

131211

aaa

aaa

aaa

A

DRAFT SLIDES

Page 38: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Determine L, U from A = L.U, i.e.

this gives

u11= a11, U12 = A12, L21 = (1/a11)A21

L22U22 = A22 – L21U12

Ch

apte

r 1

LU Factorization

38

Ch

apte

r 3

DRAFT SLIDES

Page 39: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Example….

Factorize matrix A

Ch

apte

r 1

LU Factorization

39

Ch

apte

r 3

Solution…

DRAFT SLIDES

Page 40: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

40

Ch

apte

r 3

Solution…

Step 1: First row of U and first column of L

Step 2: Find l32, u22, u23 and u33

L22U22 = A22 – L21U12

= -

DRAFT SLIDES

Page 41: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

41

Ch

apte

r 3

Solution…

Step 2: Find l32, u22, u23 and u33

= -

=

DRAFT SLIDES

Page 42: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Note….

Re-solve the previous example using GE method

Ch

apte

r 1

LU Factorization

42

Ch

apte

r 3

What are the values for dij?

d21 = 1/2d31 = 6/8d32 = 11/16

Compare

DRAFT SLIDES

Page 43: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Note….

Re-solve the previous example using GE method

Ch

apte

r 1

LU Factorization

43

Ch

apte

r 3

After elimination steps we got

Compare

DRAFT SLIDES

Page 44: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Note….

Solving a set of equations using LU decomposition takes the same number of calculations as Gaussian elimination since both methods are essentially equivalent. Why to use this method?

Ch

apte

r 1

LU Factorization

44

Ch

apte

r 3

1. The solution of a triangular set of equations is quite trivial, forward substitution is used to find y elements and vector x is obtained using back substitution scheme

n,,3,2,1i)ylb(l

1y

lby1i

1jjiji

iii

1111

1,,2n,1ni)xuy(u

1x

uyxn

1ijjiji

iii

nnnn

DRAFT SLIDES

Page 45: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Note….

Solving a set of equations using LU decomposition takes the same number of calculations as Gaussian elimination since both methods are essentially equivalent. Why to use this method?

Ch

apte

r 1

LU Factorization

45

Ch

apte

r 3

2. Once A is transformed into L and U, it can be used with any right-hand-side vector, b.

DRAFT SLIDES

Page 46: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

MATLAB has built in routines for solving linear systems. For LU decomposition, use the command “lu”. Consider the previous example

Ch

apte

r 1

LU Factorization

46

Ch

apte

r 3

A =[8 2 9;4 9 4;6 7 9];

[L,U]=lu(A)

b=[1;2;3];

Y=L\b;

X=U\Y

DRAFT SLIDES

Page 47: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Example 2.4, p.26

Ch

apte

r 1

47

Ch

apte

r 3

DRAFT SLIDES

Page 48: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Example 2.4, p.26

Ch

apte

r 1

48

Ch

apte

r 3

[ ]x

b

ADRAFT SLIDES

Page 49: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Example 2.4, p.26

Ch

apte

r 1

49

Ch

apte

r 3

For MATLAB code, see m-file called Example 24

DRAFT SLIDES

Page 50: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

50

Ch

apte

r 3 Example 2.3 in the textbook to

be discussed….

DRAFT SLIDES

Page 51: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

A three-stages absorption system, shown in the figure below, is described by the following set of equations:

Ch

apte

r 1

Example….

51

Ch

apte

r 3

fLxaGxxaGL 21)(

0)( 321 aGxxLaGLx

fGyxaGLLx 32 )(

Lxf

Gy3

stage 3

stage 2

stage 1

Lx1

Gyf

Solve for the values of xi and yi, for the following data: xf = 0.01, yf = 0.06, L = 40.8 lb/min, G = 66.7 lb/min, a=0.72. Note that yi = axi

51DRAFT SLIDES

Page 52: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Solution

52

Ch

apte

r 3

01.08.40x7.6672.0x)7.6672.08.40( 21

0x7.6672.0x)8.407.6672.0(x8.40 321

06.07.66x)8.407.6672.0(x8.40 32 Lxf

Gy3

stage 3

stage 2

stage 1

Lx1

GyfUse MATLAB….

00.4x82.88x80.40

0x7.02.48x82.88x80.40

41.0x7.02.48x82.88

32

321

21

52DRAFT SLIDES

Write your code

Page 53: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

53

Ch

apte

r 3 1xand1x:Solution

0001.2x0001.1x

2xx

21

21

21

DRAFT SLIDES

System Condition

1xand3x:Solution

0001.2x9999.0x

2xx

21

21

21

0xand2x:Solution

2x0001.1x

2xx

21

21

21

Condition number ~ 104,It is ill-conditioned system

Determinant = 110-4

Page 54: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

54

Ch

apte

r 3 Why to use this method?

- It requires fewer calculations than GE for very large systems of linear equations or for linear equations with a sparse coefficient matrix which is not banded.

- It is an efficient method for the solution of ill-conditioned set of linear equations.

- If the physics of the problem are understood, a close initial guess can be made, decreasing the number of iterations needed.

DRAFT SLIDES

An iterative approach

Page 55: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

55

Ch

apte

r 3

Basic Procedure:

- Algebraically solve each linear equation for xi

- Assume an initial guess solution array

- Solve for each xi

- Check for error after each iteration to check if error is within a pre-specified tolerance.

- Repeat until error is within the tolerance.

DRAFT SLIDES

Page 56: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

56

Ch

apte

r 3

AlgorithmA set of n equations and n unknowns:

11313212111 ... bxaxaxaxa nn

2323222121 ... bxaxaxaxa n2n

nnnnnnn bxaxaxaxa ...332211

. . . . . .

If the diagonal elements are non-zero

Rewrite each equation solving for the corresponding unknown

For example:

First equation, solve for x1

n equation, solve for xn

DRAFT SLIDES

Page 57: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

57

Ch

apte

r 3

Algorithm

Rewriting each equation

11

nn131321211 a

xaxaxabx

nn

1n1n,n22n11nnn

1n,1n

nn,1n2n2n,1n22,1n11,1n1n1n

22

nn232312122

a

xaxaxabx

a

xaxaxaxabx

a

xaxaxabx

From Equation 1

From equation 2

From equation n-1

From equation n

DRAFT SLIDES

Page 58: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

58

Ch

apte

r 3

Algorithm

General Form for any row ‘i’

.n,,2,1i,a

xab

xii

n

ij1j

jiji

i

DRAFT SLIDES

Page 59: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

59

Ch

apte

r 3

Solve for the unknowns

Assume an initial guess for [X]

n

-n

2

x

x

x

x

1

1

Use rewritten equations to solve for each value of xi.

Remember to use the most recent value of xi.

DRAFT SLIDES

Page 60: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

60

Ch

apte

r 3

Check for the tolerance using a pre-defined criterion such as

100

newi

oldi

newi

ia x

xx

The iterations are stopped when the error is less than a pre-specified tolerance for all unknowns.

DRAFT SLIDES

100x

xxoldi

oldi

newi

ia

oldi

newiia xx

Page 61: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

61

Ch

apte

r 3

Example….

Consider the following set of linear equations:

2.279

2.177

8.106

x

x

x

112144

1864

1525

3

2

1 25

aa58.106x 32

1

8

aa642.177x 31

2

213 a12a1442.279x

DRAFT SLIDES

Page 62: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

62

Ch

apte

r 3

Applying the initial guess and solving for xi

5

2

1

x

x

x

o3

2

1

6720.325

)5()2(58.106x1

8510.7

8

56720.3642.177x2

36.1558510.7126720.31442.279x3

Initial Guess

When solving for x2, how many of the initial guess values were used?

DRAFT SLIDES

Page 63: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

63

Ch

apte

r 3

%76.721006720.3

0000.16720.31a

x

%47.1251008510.7

0000.28510.72a

x

%22.10310036.155

0000.536.1553a

x

Finding the percentage relative error

100

newi

oldi

newi

ia x

xx At the end of the first iteration

The maximum percentage relative error is 125.47%

36.155

8510.7

6720.3

x

x

x

3

2

1

DRAFT SLIDES

Page 64: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

64

Ch

apte

r 3

Iteration #2Using

36.155

8510.7

6720.3

x

x

x

3

2

1

056.12

25

36.1558510.758.106x1

882.54

8

36.155056.12642.177x2

34.798

1

882.5412056.121442.279x3

from iteration #1

the values of ai are found:

DRAFT SLIDES

Page 65: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

65

Ch

apte

r 3

Finding the percentage relative error

%543.69100056.12

6720.3056.121a

%695.85100

882.54

8510.7882.542a

%540.80100

34.798

36.15534.7983a

At the end of the second iteration

54.798

882.54

056.12

x

x

x

3

2

1

The maximum percentage relative error is 85.695%

DRAFT SLIDES

Page 66: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

66

Ch

apte

r 3 Iteration x1 x2 x3

123456

3.672012.05647.182193.33800.533322.6

72.76769.54374.44775.59575.85075.906

−7.8510−54.882−255.51−1093.4−4577.2−19049

125.4785.69578.52176.63276.11275.972

−155.36−798.34−3448.9−14440−60072−249580

103.2280.54076.85276.11675.96375.931

0857.1

690.19

29048.0

x

x

x

3

2

1

Repeating more iterations, we got

Notice – The relative errors are not decreasing

Also, the solution is not converging to the true solution

DRAFT SLIDES

%1a %

2a %3a

Page 67: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

67

Ch

apte

r 3

DRAFT SLIDES

What is the problem?

This example illustrates a drawback of the Gauss-Siedel method: not all systems of equations will converge.

Is it fixable?

One class of system of equations always converges: One with a diagonally dominant coefficient matrix.

Diagonally dominant: A in A.X = b is diagonally dominant if:

n,,2,1iaan

ij1j

ijii

Page 68: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

68

Ch

apte

r 3

DRAFT SLIDES

116123

14345

3481.52

A

1293496

55323

5634124

]B[

Which coefficient matrix is diagonally dominant?

Most physical systems do result in simultaneous linear equations that have diagonally dominant coefficient matrices.

Page 69: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

69

Ch

apte

r 3

DRAFT SLIDES

Example 2

Given the system of equations

15312 321 x- x x

2835 321 x x x

761373 321 x x x

1

0

1

x

x

x

o3

2

1

With an initial guess of

The coefficient matrix is:

1373

351

5312

A

Will the solution converge using the Gauss-Siedel method?

Page 70: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

70

Ch

apte

r 3

DRAFT SLIDES

1373

351

5312

A

Checking if the coefficient matrix is diagonally dominant

43155 232122 aaa

10731313 323133 aaa

8531212 131211 aaa

The inequalities are all true; therefore the solution should converge using the Gauss-Seidel Method

Page 71: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

71

Ch

apte

r 3

DRAFT SLIDES

76

28

1

x

x

x

1373

351

5312

3

2

1

Rewriting each equation

12

531 321

xxx

5

328 312

xxx

13

7376 213

xxx

With an initial guess of

50000.0

12

150311

x

9000.4

5

135.0282

x

0923.3

13

9000.4750000.03763

x

1

0

1

x

x

x

o3

2

1

Page 72: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

72

Ch

apte

r 3

DRAFT SLIDES

The absolute relative approximate error

%00.10010050000.0

0000.150000.01

a

%00.1001009000.4

09000.42a

%662.671000923.3

0000.10923.33a

The maximum percentage relative error after the first iteration is 100%

Page 73: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

73

Ch

apte

r 3

DRAFT SLIDES

Iteration x1 x2 x3

123456

0.500000.146790.742750.946750.991770.99919

100.00240.6180.23621.5464.5391

0.74307

4.90003.71533.16443.02813.00343.0001

100.0031.88917.4084.4996

0.824990.10856

3.09233.81183.97083.99714.00014.0001

67.66218.8764.0042

0.657720.0743830.00101

Repeating more iterations, the following values are obtained

4

3

1

3

2

1

x

x

x

0001.4

0001.3

99919.0

3

2

1

x

x

xThe solution obtained Note that the exact solution is .

%1a %

2a %3a

Page 74: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

74

Ch

apte

r 3

DRAFT SLIDES

Example 3

Given the system of equations

761373 321 xxx

2835 321 xxx

15312 321 xxx

With an initial guess of

1

0

1

3

2

1

x

x

x

Page 75: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

75

Ch

apte

r 3

DRAFT SLIDES

Iteration x1 x2 x3

123456

21.000−196.15−1995.0−20149

2.0364×105

−2.0579×105

95.238110.71109.83109.90109.89109.89

0.8000014.421

−116.021204.6−12140

1.2272×105

100.0094.453112.43109.63109.92109.89

50.680−462.304718.1−47636

4.8144×105

−4.8653×106

98.027110.96109.80109.90109.89109.89

Conducting six iterations, the following values are obtained

The values are not converging?

Your comments……..

%1a %

2a %3a

Page 76: Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.

Ch

apte

r 1

Gauss-Seidel Method

76

Ch

apte

r 3

DRAFT SLIDES

5312

351

1373

A

1373

351

5312

A

Example 3

Example 2

If a system of linear equations is not diagonally dominant, check to see if rearranging the equations can form a diagonally dominant matrix.