The Thomas algorithm is Gaussian elimination specialized to a tridiagonal matrix: each row couples an unknown only to its immediate neighbours. Eliminating one unknown changes just the next diagonal entry and right-hand side. Provided all pivot elements are nonzero, a forward sweep followed by back substitution solves an -unknown linear system in time and storage, using Big O notation. Treating the same entries as a full matrix wastes the zeros: classical dense LU factorization and solve costs grow cubically for factorization and quadratically for storage.
A concrete reason to care is the Dirichlet Poisson solution by tridiagonal elimination: a three-point finite difference for the second derivative couples adjacent points on a mesh, producing precisely this tridiagonal matrix. The same structure occurs in one-dimensional Crank-Nicolson method calculations. NPTEL's archived Lecture 13 introduces the Thomas algorithm from that time-stepping problem and labels the procedure “Thomas algorithm (1949)”.[ref]
Let . Store the tridiagonal matrix by its diagonal , lower diagonal , and upper diagonal . The linear system is
with the nonexistent endpoint terms omitted. Initialize and . For , compute the elimination multiplier, modified pivot element, and modified right-hand side:
These recurrence relations apply the elementary row operation after the preceding row has already been reduced. The transformed linear system is an upper bidiagonal matrix:
Thus back substitution is especially short:
For , only remains. Check each pivot element before its first division, including before back substitution.
Figure 1.
Tridiagonal elimination preserves the narrow band: only one row and one diagonal coefficient change per step
. Details.
Equivalently, this constructs an LU decomposition with unit lower bidiagonal matrix , whose lower diagonal is , and upper bidiagonal matrix , whose diagonal is and upper diagonal is . The sweep is forward substitution in . There is no fill-in outside these bands when no rows are interchanged. LAPACK's DGTSV source uses these same coefficient and right-hand-side updates in its branch without row interchange.[ref]
Consider the original small Poisson equation example
Its exact solution is the quadratic polynomial . Use a uniform mesh with and three interior unknowns . The finite difference method replaces the negative second derivative by
Multiplying by and moving the prescribed Dirichlet boundary conditions to the right gives
The endpoint values contribute and to the first and last equations; they are not additional unknowns. The Thomas algorithm gives
and back substitution yields
All three values equal exactly: the centered finite difference for the second derivative is exact on a quadratic polynomial. This special nodal exactness does not assert exactness for arbitrary forcing or for the piecewise-linear curve joining the nodes.
Figure 1.
Exact quadratic Dirichlet Poisson solution and the three interior values recovered by tridiagonal elimination
. Details.
For any interior points with , the scaled tridiagonal matrix has and . Its pivot elements are : start at and use . All are positive. Interior rows have equality in diagonal dominance, so strict diagonal dominance is not the reason this example works. Instead it is a symmetric positive-definite matrix, since for a real vector with ,
Zero would force every neighbouring value equal and hence all values zero. This connects the boundary constraints directly to the safe pivots for tridiagonal elimination.
The displayed Thomas algorithm requires every modified pivot element to be nonzero in exact arithmetic. Nonzero original diagonal entries alone are insufficient: later pivot elements can vanish after elimination. Two useful sufficient contexts are a real symmetric positive-definite matrix, and strict diagonal dominance by rows:
For the symmetric positive-definite matrix case, elimination leaves positive-definite remaining blocks by the Schur complement, so each . Equivalently, the initial principal minors are positive, and with .
For strict diagonal dominance, a short induction shows . The first row gives . Assuming the preceding bound, the triangle inequality gives
In particular . These are structural guarantees against a zero pivot element, not universal bounds on forward error in floating-point arithmetic. A poorly conditioned linear system can still amplify roundoff error; numerical stability and the condition number must be distinguished.
An invertible matrix need not admit the unpivoted Thomas algorithm. For example,
Here and , but makes undefined. Interchanging the two equations instead gives the upper triangular matrix system , , solved immediately by back substitution. Even a nonzero first diagonal does not guarantee all later pivot elements: has determinant , yet .
For a general tridiagonal matrix, use a solver with partial pivoting when these structural guarantees are unavailable or a dangerously small pivot element occurs. Adjacent row interchanges can introduce a second upper diagonal, so a pivoted solver must track that additional fill-in; it cannot blindly continue the unpivoted recurrence relations. LAPACK's DGTSV explicitly performs partial pivoting, stores this extra upper diagonal, and includes it in back substitution. Its fixed-width storage and bounded work per row retain time for one right-hand side and storage.[ref]
For the displayed unpivoted Thomas algorithm with one right-hand side, count each scalar addition, subtraction, multiplication or division as one arithmetic operation. Forming takes five arithmetic operations per forward step. The last unknown takes one division; each remaining back substitution step takes three arithmetic operations. Thus
This is an operation-count model, excluding assignments, indexing, pivot checks and any special simplifications of the coefficients. It is not a timing benchmark. The original tridiagonal matrix needs scalar entries, and its right-hand side another . Overwriting with and with , then with , keeps storage ; the arrays, rather than the few loop temporaries, determine the total space complexity.
For repeated right-hand sides, retain the LU decomposition: computing once costs arithmetic operations, and each subsequent pair of forward substitution and back substitution sweeps costs . Hence right-hand sides cost arithmetic operations. This is the banded counterpart of Reusing LU factors for multiple right-hand sides.

Articles by others on the same topic (1)

The Tridiagonal Matrix Algorithm (TDMA), also known as the Thomas algorithm, is a specialized algorithm used for solving systems of linear equations where the coefficient matrix is tridiagonal. A tridiagonal matrix is a matrix that has non-zero entries only on its main diagonal, and the diagonals directly above and below it.