tril
Lower triangular part of a matrix.
Category: Mathematics > Linear Algebra
Syntax
L = tril(A)
Keeps the main diagonal and everything below it; the rest becomes zero.
L = tril(A, k)
Keeps the elements on and below the k-th diagonal.
Description
tril(A) zeroes the elements above the main diagonal. With k = -1 the diagonal is removed as well, giving the strictly lower part, so A = tril(A,-1) + diag(diag(A)) + triu(A,1).
It is handy for building triangular systems and for extracting the part of a symmetric matrix that is stored once.
Input arguments
A- Matrix (any class).
k- Integer diagonal offset:
0is the main diagonal, positive values are above it, negative values below. Default0.
Output arguments
L- Matrix of the same size and class as
A.
Example
Lower part with offsets
A = magic(3);
tril(A)
tril(A, -1)
Output
ans = 3×3
8 0 0
3 5 0
4 9 2
ans = 3×3
0 0 0
3 0 0
4 9 0