Notebook 11
Tridiagonal systems
In the previous lecture (nb10) we introudced the discretization matrix for the 1D heat conduction problem. In general form it can be written as a tridiagonal matrix
and stored in three arrays
Gaussian elimination using arrays
From what we have seen, this question arises in a quite natural way, and historically, the answer has been given several times and named differently
TDMA (tridiagonal matrix algorithm)
"Thomas algorithm" (Llewellyn H. Thomas, 1949 (?))
"Progonka method" (from Russian "прогонка": "run through"; Gelfand, Lokutsievski, 1952, published 1960)
Прогонка: derivation
Write solution of
where we define
For
, assume there are coefficients such that
.
Re-arranging, we can express
and via :
This is true for arbitrary
ifRe-arranging gives for
:
Прогонка: realization
Initialization of forward sweep:
Forward sweep: for
:
Initialization of backward sweep:
Backward sweep: for
:
Properties:
unknowns, one forward sweep, one backward sweep operations vs. for algorithm using full matrix No pivoting
possible stability issues Stability for diagonally dominant matrices (where
) Stability for symmetric positive definite matrices
In fact, this is a realization of Gaussian elimination on a particular data structure.
Tridiagonal matrices in Julia
In Julia, solution of a tridiagonal system is based on the LU factorization in the LAPACK routine dgtsv
which also does pivoting.
5
LU Factorization in the case of a tridiagonal matrix with random diagonal entries
5×5 Tridiagonal{Float64, Vector{Float64}}:
0.422241 0.810134 ⋅ ⋅ ⋅
0.695929 0.941789 0.690428 ⋅ ⋅
⋅ 0.596871 0.190061 0.95558 ⋅
⋅ ⋅ 0.290692 0.250277 0.263156
⋅ ⋅ ⋅ 0.124175 0.220931
LU{Float64, Tridiagonal{Float64, Vector{Float64}}}
L factor:
5×5 Matrix{Float64}:
1.0 0.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0 0.0
0.606731 0.399955 1.0 0.0 0.0
0.0 0.0 0.0 1.0 0.0
0.0 0.0 -0.587351 0.207751 1.0
U factor:
5×5 Matrix{Float64}:
0.695929 0.941789 0.690428 0.0 0.0
0.0 0.596871 0.190061 0.95558 0.0
0.0 0.0 -0.49492 -0.382189 0.0
0.0 0.0 0.0 0.124175 0.220931
0.0 0.0 0.0 0.0 0.217258
2
3
1
5
4
3.31506
-0.493445
-1.22
1.59735
3.62851
Solving this system with a positive right hand side can yield negative solution components.
We see that the in order to maintain stability, pivoting is performed: the LU factorization is performed as lu(A).p)
Define a diagonally dominant matrix with random entries with positive main diagonal and nonpositive off-diagonal elements:
5×5 Tridiagonal{Float64, Vector{Float64}}:
2.99421 -0.713217 ⋅ ⋅ ⋅
-0.0690588 2.51996 -0.316398 ⋅ ⋅
⋅ -0.635394 2.9221 -0.156421 ⋅
⋅ ⋅ -0.102088 2.8711 -0.592794
⋅ ⋅ ⋅ -0.107685 2.44815
LU{Float64, Tridiagonal{Float64, Vector{Float64}}}
L factor:
5×5 Matrix{Float64}:
1.0 0.0 0.0 0.0 0.0
-0.0230641 1.0 0.0 0.0 0.0
0.0 -0.253801 1.0 0.0 0.0
0.0 0.0 -0.0359235 1.0 0.0
0.0 0.0 0.0 -0.0375801 1.0
U factor:
5×5 Matrix{Float64}:
2.99421 -0.713217 0.0 0.0 0.0
0.0 2.50351 -0.316398 0.0 0.0
0.0 0.0 2.8418 -0.156421 0.0
0.0 0.0 0.0 2.86548 -0.592794
0.0 0.0 0.0 0.0 2.42588
1
2
3
4
5