check_tril()
and check_is_tril()
are functions that check if
an input is a valid lower triangular matrix. A lower triangular matrix is
a square matrix where all elements above the main diagonal are zero. The
check_tril()
function raises an error if the input is not a lower
triangular matrix, while check_is_tril()
returns TRUE
if the
input is a lower triangular matrix and FALSE
otherwise.
Value
check_tril()
: Returns the originalmat
if it is a valid lower triangular matrix. Raises an error message ifmat
is not a valid lower triangular matrix.check_is_tril()
: Logical value,TRUE
if the matrix is a valid lower triangular matrix, andFALSE
otherwise.
Examples
# Examples for check_tril()
# -------------------------
A <- matrix(c(1, 2, 3, 0, 4, 5, 0, 0, 6), 3, 3)
print(A)
#> [,1] [,2] [,3]
#> [1,] 1 0 0
#> [2,] 2 4 0
#> [3,] 3 5 6
check_tril(A)
#> [,1] [,2] [,3]
#> [1,] 1 0 0
#> [2,] 2 4 0
#> [3,] 3 5 6
B <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), 3, 3)
try(check_tril(B))
#> Error in check_tril(B) : Expected 'mat' to be a lower triangular matrix
# Examples for check_is_tril()
# ----------------------------
check_is_tril(A)
#> [1] TRUE
check_is_tril(B)
#> [1] FALSE