Skip to content

istril

Determine if a matrix is lower triangular

istril(A)

  • A is an array, which can be real or complex.
  • If all elements above the main diagonal of A are zeros, it returns logical 1.
  • When A is complex, it returns logical 1 if both istril(imag(A)) and istril(real(A)) are true.
  • If A is empty, it returns logical 1.

Example 1:

% istril gives 1 for the following matrices
a=zeros(3,4)
istril(a)

a=tril(rand(4))
istril(a)

a=[tril(rand(4)) zeros(4,1)]
istril(a)

a=diag(rand(1,4))
istril(a)

% istril gives 0 for the following matrix
a=[tril(rand(4)) ones(4,1)]
istril(a)
a =
0.000   0.000   0.000   0.000
0.000   0.000   0.000   0.000
0.000   0.000   0.000   0.000

ans =
1

a = 1e-1 ×
4.264   0.000   0.000   0.000
6.225   9.057   0.000   0.000
7.274   3.004   5.663   0.000
5.344   0.452   9.985   0.809

ans =
1

a = 1e-1 ×
1.709   0.000   0.000   0.000   0.000
3.571   7.196   0.000   0.000   0.000
2.342   2.499   1.930   0.000   0.000
4.830   8.098   1.317   7.979   0.000

ans =
1

a = 1e-1 ×
1.932   0.000   0.000   0.000
0.000   2.348   0.000   0.000
0.000   0.000   7.679   0.000
0.000   0.000   0.000   9.524

ans =
1

a =
0.551   0.000   0.000   0.000   1.000
0.572   0.871   0.000   0.000   1.000
0.840   0.800   0.046   0.000   1.000
0.018   0.968   0.395   0.093   1.000

ans =
0