Samiksha Jaiswal (Editor)

Tridiagonal matrix algorithm

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

In numerical linear algebra, the tridiagonal matrix algorithm, also known as the Thomas algorithm (named after Llewellyn Thomas), 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

Contents

a i x i 1 + b i x i + c i x i + 1 = d i ,

where a 1 = 0 and c n = 0 .

[ b 1 c 1 0 a 2 b 2 c 2 a 3 b 3 c n 1 0 a n b n ] [ x 1 x 2 x 3 x n ] = [ d 1 d 2 d 3 d n ] .

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. Examples of such matrices commonly arise from the discretization of 1D Poisson equation and natural cubic spline interpolation; similar systems of matrices arise in tight binding physics or nearest neighbor effects models.

Thomas' algorithm is not stable in general, but is so in several special cases, such as when the matrix is diagonally dominant (either by rows or columns) or symmetric positive definite; for a more precise characterization of stability of Thomas' algorithm, see Higham Theorem 9.12. If stability is required in the general case, Gaussian elimination with partial pivoting (GEPP) is recommended instead.

Method

The forward sweep consists of modifying the coefficients as follows, denoting the new coefficients with primes:

c i = { c i b i ; i = 1 c i b i a i c i 1 ; i = 2 , 3 , , n 1

and

d i = { d i b i ; i = 1 d i a i d i 1 b i a i c i 1 ; i = 2 , 3 , , n .

The solution is then obtained by back substitution:

x n = d n x i = d i c i x i + 1 ;   i = n 1 , n 2 , , 1.

Derivation

The derivation of the tridiagonal matrix algorithm is a special case of Gaussian elimination.

Suppose that the unknowns are x 1 , , x n , and that the equations to be solved are:

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 , , n 1 a n x n 1 + b n x n = d n ; i = n .

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

( equation 2 ) b 1 ( equation 1 ) 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

where the second equation immediately above is a simplified version of the equation immediately preceding it. 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 t h row; the (modified) n t h equation will involve only one unknown, x n . This may be solved for and then used to solve the ( n 1 ) t h 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:

a ~ i = 0 b ~ 1 = b 1 b ~ i = b i b ~ i 1 c ~ i 1 a i c ~ 1 = c 1 c ~ i = c i b ~ i 1 d ~ 1 = d 1 d ~ i = d i b ~ i 1 d ~ i 1 a i .

To further hasten the solution process, b ~ i may be divided out (if there's no division by zero risk), the newer modified coefficients, each notated with a prime, will be:

a i = 0 b i = 1 c 1 = c 1 b 1 c i = c i b i c i 1 a i d 1 = d 1 b 1 d i = 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:

x i + c i x i + 1 = d i ;   i = 1 , , n 1 x n = d n ;   i = n .

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 ;   i = n 1 , n 2 , , 1.

Variants

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

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 , i = 2 , , n 1 a n x n 1 + b n x n + c n x 1 = d n .

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. The method requires solving a modified non-cyclic version of the system for both the input and a sparse corrective vector, and then combining the solutions. This can be done efficiently if both solutions are computed at once, as the forward portion of the pure tridiagonal matrix algorithm can be shared.

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.

The textbook Numerical Mathematics by Quarteroni, Sacco and Saleri, lists a modified version of the algorithm which avoids some of the divisions (using instead multiplications), which is beneficial on some computer architectures.

References

Tridiagonal matrix algorithm Wikipedia