- Tridiagonal matrix 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 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 1DPoisson 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.
Implementation in C#
Derivation
The derivation of the
tridiagonal matrix algorithm involves manually performing some specializedGaussian 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]
Wikimedia Foundation. 2010.