Linear Algebraic Equations: 1.1 Tridiagonal Matrix Algorithm (TDMA)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Chapter 1

Linear Algebraic Equations

A system of linear algebraic equations can be solved by direct or iterative methods. The direct
methods discussed in this chapter are the TriDiagonal Matrix Algorithm (TDMA) and Gauss
Elimination methods, and the iterative method discussed is the Gauss-Seidel method.
A tridiagonal or block tridiagonal set of linear algebraic equations is formed during the
discretization of ordinary and partial differential equations. The discretization of differential
equations using the finite difference method is discussed in Chapters 5 to 10. All types of linear
algebraic equations can be solved using the Gauss Elimination method, but if the equations are
of tridiagonal type, then TDMA is very fast as compared to the Gauss Elimination method. The
Gauss–Seidel method is used for the solution of two-dimensional steady heat transfer, which
is discussed in Chapter 10.

1.1 Tridiagonal Matrix Algorithm (TDMA)


TDMA is a direct method. Consider the following tridiagonal set of linear algebraic equations:

ªD E º ª Z º ª F º
«C D E » «Z » «F »
«  »«  » «  »
« C D E » « Z » « F »
« »« » « »
« C D E » « Z » « F »
«    » « » « » (1.1)
« »« » « »
«    » « » « »
«    » « » « »
« »« » « »
« C0  D0  E0  » « Z 0  » « F 0  »
« »« » « »
¬« C0 D0 ¼» ¬« Z 0 ¼» ¬« F 0 ¼»

N linear algebraic equations can be written in the form Ax = d. The matrix A contains elements
on the diagonal (bi, i = 1 to N), sub-diagonal (ai, i = 2 to N), and super-diagonal (ci, i = 1 to
N – 1), and thus is called a tridiagonal matrix. The algorithm for the solution of this sort of
linear algebraic equation is called the TriDiagonal Matrix Algorithm or the Thomas algorithm.
1
2 Introduction to Numerical Methods in Chemical Engineering

The equations are of the type


C Z   D Z  E Z 
K K K K K K
F K
where a1 = 0, cN = 0 (1.2)
Let us write the solution at xi in terms of xi+1 as
E Z 
Z H  K K
K K
(1.3a)
CK
Then we can also write
E  Z
Z K
H K   K K
(1.3b)
C K 
where bi and gi are obtained by substituting Eq. (1.3b) into Eq. (1.2). Thus we get
§ E Z ·
C ¨ H    ¸  D Z  E Z 
K K
K K
K K K K
F K
© C  ¹ K

The above equation can be written as


§ C E  ·
¨D  ¸Z F  CH  E Z 
K K
K K K K K  K K

© C  ¹ K

Thus
F  C H  E
Z  Z 
K K K K

§ · § C E  ·
K K
C E 
¨D  ¸ ¨D 
K K K K
¸ K K
© C  ¹ © C  ¹ K K

Comparing with Eq. (1.3a), we get


C E 
C D  K K
(1.4)
K K
C K

F  CH  F  CH 
HK K K K K K K

§ C E  · CK
¨D  ¸ K
K K
(1.5)
© C  ¹ K

a1 = 0; therefore
b1 = b1 (1.6)
and
F
H (1.7)
D
The algorithm for the solution of a tridiagonal set of linear algebraic equations is given below:
(i) Calculate bi and gi for i = 1 to N.

E Z
(ii) Calculate Z 0 H 0  0 0  . Since cN = 0, therefore xN = g N.
C0
E Z 
(iii) Calculate Z HK  for i = N – 1, N – 2, …, 3, 2, 1.
K K
K
CK
Linear Algebraic Equations 3

EXAMPLE 1.1 Solve the following set of linear algebraic equations using TDMA

ª   º ª Z º ª  º
«    » «Z » «  »
« »« » « »
«    » « Z » «  »
« »« » « »
«    » « Z » «  »
«    » « Z » «  »
« »« » « »
«   » « Z » «  »
««
¬   »»¼ ««¬ Z »»¼ ««  »»
¬ ¼
Solution We have

C D  
F 
H 
D 

C E  
C D   
C  

F  CH     u   


H
C   
 
 

C E  
C D    
C  




 
F  CH  
H 
C 



C E  
C D    
C  



F  CH    


H 
C 



C E  
C D   
C  


4 Introduction to Numerical Methods in Chemical Engineering

F  CH     


H
C  



C E  
C D    
C  




 
F  CH   
H
C  



C E  
C D    
C  




 
F  CH   
H
C  


Now let us compute the solution starting with x7.

Z H 

E Z   
Z H     u 
C   

E Z   u 
Z H     
C  

E Z  u 
Z H      
C 

E Z  u 
Z H      
C 

E Z  
Z H     
C  

E Z 
Z H    
C 
Linear Algebraic Equations 5

Program 1.1 uses the above method for solving the tridiagonal system of linear algebraic
equations and is given in the Appendix.

1.2 Gauss Elimination Method


Gauss Elimination is a direct method. The Gauss Elimination method reduces the system of
equations to an upper triangular system which can then be solved by back substitution.
Consider the following system of three linear algebraic equations:
C Z  C Z  C Z F
C Z  C Z  C Z F
C Z  C Z   C Z F
The augmented matrix is

ª C C C F º


« »
« C C C F »
(1.8)
« C C C F »¼
¬
C
Take the element a11 as the pivot. Multiply the first equation by   and then add it to the
second equation, which then becomes C

§ CC · § CC · C


¨ C  ¸ Z  ¨ C  ¸ Z F  F
© C ¹ © C ¹ C
Thus x1 is eliminated from the second equation. Similarly, eliminate x1 from the third
C
equation by multiplying the first equation by  and then adding it to the third equation.
C
At the end of the first stage the augmented matrix becomes
ª C C C F º
« »
« c
C c Fc »
C
(1.9)
« c
C c Fc »¼
C
¬
c
C
Now take the element a¢22 as the new pivot. Multiply the second equation by  and then
c
C
add it to the third equation. Thus x2 is eliminated from the third equation. At the end of the
second stage the augmented matrix becomes

ª C C C F º


« »
« c
C c
C Fc »
(1.10)
«  cc
C Fcc »¼
¬
The values of x1, x2, and x3 can be obtained by back substitution. The pivots should be chosen
in such a way that they are nonzero. Rows can be exchanged so that the pivot is nonzero. This
procedure is called partial pivoting.
6 Introduction to Numerical Methods in Chemical Engineering

EXAMPLE 1.2 Solve the following set of three linear algebraic equations in three variables
using the Gauss Elimination method:
 Z  Z    Z 
 Z   Z   Z 
Z   Z    Z 
Solution The augmented matrix is

ª    º
« »
«    »
«    »
¬ ¼

Multiply the first equation by  and then add it to the second equation. We get

ª    º
« »
«     »
«     »¼
¬

Multiply the first equation by  and then add it to the third equation. We get

ª    º
« »
«     »
«     »
¬ ¼

This completes the first stage. Multiply the second equation by  and then add it to the

third equation. We get

ª    º
« »
«     »
«     »¼
¬
From the previous equation we get
9.68367x3 = 48.418367
Solving, we get x3 = 5.
From the second equation we get
9.8x2 + 0.6x3 = 42.2
   u 
Thus Z 

From the first equation we get
10x1 + x2 + 2x3 = 44
Linear Algebraic Equations 7

     u 
Thus Z .


Program 1.2 uses the Gauss elimination method for solving a system of linear algebraic
equations and is given in the Appendix.

EXAMPLE 1.3 Solve the following set of three linear algebraic equations in three variables
using the Gauss Elimination method:
 Z  Z    Z 
 Z   Z   Z 
Z  Z    Z 
Solution The augmented matrix is

ª     º
« »
«    »
«    »
¬ ¼

Multiply the first equation by and then add it to the second equation. We get

ª    º
« »
«   »
«   »¼
¬

Multiply the first equation by  and then add it to the third equation. We get

ª    º
« »
«   »
«    »
¬ ¼

Multiply the second equation by 0.3076923 and then add it to the third equation. We get

ª   º
« »
«   »
«    »¼
¬

From the previous equation, we get


3.5384x3 = –3.5384
Solving, we get x3 = –1.
8 Introduction to Numerical Methods in Chemical Engineering

From the second equation, we get


4.3333x2 – 3.6667x3 = –5
  
Thus Z  .

From the first equation, we get
3x1 + x2 – 2x3 = 9

Thus Z .

EXAMPLE 1.4 Benzene (1), toluene (2), styrene (3), and xylene (4) are to be separated in
the sequence of distillation columns shown in Fig. 1.1. Determine molar flow rates of streams
D1, B1, D2, and B2. The composition of the feed stream and the streams D1, B1, D2, and B2 is
shown in the figure. Also, determine the molar flow rates and compositions of streams B and
D. The molar flow rate of the feed stream is 70 mol/min.
D1 x1 = 0.35
x2 = 0.54
x3 = 0.04
x4 = 0.07

x1 = 0.16
B1 x2 = 0.42
x1 = 0.20 x3 = 0.24
x2 = 0.40 70 mol/min x4 = 0.18
x3 = 0.25
x4 = 0.15 D2 x1 = 0.21
x2 = 0.54
x3 = 0.10
x4 = 0.15

x1 = 0.01
x2 = 0.10
B2 x3 = 0.65
x4 = 0.24
Fig. 1.1 Schematic diagram for Example 1.4.

Solution The material balance equations for benzene (1), toluene (2), styrene (3), and xylene
(4) are given below.
Linear Algebraic Equations 9

 u  &   $  &  $

 u   &   $   &   $

 u   &   $   &  $

 u   &  $  &   $

The above equations can be written as

ª    º ª & º ª  º


« « »
«    »» « $ » « »
« »
«    » « & » «»
« »« » « »
«¬    »¼ ¬« $ ¼» ¬«¼»
Solving by using the Gauss Elimination method, we get
D1 = 26.25 mol/min
B1 = 17.5 mol/min
D2 = 8.75 mol/min
B2 = 17.5 mol/min.
B = D2 + B2 = 26.25 mol/min.
The composition of stream B is given by
&  $
Z$ 
$
 &   $
Z $ 
$
 &  $
Z$ 
$
&   $
Z $ 
$
D = D1 + B1 = 43.75 mol/min.
The composition of stream D is given by

&   $
Z& 
&
 &   $
Z & 
&
10 Introduction to Numerical Methods in Chemical Engineering

 &   $


Z & 
&
 &  $
Z& 
&
Now, let us check the solution obtained. B + D is 70 mol/min, which is correct. Now, let us
back-calculate the feed composition.
&Z&  $Z$


&Z  &  $Z  $


&Z &  $Z $


&Z  &  $Z  $



1.3 Gauss–Seidel Method


Gauss–Seidel is an iterative method. Consider a system of N linear algebraic equations in N
variables. The first equation can be written with variable x1 on the left hand side and the rest
of the terms on the right hand side. Similarly, the second equation can be written with variable
x2 on the left hand side and the rest of the terms on the right hand side, and so on. Now we
can assume some values of the variables, and compute the new value of x1 from the first
equation and the new value of x2 from the second equation, and so on. In the Gauss–Seidel
method, when the new value of x2 is computed from the second equation then on the right hand
side for the variable x1 the updated value calculated from the first equation, is used. Similarly,
when the new value of x3 is calculated from the third equation, then on the right hand side for
the variables x1 and x2 the updated values calculated from the first and second equations are
used. By doing this a higher convergence rate is obtained. So the latest values of the variables
are always used.
In the above explanation it is assumed that in the first equation the coefficient of x1 is
the highest among the coefficients of the other variables, and in the second equation the
coefficient of x2 is the highest among the coefficients of the other variables. All the equations
have many variables in them. A survey of the given system of linear algebraic equations is
made and that variable which has the highest coefficient is kept on the left hand side. The
variable whose coefficient is the largest is used to express that variable in terms of the others.
The Gauss–Seidel method has the disadvantage of not always converging to a solution
and of sometimes converging very slowly. However, this method will always converge to a
solution when the magnitude of the coefficient on the left hand side is sufficiently dominant
with respect to the magnitudes of the other coefficients in that equation.
Linear Algebraic Equations 11

EXAMPLE 1.5 Solve the following set of three linear algebraic equations in three variables
using the Gauss–Seidel method:
10x1 + x2 + 2x3 = 44
2x1 + 10x2 + x3 = 51
x1 + 2x2 + 10x3 = 61
Solution It can be seen that the coefficient of x1 is dominant in the first equation, and the
coefficient of x2 and x3 are dominant in the second and third equations, respectively. Thus
  ZP   ZP
ZP 

   ZP   ZP
ZP 

  ZP    ZP 
ZP 

Let us assume x2 = 0, x3 = 0. The initial values used will not affect the converged solution, but
will affect the number of iterations required for convergence.
First Iteration:
    
Z 

   u   
Z 

     – 
Z 

Second Iteration:
     u 
Z 

   u   
Z 

     u 
Z 

The final converged solution is x1 = 3, x 2 = 4, x3 = 5.
Program 1.3 uses the Gauss–Seidel method for solving a system of linear algebraic equations
and is given in the Appendix.

EXAMPLE 1.6 Solve the following set of three linear algebraic equations in three variables
using the Gauss–Seidel method:
 Z  Z    Z 
 Z   Z   Z  
Z  Z    Z 
12 Introduction to Numerical Methods in Chemical Engineering

Solution Let us write the first, second and third equations in the form
  ZP   ZP
ZP 

  ZP    ZP
ZP 

  ZP   ZP 
ZP 

Let us assume x2 = 0, x3 = 0.
First Iteration:

Z 

    
Z  

    
Z  

Second Iteration:
     u 
Z 

     u 
Z  

    
Z  

The final converged solution is x1 = 3, x2 = –2, x3 = –1.

Exercises
1.1 Solve the following using TDMA:
ª   º ª Z º ª  º
«    » « Z » « »
« »« » « »
«    » « Z » «  »
« »« » « »
«     » « Z » «  »
«     » « Z » «  »
« »« » « »
«    » « Z » «  »
«   » « Z » «  »
« »« » « »
¬«   ¼» ¬« Z ¼» ¬«  ¼»
(Ans: x1 = 111.11, x2 = 122.22, x3 = 133.33, x4 = 144.44, x5 = 155.55,
x6 = 166.66, x7 = 177.77, x8 = 188.88)
Linear Algebraic Equations 13

1.2 Solve the following linear algebraic equations using the Gauss elimination method:
2x1 – x2 = 100
– x1 + 2x2 – x3 = 0
– x2 + 2x3 – x4 = 0
– x3 + 2x4 – x5 = 0
– x4 + 2x5 – x6 = 0
– x5 + 2x6 – x7 = 0
– x6 + 2x7 – x8 = 0
– x7 + 2x8 = 200
Note that the augmented matrix for this problem is

ª          º
« »
«          »
«          »
« »
«          »
«          »
« »
«           »
«          »
« »
«¬          »¼

(Ans: x1 = 111.11, x2 = 122.22, x3 = 133.33, x4 = 144.44, x5 = 155.55,


x6 = 166.66, x7 = 177.77, x8 = 188.88)
1.3 Solve the equations in Problem 1.2 using the Gauss–Seidel method.
Note that the equations are expressed in the form
  ZP
ZP 

ZP   ZP
ZP 


ZP   ZP
ZP 

ZP   ZP
Z P 

ZP   ZP
ZP 

14 Introduction to Numerical Methods in Chemical Engineering

ZP   Z P
ZP 

ZP   ZP
Z P 

  Z P 
ZP 

(Ans: x1 = 111.11, x2 = 122.22, x3 = 133.33, x4 = 144.44, x5 = 155.55,
x6 = 166.66, x7 = 177.77, x8 = 188.88)
1.4 Solve the following linear algebraic equations using the Gauss elimination method:
4x1 + 2x2 + x3 = 11
–x1 + 2x2 = 3
2x1 + x2 + 4x3 = 16
Note that the augmented matrix is

ª    º
« »
«    »
«     »
¬ ¼
(Ans: x1 = 1, x2 = 2, x3 = 3)

1.5 Solve the linear algebraic equations of Problem 1.4 using the Gauss–Seidel method:
Note that for Gauss–Seidel to converge the equations are expressed in the form
   ZP  ZP
ZP 


  ZP 
ZP 

   ZP   ZP 
ZP 

(Ans: x1 = 1, x2 = 2, x3 = 3)

1.6 Solve the following linear algebraic equations using the Gauss elimination method:
 Z   Z   Z 
Z   Z  Z 
 Z   Z   Z 
(Ans: x1 = 1.2857, x2 = 1.9286, x3 = 2.8571)
Linear Algebraic Equations 15

1.7 Solve the linear algebraic equations of Problem 1.6 using the Gauss-Seidel method:
Note that for Gauss–Seidel to converge the equations are expressed in the form
   ZP   ZP
ZP 

  ZP   ZP
ZP 


   ZP    ZP 
ZP 

(Ans: x1 = 1.2857, x2 = 1.9286, x3 = 2.8571)
1.8 Solve the following linear algebraic equations using the Gauss elimination method:

ª          º ª6 
º ª  º
«   « »
«        »» «6 
»
«  »
« »
«          » «6 » «  »
»« »

« « »
«          » «6  » «  »
«          » «6 » « »
« »« » « »


«         » «6  » «  »
«          » ««6 »
»
«  »
« » 
« »
«         » «6 
» «  »
« »« » « »
¬«          ¼» ¬«6  ¼» ¬«  ¼»
Note that for using the Gauss elimination method the equations have to expressed
in the form of augmented matrix as

ª           º
« »
«           »
«           »
« »
«           »
«          »
« »
«           »
«           »»
«
«           »
« »
«¬           »¼
(Ans: T1,1 = 47.14, T1,2 = 91.25, T1,3 = 182.86, T2,1 = 57.32, T2,2 = 115.00,
T2,3 = 220.18, T3,1 = 47.14, T3,2 = 91.25, T3,3 = 182.86)
16 Introduction to Numerical Methods in Chemical Engineering

1.9 Solve the following linear algebraic equations using the Gauss–Seidel method:
6  6  6 
  

6  6
 
6 6
 

6
 6  6  

6  6
 
6 
6 

6
6
 6 
6
6 

6 6
 
 6 
6 

6
 6  6  

6 
 6  6
 
6 

6  6  6 
  

Note that for Gauss–Seidel to converge the equations are to be expressed in the
form
  6P  6 P
6 P   




6P   6 P  6 P  
6 P    




6P  6 P  
6 P   




6P  6 P  6 P  
6 P    




6P  6 P  6 P  6 P
6 P     




6P   6 P   6 P  
6 P    




P  P
P    6  6
6

P  P  P
P  6  6  6  
6

P  P 
P  6  6  
6

(Ans: T1,1 = 47.14, T1,2 = 91.25, T1,3 = 182.86, T2,1 = 57.32, T2,2 = 115.00,
T2,3 = 220.18, T3,1 = 47.14, T3,2 = 91.25, T3,3 = 182.86)

You might also like