isTriangular {Matrix}R Documentation

isTriangular() and isDiagonal() Checking if Matrix is Triangular or Diagonal


isTriangular(M) returns a logical indicating if M is a triangular matrix. Analogously, isDiagonal(M) is true iff M is a diagonal matrix.

Contrary to isSymmetric(), these two functions are generically from package Matrix, and hence also define methods for traditional (class "matrix") matrices.

By our definition, triangular, diagonal and symmetric matrices are all square, i.e. have the same number of rows and columns.



isTriangular(object, upper = NA, ...)



any R object, typically a matrix (traditional or Matrix package).


logical, one of NA (default), FALSE, or TRUE where the last two cases require a lower or upper triangular object to result in TRUE.


potentially further arguments for other methods.


a (“scalar”) logical, TRUE or FALSE, never NA. For isTriangular(), if the result is TRUE, it may contain an attribute (see attributes "kind", either "L" or "U" indicating if it is a lower or upper triangular matrix.

See Also

isSymmetric; formal class (and subclasses) "triangularMatrix" and "diagonalMatrix".


## is TRUE: a diagonal matrix is also (both upper and lower) triangular
(M <- Matrix(c(1,2,0,1), 2,2))
isTriangular(M) # TRUE (*and* of formal class "dtrMatrix")
isTriangular(as(M, "dgeMatrix")) # still triangular, even if not "formally"
isTriangular(crossprod(M)) # FALSE

isDiagonal(matrix(c(2,0,0,1), 2,2)) # TRUE

[Package Matrix version 1.4-1 Index]