You are on page 1of 3

# Tridiagonal matrix algorithm - Wikipedia, the free encyclopedia

Page 1 of 3

## us improve Wikipedia by supporting it financially.

TridiagonalHelpmatrix
algorithm

The tridiagonal matrix algorithm (TDMA), also known as the Thomas algorithm, is a simplified
form of Gaussian elimination that can be used to solve tridiagonal systems of equations. A
tridiagonal system may be written as

where

and

## . In matrix form, this system is written as

For such systems, the solution can be obtained in O(n) operations instead of O(n3) required by
Gaussian elimination. A first sweep eliminates the ai's, and then an (abbreviated) backward
substitution produces the solution. Example of such matrices commonly arise from the discretization
of 1D problems (e.g. the 1D Poisson problem).

Contents

1 Method
1.1 Implementation in C
2 Variants
3 References

Method
See the derivation.
The first step consists of modifying the coefficients as follows, denoting the new modified
coefficients with primes:

http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm

10/6/2007

## Tridiagonal matrix algorithm - Wikipedia, the free encyclopedia

Page 2 of 3

This is the forward sweep. The solution is then obtained by back substitution:

Implementation in C
The following C function will solve a general tridiagonal system. Note that the index i here is zero
based, in other words
where n is the number of unknowns.
//Fills solution into x. Warning: will modify c and d!
void TridiagonalSolve(const double *a, const double *b, double *c, double *d, double *x, unsigned int
int i;
//Modify the coefficients.
c[0] = c[0]/b[0];
d[0] = d[0]/b[0];
double id;
for(i = 1; i != n; i++){
id = 1.0/(b[i] - c[i - 1]*a[i]);
c[i] = c[i]*id;
d[i] = (d[i] - a[i]*d[i - 1])*id;
}

## //Division by zero risk.

//Last value calculated is redundant.

## //Now back substitute.

x[n - 1] = d[n - 1];
for(i = n - 2; i != -1; i--)
x[i] = d[i] - c[i]*x[i + 1];
}

Variants
In some situations, particularly those involving periodic boundary conditions, a slightly perturbed
form of the tridiagonal system may need to be solved:

In this case, we can make use of the Sherman-Morrison formula to avoid the additional operations of
Gaussian elimination and still use the Thomas algorithm.
In other situations, the system of equations may be block tridiagonal (see block matrix), with
smaller submatrices arranged as the individual elements in the above matrix system(e.g. the 2D
Poisson problem). Simplified forms of Gaussian elimination have been developed for these
situations.

References

http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm

10/6/2007

## Tridiagonal matrix algorithm - Wikipedia, the free encyclopedia

Page 3 of 3

Conte, S.D., and deBoor, C. (1972). Elementary Numerical Analysis. McGraw-Hill, New
York..
This article incorporates text from the article matrix algorithm - TDMA (Thomas algorithm)
Tridiagonal matrix algorithm - TDMA (Thomas algorithm) (http://www.cfdonline.com/Wiki/Tridiagonal) on CFD-Wiki (http://www.cfd-online.com/Wiki/Main_Page)
that is under the GFDL license.

## Thomas algorithm - SCILAB (http://www.arbredeslemuriens.com/Categorie.php?

IDCategorie=AlgoScilab&IDTitre=182)

## Thomas algorithm for tridiagonal superior periodic matrix - SCILAB

(http://www.arbredeslemuriens.com/Categorie.php?IDCategorie=AlgoScilab&IDTitre=185)
Category: Numerical linear algebra