Learn R Programming

Matrix (version 1.0-1)

isTriangular: isTriangular() and isDiagonal() and Methods

Description

isTriangular(M) returns a logical indicating 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 Matrix package, and hence also define methods for traditional (class "matrix") matrices.

Usage

isDiagonal(object)

isTriangular(object, ...) ## S3 method for class 'CsparseMatrix': isTriangular(object, upper = NA)

Arguments

object
any Robject, typically a matrix (traditional or Matrix package).
upper
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.

Value

  • a (scalar) logical, TRUE or FALSE, never NA.

See Also

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

Examples

Run this code
isTriangular(Diagonal(4))
## is TRUE: a diagonl 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

Run the code above in your browser using DataLab