Edit or run this notebook
Scientific Computing TU Berlin Winter 2021/22 © Jürgen Fuhrmann
Notebook 11
1.4 ms
4.5 ms
6.5 ms

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 A=(b1c1a2b2c2a3b3cn1aNbN)

and stored in three arrays a,b,c.

7.1 μs

Gaussian elimination using arrays a,b,c as matrix storage ?

  • 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)

2.4 ms

Прогонка: derivation

Write solution of Au=f as

aiui1+biui+ciui+1=fi(i=1N)

where we define a1=0, cN=0.

  • For i=1N1, assume there are coefficients αi,βi such that

ui=αi+1ui+1+βi+1

.

  • Re-arranging, we can express ui1 and ui via ui+1:

(aiαiαi+1+biαi+1+ci)ui+1+(aiαiβi+1+aiβi+biβi+1fi)=0

  • This is true for arbitrary u if {aiαiαi+1+biαi+1+ci=0aiαiβi+1+aiβi+biβi+1fi=0

  • Re-arranging gives for i=1N1:

{αi+1=ciaiαi+biβi+1=fiaiβiaiαi+bi

15.4 μs

Прогонка: realization

  • Initialization of forward sweep:

{α2=c1b1β2=fib1

  • Forward sweep: for i=2N1:

{αi+1=ciaiαi+biβi+1=fiaiβiaiαi+bi

  • Initialization of backward sweep: uN=fNaNβNaNαN+bN

  • Backward sweep: for i=N11:

ui=αi+1ui+1+βi+1

12.6 μs

Properties:

  • N unknowns, one forward sweep, one backward sweep O(N) operations vs. O(N2.75) for algorithm using full matrix

  • No pivoting possible stability issues

  • Stability for diagonally dominant matrices (where |bi|>|ai|+|ci|)

  • Stability for symmetric positive definite matrices

  • In fact, this is a realization of Gaussian elimination on a particular data structure.

165 ms

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.

3.9 μs
N
5
68 ns
  • LU Factorization in the case of a tridiagonal matrix with random diagonal entries

7.3 μs
A
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
4.6 μs
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
3.5 μs
2.7 μs
4.1 μs

Solving this system with a positive right hand side can yield negative solution components.

2.2 μs

We see that the in order to maintain stability, pivoting is performed: the LU factorization is performed as PA=LU where P is a permutation matrix. The underlying permutation can be obtained as lu(A).p)

2.8 μs
  • Define a diagonally dominant matrix with random entries with positive main diagonal and nonpositive off-diagonal elements:

3.8 μs
A1
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
39.6 ms
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
2.4 μs
4.3 μs
Loading...
ii