Tridiagonal matrix algorithm

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

:a_i x_{i - 1} + b_i x_i + c_i x_{i + 1} = d_i , ,!where a_1 = 0, and c_n = 0, . In matrix form, this system is written as left [ egin{matrix} {b_1} & {c_1} & { } & { } & { 0 } \ {a_2} & {b_2} & {c_2} & { } & { } \ { } & {a_3} & {b_3} & cdot & { } \ { } & { } & cdot & cdot & {c_{n-1\ { 0 } & { } & { } & {a_n} & {b_n}\ end{matrix} ight] left [ egin{matrix} {x_1 } \ {x_2 } \ cdot \ cdot \ {x_n } \end{matrix} ight] =left [ egin{matrix} {d_1 } \ {d_2 } \ cdot \ cdot \ {d_n } \end{matrix} ight] .

For such systems, the solution can be obtained in O(n) operations instead of O(n^3) required by Gaussian elimination. A first sweep eliminates the a_i'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:

:c'_i = egin{cases}egin{array}{lcl} cfrac{c_1}{b_1} & ; & i = 1 \ cfrac{c_i}{b_i - c'_{i - 1} a_i} & ; & i = 2, 3, dots, n - 1 \end{array}end{cases},

:d'_i = egin{cases}egin{array}{lcl} cfrac{d_1}{b_1} & ; & i = 1 \ cfrac{d_i - d'_{i - 1} a_i}{b_i - c'_{i - 1} a_i} & ; & i = 2, 3, dots, n \end{array}end{cases},

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

:x_n = d'_n,

:x_i = d'_i - c'_i x_{i + 1} qquad ; i = n - 1, n - 2, ldots, 1

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 i = 0, 1, dots, n - 1 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 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 x_1,ldots, x_n, and that the equations to be solved are:

:egin{align}b_1 x_1 + c_1 x_2 & = d_1;& i & = 1 \a_i x_{i - 1} + b_i x_i + c_i x_{i + 1} & = d_i;& i & = 2, ldots, n - 1 \a_n x_{n - 1} + b_n x_n & = d_n;& i & = nend{align}

Consider modifying the second (i = 2) equation with the first equation as follows:

:(mbox{equation 2}) cdot b_1 - (mbox{equation 1}) cdot a_2

which would give:

:(a_2 x_1 + b_2 x_2 + c_2 x_3) b_1 - (b_1 x_1 + c_1 x_2) a_2 = d_2 b_1 - d_1 a_2,

:(b_2 b_1 - c_1 a_2) x_2 + c_2 b_1 x_3 = d_2 b_1 - d_1 a_2,

and the effect is that x_1 has been eliminated from the second equation. Using a similar tactic with the modified second equation on the third equation yields:

:(a_3 x_2 + b_3 x_3 + c_3 x_4) (b_2 b_1 - c_1 a_2) -((b_2 b_1 - c_1 a_2) x_2 + c_2 b_1 x_3) a_3= d_3 (b_2 b_1 - c_1 a_2) - (d_2 b_1 - d_1 a_2) a_3,

:(b_3 (b_2 b_1 - c_1 a_2) - c_2 b_1 a_3 )x_3 + c_3 (b_2 b_1 - c_1 a_2) x_4= d_3 (b_2 b_1 - c_1 a_2) - (d_2 b_1 - d_1 a_2) a_3,

This time x_2 was eliminated. If this procedure is repeated until the n^{th} row; the (modified) n^{th} equation will involve only one unknown, x_n. This may be solved for and then used to solve the (n - 1)^{th} 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:

: ilde a_i = 0,

: ilde b_1 = b_1,: ilde b_i = b_i ilde b_{i - 1} - ilde c_{i - 1} a_i,

: ilde c_1 = c_1,: ilde c_i = c_i ilde b_{i - 1},

: ilde d_1 = d_1,: ilde d_i = d_i ilde b_{i - 1} - ilde d_{i - 1} a_i,

To further hasten the solution process, ilde b_i may be divided out (if there's no division by zero risk), the newer modified coefficients notated with an asterisk will be:

:a'_i = 0,

:b'_i = 1,

:c'_1 = frac{c_1}{b_1},:c'_i = frac{c_i}{b_i - c'_{i - 1} a_i},

:d'_1 = frac{d_1}{b_1},:d'_i = frac{d_i - d'_{i - 1} a_i}{b_i - c'_{i - 1} a_i},

This gives the following system with the same unknowns and coefficients defined in terms of the original ones above:

:egin{array}{lcl}x_i + c'_i x_{i + 1} = d'_i qquad &;& i = 1, ldots, n - 1 \x_n = d'_n qquad &;& i = n \end{array},

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:

:x_n = d'_n,

:x_i = d'_i - c'_i x_{i + 1} qquad ; i = n - 1, n - 2, ldots, 1

Variants

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

:egin{align}a_1 x_{n} + b_1 x_1 + c_1 x_2 & = d_1, \a_i x_{i - 1} + b_i x_i + c_i x_{i + 1} & = d_i,quadquad i = 2,ldots,n-1 \a_n x_{n-1} + b_n x_n + c_n x_1 & = d_n.end{align}

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 &mdash; TDMA (Thomas algorithm)

External links

* [http://www.arbredeslemuriens.com/Categorie.php?IDCategorie=AlgoScilab&IDTitre=182 Thomas algorithm &mdash; SCILAB]
* [http://www.arbredeslemuriens.com/Categorie.php?IDCategorie=AlgoScilab&IDTitre=185 Thomas algorithm for tridiagonal superior periodic matrix &mdash; SCILAB]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • 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

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”