Skip to contents

check_triu() and check_is_triu() are functions that check if an input is a valid upper triangular matrix. An upper triangular matrix is a square matrix where all elements below the main diagonal are zero. The check_triu() function raises an error if the input is not an upper triangular matrix, while check_is_triu() returns TRUE if the input is an upper triangular matrix and FALSE otherwise.

Usage

check_triu(mat, par_name = "mat")

check_is_triu(mat, par_name = "mat")

Arguments

mat

The matrix to check.

par_name

The name of the parameter to display in error messages.

Value

  • check_triu(): Returns the original mat if it is a valid upper triangular matrix. Raises an error message if mat is not a valid upper triangular matrix.

  • check_is_triu(): Logical value, TRUE if the matrix is a valid upper triangular matrix, and FALSE otherwise.

Examples

# Examples for check_triu()
# --------------------------
A <- matrix(c(1, 0, 0, 3, 4, 0, 5, 6, 7), 3, 3)
print(A)
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    0    4    6
#> [3,]    0    0    7
check_triu(A)
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    0    4    6
#> [3,]    0    0    7

B <- matrix(c(1, 2, 0, 3, 4, 0, 5, 6, 7), 3, 3)
try(check_triu(B))
#> Error in check_triu(B) : Expected 'mat' to be an upper triangular matrix.

# Examples for check_is_triu()
# ----------------------------

check_is_triu(A)
#> [1] TRUE

check_is_triu(B)
#> [1] FALSE