The Thomas algorithm is a specialized form of Gaussian elimination for solving a tridiagonal matrix
system. For subdiagonal entries , diagonal entries
, superdiagonal entries
, and right-hand side
, set
and
. For
, ...,
, forward elimination computes
For ,
...,
,
it computes
Back substitution starts with and continues with
for
, ..., 1.
The algorithm requires only linear time and storage in the number of equations. Pivoting or a more general solver may be needed when an elimination denominator vanishes or is too small for stable floating-point computation.