Tridiagonal Matrix Algorithm: A. Salih
Tridiagonal Matrix Algorithm: A. Salih
A. Salih
Department of Aerospace Engineering
Indian Institute of Space Science and Technology, Thiruvananthapuram
October 2010
A system of simultaneous algebraic equations with nonzero coefficients only on the main
diagonal, the lower diagonal, and the upper diagonal is called a tridiagonal system of equations.
Consider a tridiagonal system of N equations with N unknowns, u1 , u2 , u3 , uN as given below:
b1 c1 u1 d1
a2 b2 c2 u2 d2
a3 b3 c3
u3
d3
... ..
= ..
. . (1)
.. ..
...
. .
aN1 bN1 cN1 uN1 dN1
aN bN uN dN
A standard method for solving a system of linear, algebraic equations is gaussian elimination.
Thomas algorithm, also called TriDiagonal Matrix Algorithm (TDMA) is essentially the result
of applying gaussian elimination to the tridiagonal system of equations.
The ith equation in the system may be written as
where a1 = 0 and cN = 0. Looking at the system of equations, we see that ith unknown can be
expressed as a function of (i + 1)th unknown. That is
ui = Pi ui+1 + Qi (3)
ui1 = Pi1 ui + Qi1 (4)
where Pi and Qi are constants. Note that if all the equations in the system are expressed in this
fashion, the coefficient matrix of the system would transform to a an upper triangular matrix.
To determine the constants Pi and Qi , we plug equation (4) in (2) to yield
or
(bi + ai Pi1 ) ui + ci ui+1 = di ai Qi1
or
ci di ai Qi1
ui = ui+1 + (5)
bi + ai Pi1 bi + ai Pi1
1
Comparing equations (3) and (5), we obtain
ci di ai Qi1
Pi = Qi = (6)
bi + ai Pi1 bi + ai Pi1
These are the recurring relations for the constants P and Q. It shows that Pi can be calculated
if Pi1 is known. To start the computation, we use the fact that a1 = 0. Now, P1 and Q1 can
be easily calculated because terms involving P0 and Q0 vanish. Therefore,
c1 d1
P1 = Q1 = (7)
b1 b1
Once the values of P1 and Q1 are known, we can use the recurring expressions for Pi and Qi for
all values of i.
Now, to start the back substitution, we use the fact that cN = 0. As a consequence, from
equation (6), we have PN = 0, which results in uN = QN . Once the value of uN is known we
use equation (3) to obtain uN1 , uN2 , u1 .
A Fortran implementation
The following Fortran code will solve a general tridiagonal system. Note that n is the number
of unknowns.
program TDMA
implicit doubleprecision(a-h,o-z)
parameter (nd = 100)
doubleprecision A(nd), B(nd), C(nd), D(nd), X(nd), P(0:nd), Q(0:nd)
c
A(1) = 0
C(n) = 0
c
c forward elimination
do i = 1, n
denom = B(i) + A(i)P(i1)
P(i) = C(i) /denom
Q(i) = (D(i) A(i)Q(i1)) /denom
enddo
c
c back substitution
do i = n, 1, 1
X(i) = P(i)X(i+1) + Q(i)
enddo
stop
end