Professional Documents
Culture Documents
Lecture 5:
Solution to a System of Linear
Algebraic Equations
Instructor: Samah Alghoul
Outlines
➢Direct Solver:
▪ Gaussian Elimination
➢Iterative Solvers
➢Gauss Jacobi
Importance!
› linear algebraic equations arising out of discretization of a differential
equation, have two key attributes:
1. the coefficient is sparse and, often, banded,
2. the coefficient matrix is large.
1. Forward elimination
2. Backward substitution
Traiangular
Upper
Matrix
ME 626 ADVANCED NUMERICAL METHODS 7/6/2019 11
Direct Solvers - Gaussian Elimination
nlong ~ K3
Nlong ~ K2
Number of Operations
Number of Operations
19
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -260.6
2 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 -146.1
3 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 -130.3
4 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 -114.5
5 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0
6 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 -146.1
7 0 0 0 0 0 0 -64 16 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1569.1
8 0 0 0 0 0 0 0 -60 16 0 0 4 16 0 0 0 0 0 0 0 0 0 0 0 0 8 924.24
9 0 0 0 0 0 0 0 0 -60 16 0 1.07 4.27 16 0 0 0 0 0 0 0 0 0 0 0 9 2078.2
10 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 114.49
11 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 -130.3
12 0 0 0 0 0 0 0 0 0 0 0 -60 17.1 0.29 0 0 16 0 0 0 0 0 0 0 0 12 990.26
13 0 0 0 0 0 0 0 0 0 0 0 0 -55 17.2 0 0 4.59 16 0 0 0 0 0 0 0 13 548.35
14 0 0 0 0 0 0 0 0 0 0 0 0 0 -54 16 0 1.53 5.06 16 0 0 0 0 0 0 14 1796.5
15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 15 130.27
16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 16 -114.5
17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -59 17.5 0.45 0 0 16 0 0 0 17 2135.2
18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -54 17.6 0 0 4.72 16 0 0 18 2316.5
19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -53 16 0 1.67 5.25 16 0 19 3796.8
20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 20 146.06
21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 21 0
22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 22 114.49
23 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 23 130.27
24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 24 146.06
25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 25 260.55
1000
500
0
0 1000 2000 3000 4000 5000 6000
Number of equtions
› Memory Issues
› For example, if a 3D computation with just 40 nodes in each direction,
– Number of nodes = number of equations = K = 403 = 64,000.
– a coefficient matrix of size K 2 ≈ 4 × 109 , i.e., 4 billion real numbers.
– If double precision is used, the memory required to store them would be
4 × 109 x 8 = 32 billion bytes = 32 GB RAM
– Which is beyond the scope of a modern-day computer unless parallel
computing is employed.
– problems of practical interest require far more than 64,000 nodes,
implying that from a memory requirement standpoint, Gaussian
elimination is.
1. Processing Time.
▪ The method takes very long time due to long operations included.
2. Approximation issues
▪ It would produce acceptable results if A’s in a given row are within
several orders of magnitude variation.
3. Memory Issue.
▪ The coefficient matrix is of size K × K, the memory necessary to store
this matrix can quickly grow.
ME 626 ADVANCED NUMERICAL METHODS 7/6/2019 26
Banded Linear System
Solvers
Direct Solvers - Banded Linear System Solvers
› Importance!
▪ It treats a zero as any other real number, and multiplications by zero are
as time consuming as multiplications by nonzeroes.
▪ An approach to store only the nonzeroes and their locations in the matrix
where they are situated, will reduce the memory usage significantly.
› Number of Operations
› In previous example, for a 64,000-node mesh, the real number storage will
reduce dramatically from 64,0002 to at most 64,000×7, assuming a 3D mesh
is being used along with a second-order central difference scheme.
› Not storing the zeroes will also improve computational efficiency
dramatically. This is because multiplications by zeroes will not be performed
in the first place.
› Which discretized as
Superdiagonal
Tridiagonal
matrix
Subdiagonal
Central diagonal
ME 626 ADVANCED NUMERICAL METHODS 7/6/2019 32
Direct Solvers - Banded Linear System Solvers
› First, instead of storing the full [A] matrix, only the three diagonals are
stored in the following form:
› At the end of this process, the new coefficient matrix will assume an
upper triangular shape with only two diagonals.
Nlong ~ 3(N-1)
Nlong ~ 2(N-1)
Nlong ~ N
› When the diagonals are clustered in the middle, the forward elimination phase
of the Gaussian elimination algorithm retains only the five diagonals, and no
nonzero elements are generated beyond the two upper diagonals.
› When the diagonals are not clustered, the entire upper triangle gets populated
with nonzeroes once the forward elimination phase has been completed.
› This implies that in the latter case, simply allocating memory for the five
diagonals is not sufficient.
› Due to this reason, the five-banded matrices arising out of discretization of a
2D PDE is generally not referred to as a pentadiagonal matrix. The term
pentadiagonal is only reserved for matrices in which all five diagonals are
clustered in the middle.
Nlong ~ 8(N-1)
Nlong ~ N
Nlong ~ 3(N-1)
Convergence,
› Is the process of the solution approaching the exact numerical
solution with successive iterations.
› Convergence error: the error between the exact numerical solution
and the partially converged solution.
› The only way to eliminate convergence error is to continue the
iteration until machine accuracy has been reached.
› This means that the convergence error is comparable with the round-
off error, and further iterations will simply make the solution oscillate.
– and
› matrices which obey the criteria shown are known as diagonally dominant.
› Diagonal dominance is sufficient but not necessary condition.
ME 626 ADVANCED NUMERICAL METHODS 7/6/2019 47
Residual and Correction
Form of Equations
48
The Residual and Correction Form of Equations
› Discretized Poisson in 2D
› By comparing,
› Let us now consider a case, where starting from the nth iteration
(previous), we are trying to find the solution at the (n+ 1)th iteration
(current).
› Therefore, for the (n+ 1)th iteration, we may write
› Let the change (or correction) in the value of from the previous to
the current iteration be denoted by ’.
› Substitution
› Rearranging, we get
› Then
correction form of the
algebraic equation
Grid Dependency
› The magnitude of the residual is also dependent on grid spacing and
the number of nodes.
› In order to remove problem dependency on the choice of the
prescribed tolerance, it is preferable to monitor the normalized
residual rather than the raw residual.
› The normalized residual is computed as follows:
› If the prescribed tolerance is now applied to R2* rather than R2, the
convergence criterion becomes problem independent.
› For example, in the scenario discussed in the preceding paragraph, if
εtol = 10-6, in both cases, the residual would be reduced by 6 orders of
magnitude, and the corresponding dimensional temperatures would
be accurate in the 3rd decimal place.
› On account of its generality, the scaled or normalized residual
method is used routinely for monitoring convergence in general-
purpose codes for solving linear systems.
› Step 3: Compute the residual vector using φ(n+ 1), and then compute
R2(n + 1).
› Step 4: Monitor convergence, i.e., check if R2( n+1) < εtol ? If YES, then
go to Step 7. If NO, then go to Step 5.
› Step 6: Go to Step 2.
Number of Operations
› In the above algorithm, every iteration requires 10 long operations per
node – 5 in the update formula, and 5 in the computation of the
residual.
› For K nodes, this amounts to 10K long operations.
› In addition, there are approximately K long operations in the
computation of R2, and one square-root operation.
› Assuming that the square-root operation counts as 2 long operations,
the total number of long operations is approximately 11K + 2 per
iteration.
16 17 18 19 20
11 12 13 14 15
6 7 8 9 10
1 2 3 4 5