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 for "n" unknowns may be written as
:where and . In matrix form, this system is written as
For such systems, the solution can be obtained in operations instead of required by Gaussian elimination. A first sweep eliminates the 's, and then an (abbreviated) backward substitution produces the solution. Example of such matrices commonly arise from the discretization of 1D Poisson equation (e.g., the 1D diffusion problem).
Method
The first step consists of modifying the coefficients as follows, denoting the new modified coefficients with primes:
:
:
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 here is zero based, in other words where 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 n){ int i;
/* Modify the coefficients. */ c [0] /= b [0] ; /* Division by zero risk. */ d [0] /= b [0] ; for(i = 1; i < n; i++){ double id = 1.0/(b [i] - c [i - 1] *a [i] ); /* Division by zero risk. */ c [i] *= id; /* Last value calculated is redundant. */ d [i] = (d [i] - d [i - 1] *a [i] )*id; }
/* Now back substitute. */ x [n - 1] = d [n - 1] ; for(i = n - 2; i >= 0; i--) x [i] = d [i] - c [i] *x [i + 1] ;}
Implementation in C#
double [] TDMASolve(double [] a, double [] b, double [] c, double [] d) { double [] cc = new double [c.Length] ; double [] dd = new double [d.Length] ;
double [] x = new double [f.Length] ; int N = d.Length; cc [0] = c [0] / b [0] ; dd [0] = d [0] / b [0] ; for (int i = 1; i < N; i++) { double m = b [i] - cc [i - 1] * a [i] ; cc [i] = c [i] / m; dd [i] = (d [i] - dd [i - 1] * a [i] ) / m; } x [N - 1] = d [N - 1] ; for (int i = N - 2; i >= 0; i--) { x [i] = dd [i - 1] - cc [i - 1] * x [i + 1] ; } return x; }
Derivation
The derivation of the tridiagonal matrix algorithm involves manually performing some specialized Gaussian elimination in a generic manner.
Suppose that the unknowns are , and that the equations to be solved are:
:
Consider modifying the second () equation with the first equation as follows:
:
which would give:
:
:
and the effect is that has been eliminated from the second equation. Using a similar tactic with the modified second equation on the third equation yields:
:
:
This time was eliminated. If this procedure is repeated until the row; the (modified) equation will involve only one unknown, . This may be solved for and then used to solve the equation, and so on until all of the unknowns are solved for.
Clearly, the coefficients on the modified equations get more and more complicated if stated explicitly. By examining the procedure, the modified coefficients (notated with tildes) may instead be defined recursively:
:
::
::
::
To further hasten the solution process, may be divided out (if there's no division by zero risk), the newer modified coefficients notated with an asterisk will be:
:
:
::
::
This gives the following system with the same unknowns and coefficients defined in terms of the original ones above:
:
The last equation involves only one unknown. Solving it in turn reduces the next last equation to one unknown, so that this backward substitution can be used to find all of the unknowns:
:
:
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.
A variant of the Thomas algorithm is the Hu-Gallash algorithm, which uses forward substitution instead of backwards substitution.
References
*cite book|author=Conte, S.D., and deBoor, C.|year=1972|title=Elementary Numerical Analysis|publisher= McGraw-Hill, New York. *CFDWiki|name=Tridiagonal matrix algorithm — TDMA (Thomas algorithm)
External links
* [http://www.arbredeslemuriens.com/Categorie.php?IDCategorie=AlgoScilab&IDTitre=182 Thomas algorithm — SCILAB] * [http://www.arbredeslemuriens.com/Categorie.php?IDCategorie=AlgoScilab&IDTitre=185 Thomas algorithm for tridiagonal superior periodic matrix — SCILAB]
Tridiagonal matrix — In linear algebra, a tridiagonal matrix is a matrix that is almost a diagonal matrix. To be exact: a tridiagonal matrix has nonzero elements only in the main diagonal, the first diagonal below this, and the first diagonal above the main… … Wikipedia
Divide-and-conquer eigenvalue algorithm — Divide and conquer eigenvalue algorithms are a class of eigenvalue algorithms for Hermitian or real symmetric matrices that have recently (circa 1990s) become competitive in terms of stability and efficiency with more traditional algorithms such… … Wikipedia
Lanczos algorithm — The Lanczos algorithm is an iterative algorithm invented by Cornelius Lanczos that is an adaptation of power methods to find eigenvalues and eigenvectors of a square matrix or the singular value decomposition of a rectangular matrix. It is… … Wikipedia
Block matrix — In the mathematical discipline of matrix theory, a block matrix or a partitioned matrix is a matrix broken into sections called blocks. Looking at it another way, the matrix is written in terms of smaller matrices.[1] We group the rows and… … Wikipedia
QR algorithm — In numerical linear algebra, the QR algorithm is an eigenvalue algorithm; that is, a procedure to calculate the eigenvalues and eigenvectors of a matrix. The QR transformation was developed in 1961 by John G.F. Francis (England) and by Vera N.… … Wikipedia
Band matrix — In mathematics, particularly matrix theory, a band matrix is a sparse matrix whose non zero entries are confined to a diagonal band, comprising the main diagonal and zero or more diagonals on either side. Contents 1 Matrix bandwidth 2… … Wikipedia
Sparse matrix — A sparse matrix obtained when solving a finite element problem in two dimensions. The non zero elements are shown in black. In the subfield of numerical analysis, a sparse matrix is a matrix populated primarily with zeros (Stoer Bulirsch 2002,… … Wikipedia
Triangular matrix — In the mathematical discipline of linear algebra, a triangular matrix is a special kind of square matrix where the entries either below or above the main diagonal are zero. Because matrix equations with triangular matrices are easier to solve… … Wikipedia
Eigenvalue algorithm — In linear algebra, one of the most important problems is designing efficient and stable algorithms for finding the eigenvalues of a matrix. These eigenvalue algorithms may also find eigenvectors. Contents 1 Characteristic polynomial 2 Power… … Wikipedia
Arrowhead matrix — In the mathematical field of linear algebra, an arrowhead matrix is a square matrix containing zeros in all entries except for the first row, first column, and main diagonal. [cite book |author=Stewart, G. W. |title=Matrix Algorithms… … Wikipedia