A tridiagonal system has nonzeros only on the main diagonal and its two neighbours. Spline interpolation, implicit heat/diffusion steps and several smoothing problems all reduce to such systems. A dense solver wastes cubic time and quadratic memory on zeros; the Thomas algorithm is Gaussian elimination that skips every zero, so it runs in linear time using three short bands.
The elimination sweep depends only on the matrix, so it is performed once and reused: each new right-hand side costs two short sweeps and no division. This fits the common case where the matrix depends on fixed geometry (for example knot spacing) while the right-hand side changes per channel or per tick.
Let
Eliminating
The reciprocals
Division by
| Operation | Time | Space | Notes |
|---|---|---|---|
| Factorization |
|
||
| Solve (per RHS) | About |
||
| Dense LU, for contrast | Operates on all the zeros |
Storage is three bands of fixed capacity; nothing is allocated dynamically. Factoring once and solving
Take
| 0 | |||
| 1 | |||
| 2 | |||
| 3 | unused |
Right-hand side
Right-hand side
Verify: row 1 of
-
No pivoting. The algorithm is stable when
$A$ is strictly diagonally dominant ($|b_k| > |a_k| + |c_k|$ ) or symmetric positive-definite; spline systems are both. For other tridiagonal matrices a zero or tiny pivot can appear even when$A$ is nonsingular, and growth can destroy accuracy. Use LU decomposition with partial pivoting instead. -
Vanishing pivot. If
$|p_k| \le \varepsilon \cdot s$ , where$\varepsilon$ is the machine epsilon and$s$ is the largest absolute entry among the$n$ rows, the factorization reports failure instead of dividing. The relative threshold keeps the test meaningful regardless of the matrix's scale. -
Size limits. A size of zero or one exceeding the compile-time capacity is rejected. Entries of the solution beyond
$n$ are zero. - Failed factorization. A solve is only meaningful after a successful factorization; refactor whenever the matrix changes.
- Floating-point only. Reciprocals and the epsilon test have no meaning for integer types.
- Cyclic tridiagonal. Periodic boundary conditions add corner entries; the Sherman–Morrison formula reduces the solve to two tridiagonal solves.
- Block tridiagonal. Scalar pivots become small dense blocks, as in implicit multi-variable PDE steps.
-
Symmetric case. When
$a_k = c_{k-1}$ , one band can be dropped and the factorization becomes$LDL^T$ . - Parallel variants. Cyclic reduction trades extra work for parallelism; irrelevant on a single embedded core.
- Cubic spline interpolation — the second-derivative system at the knots is tridiagonal and diagonally dominant.
- Implicit finite differences — backward-Euler and Crank–Nicolson steps for 1-D heat and diffusion equations.
- Smoothing — penalized least-squares smoothers produce banded normal equations.
| Algorithm | Relationship |
|---|---|
| LU Decomposition | General fallback with partial pivoting; |
| Triangular Solve | Same forward/back substitution idea, applied to full triangular factors |
| Levinson–Durbin | Another structured solver, for Toeplitz systems |
| Cubic spline interpolation | Main consumer; plans the second derivatives by solving one tridiagonal system |
- Thomas, L. H., "Elliptic Problems in Linear Difference Equations over a Network", Watson Scientific Computing Laboratory, Columbia University, 1949.
- Golub, G. H. & Van Loan, C. F., Matrix Computations, 4th ed., Johns Hopkins University Press, 2013, §4.3.