isTriangular-methods function

Test whether a Matrix is Triangular or Diagonal

Test whether a Matrix is Triangular or Diagonal

isTriangular and isDiagonal test whether their argument is a triangular or diagonal matrix, respectively. Unlike the analogous isSymmetric, these two functions are generically from Matrix rather than base. Hence Matrix

defines methods for traditional matrices of implicit class

"matrix" in addition to matrices inheriting from virtual class "Matrix".

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

methods

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

Arguments

  • object: an object, typically a matrix.
  • upper: a logical , either TRUE or FALSE, in which case TRUE is returned only for upper or lower triangular object; or otherwise NA (the default), in which case TRUE is returned for any triangular object.
  • ...: further arguments passed to methods (currently unused by Matrix).

Returns

A logical , either TRUE or FALSE

(never NA).

If object is triangular and upper is NA, then isTriangular returns TRUE with an attribute

kind, either "U" or "L", indicating that object is u pper or l ower triangular, respectively. Users should not rely on how kind is determined for diagonal matrices, which are both upper and lower triangular.

See Also

isSymmetric; virtual classes "triangularMatrix" and "diagonalMatrix" and their subclasses.

Examples

isTriangular(Diagonal(4)) ## 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, "generalMatrix")) # still triangular, even if not "formally" isTriangular(crossprod(M)) # FALSE isDiagonal(matrix(c(2,0,0,1), 2,2)) # TRUE ## Look at implementations: showMethods("isTriangular", includeDefs = TRUE) showMethods("isDiagonal", includeDefs = TRUE)
  • Maintainer: Martin Maechler
  • License: GPL (>= 2) | file LICENCE
  • Last published: 2025-03-11