tril
Tril is a matrix operation that returns the lower triangular part of a matrix, including the main diagonal, by zeroing out all elements above the diagonal. In many implementations, an optional offset parameter allows extending or shrinking the included diagonal band.
Mathematically, for a matrix A with entries aij, tril(A) yields a matrix B with bij = aij if
Example: for A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], tril(A) is [[1, 0, 0],
Common implementations and variants:
- MATLAB and Octave: tril(A) and tril(A, k) where k shifts the diagonal band.
- NumPy (Python): numpy.tril(a, k=0) returns the lower triangular portion with an optional offset k.
- R: base lower.tri returns a logical mask; tril can be formed by applying that mask to a
- Julia: tril(A, k=0) (and related syntax) provides the lower triangular part.
Applications include solving lower-triangular systems, constructing triangular factors in decompositions, and preparing matrices for algorithms that
See also: triu (the corresponding upper triangular operation), triangular matrices, LU decomposition.