0% found this document useful (0 votes)
105 views12 pages

Solution of Linear Algebraic Equations: These Equations Could Also Be Written As

Uploaded by

THE SEZAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views12 pages

Solution of Linear Algebraic Equations: These Equations Could Also Be Written As

Uploaded by

THE SEZAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

SOLUTION OF LINEAR ALGEBRAIC EQUATIONS

Discretization of governing equations and boundary conditions yields a set of linear


algebraic equations with more than 2 unknowns for unknowns at grid points. To find
the values of the dependent variables at grid points, the algebraic equations need to
be solved.

Generally, number of algebraic equations is high, sometimes in the order of millons.


Hence, for the solution of the algebraic equations, systematic techniques should be
developed.

Discretization equations were obtained as

𝒂𝑷 𝑻𝑷 = 𝒂𝑬 𝑻𝑬 + 𝒂𝑾 𝑻𝑾 + 𝒃
These equations could also be written as

aiTi = biTi+1 + ciTi-1 + di i=1, 2, 3, ……. N


or
- ciTi-1 + aiTi - biTi+1 = di i=1, 2, 3, ……. N

NOTE: To solve algebraic equations, matrix operations are commonly used.

These equations can be written as a matrix equation in the following form:

𝐴 𝑇 = 𝐷

where
[A]: Coefficient matrix
[T]: Unknown matrix
[D]: Constant matrix

4 Algebraic Equation Solution


1
Methods
(dx)

i=1 2 3 4 5 6
w e i
A B
W i P E
i-1 i+1 (Dx)B
Dx

- ciTi-1 + aiTi - biTi+1 = di i=1, 2, 3, ……. N

𝑎1 − 𝑏1
0 0 0 0 0 𝑇1 𝑑1
−𝑐2 𝑎2
−𝑏2 0 0 0 0 𝑇2 𝑑2
0 −𝑐3𝑎3 −𝑏2 0 0 0 𝑇3 𝑑3
……… … …
………… ….. = …..
………….. … …
………… …. ….
0 0 0 0 −𝑐𝑁−1 𝑎𝑁−1 −𝑏𝑁−1 𝑇𝑁−1 𝑑𝑁−1
0 0 0 0 0 −𝑐𝑁 𝑎𝑁 𝑇𝑁 𝑑𝑁

NOTE:
1) Number of equations is the same as the number of grid points.
2) Grids 1 and N are boundary grids.
3) In equations for boundary grids, there two unknowns.
4) In equations for inner grids, there are three unknowns.
5) Coefficient matrix is a tri-diagonal matrix, i.e., only three entries around
the diagonal are non-zero, all other entries are zero.

4 Algebraic Equation Solution


2
Methods
ALGEBRAIC EQUATION SOLUTION METHODS

There are two families of solution methods for linear algebraic equations:

1. Direct solution methods


2. Indirect or iterative solution methods

Direct Solution Methods

The number of operations for the solution of the system of N equations with N
unknowns is finite and it is known beforehand. Examples for direct solution methods
are
- Cramer’s rule
- Matrix inversion method
- Gaussian elimination method
- Gauss –Jordan Elimination method (Tri-Diagonal Matrix Algorithm, TDMA)

Iterative Methods

Iterative methods are based on the application of a relatively simple algorithm


repeatedly which eventually leads to a converged solution. The number of iteration
(repetition) can not be predicted in advance. Number of iteration sometimes can be
large. Well known iterative methods are

- Jacobi point by point iterative method


- Gauss-Seidel point by point iterative method

Jacobi and Gauss-Seidel iterative methods are easy to implement in simple computer
programs, but they can be slow to converge when the system of equations is large.
Hence, they are not considered suitable for general CFD procedure.

TDMA is essentialy a direct method for one-dimensional problems, but it can be


applied iteratively, in a line-by-line fashion to solve multi-dimensional problems. This
approach is widely used in CFD programs. It is computationally inexpensive and has
the advantage that it requires a minimum amount of computer storage.

4 Algebraic Equation Solution


3
Methods
Gauss-Jordan Elimination Method (Tri-Diagonal Matrix Algorithm, DTMA)

i=1 2 3 4 5 i=N=6
w e i
A B
W i P E
i-1 i+1
Consider a system of equations obtained for N grids given above.

Let’s write the discretization equations in the following form:

- ciTi-1 + aiTi - biTi+1 = di i=1, 2, 3, ……. N


As a matrix equation, we can write the above equation as

𝑎1 − 𝑏1 0 0 0 0 0 𝑇1 𝑑1
−𝑐2 𝑎2 −𝑏2 0 0 0 0 𝑇2 𝑑2
0 −𝑐3 𝑎3 −𝑏2 0 0 0 𝑇3 𝑑3
……… … …
………… ….. = …..
………….. … …
………… …. ….
0 0 0 0 −𝑐𝑁−1 𝑎𝑁−1 −𝑏𝑁−1 𝑇𝑁−1 𝑑𝑁−1
0 0 0 0 0 −𝑐𝑁 𝑎𝑁 𝑇𝑁 𝑑𝑁

Using TDMA, solution of the above set of equations are obtained in two operations:

1. Forward elimination

Starting from equation i=2, unknown Ti is solved in terms of Ti+1 and substituted into
equation i+1. As a result, one unknown is eliminated from each equation for i = 2, 3,
….. N.

2. Backward substitution

As a result of the forward elimination, one of the unknowns from each equation is
eliminated. Since there were only two unknowns in the last equation, after forward
elimination, only one unknown, TN remains . Then, TN is solved from the last equation,
then by back substitution, all other unknowns TN-1, TN-2, ……… T1 are solved.

4 Algebraic Equation Solution


4
Methods
Forward Elimination

Let’s write the algebraic equation as


aiTi = biTi+1 + ciTi-1 + di (1)
Note that in forward elimination, we look for an expression for Ti in terms of Ti+1. It
can be written as 𝑎 −𝑏 0 0 0 0 0 𝑇 𝑑
1 1 1 1
−𝑐2 𝑎2 −𝑏2 0 0 0 0 𝑇2 𝑑2
Ti = PiTi+1 + Qi (2) 0 −𝑐3 𝑎3 −𝑏2 0 0 0 𝑇3 𝑑3
From Eq. (2), we can also write ……… … …
………… ….. = …..
Ti-1 = Pi-1Ti + Qi-1 (3) ………….. … …
………… …. ….
0 0 0 0 −𝑐𝑁−1 𝑎𝑁−1 −𝑏𝑁−1 𝑇𝑁−1 𝑑𝑁−1
Substituting Eq. (3) into Eq. (1), we get, 0 0 0 0 0 −𝑐𝑁 𝑎𝑁 𝑇𝑁 𝑑𝑁

aiTi = biTi+1 + ci (Pi-1Ti + Qi-1) + di (4)


Rearranging Eq. (4) in the form similar to Eq. (2), we obtain coefficients Pi and Qi as,
𝑏 𝑑 +𝑐 𝑄
Ti = 𝑎 −𝑐 𝑖𝑃 Ti+1 + 𝑎𝑖 −𝑐𝑖 𝑃𝑖−1
𝑖 𝑖 𝑖−1 𝑖 𝑖 𝑖−1

Comparing with Eq. (2), we can write


𝒃𝒊 𝒅𝒊 +𝒄𝒊 𝑸𝒊−𝟏
𝑷𝒊 = 𝑸𝒊 = (5)
𝒂𝒊 − 𝒄𝒊 𝑷𝒊−𝟏 𝒂𝒊 −𝒄𝒊 𝑷𝒊−𝟏
For inner grid points, Pi and Qi are calculated from Eq.(5). For boundary grids, Pi and
Qi are calculated as follows:

𝒃𝟏 𝒅𝟏
For i = 1, c1 = 0 hence, 𝑷𝟏 = 𝑸𝟏 = (6)
𝒂𝟏
𝒂𝟏
𝒅𝑵 +𝒄𝑵 𝑸𝑵−𝟏
For i = N, bN = 0 hence, 𝑷𝑵 = 𝟎 𝑸𝑵 = and TN = QN (7)
𝒂𝑵 −𝒄𝑵 𝑷𝑵−𝟏

Backward Substitution
In the backward substitution, starting from i = N-1, using Eq. (2), we solve TN-1, TN-2,
TN-3, ……….. T2 and T1.

Special Case: Boundary temperatures are given


For i = 1, a1=1, b1, 0, c1 = 0, 𝑻𝟏 = d1
For i = N, aN=1, bN, 0, cN = 0, 𝑻𝑵 = dN

4 Algebraic Equation Solution


5
Methods
Summary of TDMA Algorithm

1) From Eq. (6), P1 and Q1 are calculated for i = 1 (left boundary node)
𝒃𝟏 𝒅𝟏
For i = 1, c1 = 0 hence, 𝑷𝟏 = 𝑸𝟏 = (6)
𝒂𝟏
𝒂𝟏

1) From Eq. (5), Pi and Qi are calculated for i = 2, 3, ….. N-1 (For inner nodes)

𝒃𝒊 𝒅𝒊 +𝒄𝒊 𝑸𝒊−𝟏
𝑷𝒊 = 𝑸𝒊 = (5)
𝒂𝒊 − 𝒄𝒊 𝑷𝒊−𝟏 𝒂𝒊 −𝒄𝒊 𝑷𝒊−𝟏

2) From Eq. (7), PN and QN are calculated for i = N and TN=QN is obtained (right
boundary)
𝒅𝑵 +𝒄𝑵 𝑸𝑵−𝟏
For i = N, bN = 0 hence, 𝑷𝑵 = 𝟎 𝑸𝑵 = and TN = QN (7)
𝒂𝑵 −𝒄𝑵 𝑷𝑵−𝟏

3) From Eq. (2), starting from i=N-1, TN-1, TN-2, ……. T2 and T1 are calculated.
Ti = PiTi+1 + Qi (2)

i=1 2 3 4 5 i=N=6
w e i
A B
W i P E
i-1 i+1

4 Algebraic Equation Solution


6
Methods
Example: Consider heat conduction in an insulated rod. The left end is kept at 200 0C
and from the right end heat is transferred to the surrounding with a rate of qB = 100
W/m2 s. The thermal conductivity k=100 W/m/K and the cross-sectional area of the
rod is A=10x10-3 m2. Calculate the steady state temperature distribution in the rod.
L = 0.5 m

A
TA=200 B
x
Step 1: Mathematical formulation

𝑑 𝑑𝑇
Basic equation: 𝑘 =0
𝑑𝑥 𝑑𝑥
Boundary conditions: At x=0, T=TA=200 oC and at x=L, -kdt/dx=qB

Step 2: Grid (mesh) generation

Equally spaced 4 grid points (except the boundary points) are considered as the
computational mesh, as below.
(dx)

i=1 2 3 4 5 6
w e i
A B
W i P E
i-1 i+1 (Dx)B
Dx

Note: Dx = (dx)e = (dx)w = dx = 0.5/5=0.1, (Dx)B = Dx/2 = 0.05 m

Step 3: Discretization

4 Algebraic Equation Solution


7
Methods
Now we have a set of algebraic equations for all grid points as follows:

For node 1: T1 = 200 Boundary node


For node 2: 2T2 = T1 + T3 2T2 = 200 + T3
For node 3: 2T3 = T2 + T4
Inner nodes
For node 4: 2T4 = T3 + T5
𝒂𝑷 𝑻𝑷 = 𝒂𝑬 𝑻𝑬 + 𝒂𝑾 𝑻𝑾
For node 5: 2T5 = T4 + T6
For node 6. T6 = T5 – 0.100 Boundary node
𝒂𝑷 𝑻𝑷 = 𝒂𝑬 𝑻𝑬 + 𝒂𝑾 𝑻𝑾 + 𝒃
aiTi = biTi+1 + ciTi-1 + di i=1, 2, 3, ……. N
or
- ciTi-1 + aiTi - biTi+1 = di i=1, 2, 3, ……. N

- Ti-1 + 2Ti - Ti+1 = 0 i=2, 3, ……. N-1


As a matrix equation, we can write the above equation as

1 0 0 0 0 0 𝑇1 200
−1 2 − 1 0 0 0 𝑇2 0
NOTE: Both
0 −1 2 −1 0 0 𝑇3 0 sides of
0 0 −1 2 −1 0 𝑇4 0 equations for
0 0 0 −1 2 −1 𝑇5 = 0 inner nodes
… … divided by
…. …. 1000.

0 0 0 0 −1 1 𝑇6 −0.100

Step 4: Solution of algebraic equations: Solve the algebraic equations using TDMA

Summary of TDMA Algorithm


1) From Eq. (6), P1 and Q1 are calculated for i = 1 (left boundary node)
2) From Eq. (5), Pi and Qi are calculated for i = 2, 3, ….. N-1 (For inner nodes)
3) From Eq. (7), PN and QN are calculated for i = N and TN=QN is obtained (right
boundary)
4) From Eq. (2), starting from i=N-1, TN-1, TN-2, ……. T2 and T1 are calculated.
4 Algebraic Equation Solution
8
Methods
1 0 0 0 0 0 𝑇1 200
Forward Elimination −1 2 − 1 0 0 0 𝑇2 0
0 −1 2 −1 0 0 𝑇3 0
0 0 −1 2 −1 0 𝑇4 0
1) a1 = 1, c1 = 0, b1 = 0, T1 = 200 0 0 0 −1 2 −1 𝑇5 = 0
… …
…. ….
2) Calculate Pi and Qi for all grid nodes
0 0 0 0 −1 1 𝑇6 −0.100
𝒃𝒊 𝒅𝒊 +𝒄𝒊 𝑸𝒊−𝟏
𝑷𝒊 = 𝑸𝒊 = (5)
𝒂𝒊 − 𝒄𝒊 𝑷𝒊−𝟏 𝒂𝒊 −𝒄𝒊 𝑷𝒊−𝟏

𝒃𝟏 𝟎 𝒅𝟏 𝟐𝟎𝟎
For i = 1, c1 = 0 hence, 𝑷𝟏 = = =𝟎 𝑸𝟏 =
𝒂𝟏
= 𝟏 =200 (6)
𝒂𝟏 𝟏

𝑏2 1 1
For i=2 𝑃2 = = =
𝑎2 −𝑐2 𝑃2−1 2−(1)(0) 2

𝑑2 +𝑐2 𝑄2−1 0+ 1 200


𝑄2 = = 2− 1 0 = 66.6
𝑎2 −𝑐2 𝑃2−1
𝑏3 1
For i=3 𝑃3 = = = 0.75
𝑎3 −𝑐3 𝑃3−1 2−(1)(1/2)

𝑑3 +𝑐3 𝑄3−1 0+ 1 (66.6)


𝑄3 = = = 50
𝑎3 −𝑐3 𝑃3−1 2− 1 (0.5)

𝑏4 1
For i=4 𝑃4 = = = 0.8
𝑎4 −𝑐4 𝑃4−1 2−(1)(0.75)

𝑑4 +𝑐4 𝑄4−1 0+ 1 (50)


𝑄4 = = = 40
𝑎4 −𝑐4 𝑃4−1 2− 1 (0.75)

𝑏5 1
For i = 5 𝑃5 = = = 0.833
𝑎5 −𝑐5 𝑃5−1 2−(1)(0.8)

𝑑5 +𝑐5 𝑄5−1 0+ 1 (40)


𝑄5 = = = 33.33
𝑎5 −𝑐5 𝑃5−1 2− 1 (0.833)
𝑏5 0
For i = 6 𝑃6 = = =0
𝑎5 −𝑐5 𝑃5−1 2−(1)(0.83)

𝑑6 +𝑐6 𝑄6−1 0.1+ 1 (33.3)


𝑄6 = = = 190
𝑎6 −𝑐6 𝑃6−1 1− 1 (0.833)

4 Algebraic Equation Solution


9
Methods
Ti = PiTi+1 + Qi (2)
TN = T6 = 190

T5 =P5T6+Q5= 191.66

T4 =P4T5+Q4= 193.33

T3 = 195

T2 = 196.66

T1 = 200 oC (BC)

4 Algebraic Equation Solution


10
Methods
Gauss-Seidel Iterative Method
There are many iteration techniques. Among these, Gauss-Seidel technique is the one
used commonly since it is easy to use.

To apply Gauss-Seidel method,

1) An initial value is assumed for all unknows at all grid points. (Generally, initial
values are assumed as zero.)

2) From each equation, one unknown which has the highest coefficient is solved
using the values for other variables from the previous iteration (or the initial
values).

3) Repeat (iterate) the calculations using the updated values of the unknowns.

4) When the difference between the values of all unknowns in two subsequent
iterations is smaller than the convergence criteria assumed, iteration is
terminated.

Example:
4x1 – x2 + x3 = 4
x1 + 6x2 + x3 = 4 x1 = ?, x2 = ?, x3 = ?
- x1 + 2x2 + 5x3 = 4
Step 1: Assume initial values as zero for all unknowns.

Step 2: Solve one unknown from each equation


1 1 1
𝑥1 = 4 + 𝑥2 − 𝑥3 𝑥2 = 9 − 𝑥1 − 𝑥3 𝑥3 = 4 + 𝑥1 − 2𝑥2
4 6 5
Step 3: Repeat the calculations
Iteration 1:
1 1 1
𝑥1 = 4+0−0 = 1 𝑥2 = 9 − 1 − 0 = 1.33 𝑥3 = 4 + 1 − 1.33 = 0.73
4 6 5

Iteration 2:
1 1 1
𝑥1 = 4 + 1.33 − 0.73 = 1.15 𝑥2 = 6 9 − 1.15 − 0.73 = 1.19 𝑥3 = 5 4 + 1.15 − 1.19 = 0.79
4

Step 4: Check the convergence: Calculate the difference between values obtained in
two following iterations and compare them with the convergence criteria e chosen.

4 Algebraic Equation Solution


11
Methods
ÇANKAYA UNIVERSITY
MECHANICAL ENGINEERING DEPARTMENT

ME654 COMPUTATIONAL FLUID DYNAMICS


HOMEWORK 2

1) Consider 1-dimensional steady heat conduction in a rod. Total length of the rod
is 3 units. Everywhere in the rod thermal conductivity is k=1 and there is a heat
generation of S=2. At left end of the rod (at x=0) T=1 and at the right end of the
rod (at x=3), dT/dx =5 are given as the boundary conditions.
a) Consider grid points are located at x=0, 1, 2 and 3, derive the discretization
equations using both finite difference and control volume approaches.
b) Solve the discretization equation sets using both TDMA and Gauss-Seidel
iteration methods. (NOTE: Do not use a program.)
c) Compare the numerically obtained results with the analytical solution and
interpret.

2. Consider 1-dimensional steady heat conduction in a rod. Total length of the rod is
1 unit. Everywhere in the rod thermal conductivity is k=1 and there is a heat
generation of S=2. At left end of the rod (x=0) T=0 and at the right end of the rod
(x=1), dT/dx =1 are given as the boundary conditions. Using control volume
approach, derive the discretization equations considering 3, 5, 15 and 20 equal
control volumes. Solve the set of algebraic equations for all four grid systems and
compare the results with each other and with analytical solution. Show the results
on a graph and analyze the results and interpret the effect of the grid size on the
numerical results.

4 Algebraic Equation Solution


12
Methods

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy