is.diag: Diagonal Matrix

Description Usage Arguments Details Value Author(s) References Examples

View source: R/is.R

Description

Checks if off-diagonal elements of a square matrix are all zeroes.

Usage

1
is.diag(X, tol = 1e-08, stop = FALSE)

Arguments

X

Square numeric matrix.

tol

Numeric. Tolerance.

stop

Logical. If TRUE, stops and returns an error if X is not a diagonal matrix. If FALSE, returns the result of the test.

Details

The off-diagonal elements are added and compared to a tolerance value. If the sum is less than or equal to the tolerance value, all the elements are assumed to be zeroes.

Value

If stop = FALSE, returns TRUE, if the sum of the off-diagonal elements of X is equal to zero, or returns FALSE, if the sum of the off-diagonal elements of X is NOT equal to zero.

Author(s)

Ivan Jacob Agaloos Pesigan

References

Wikipedia: Diagonal matrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
A <- matrix(
  data = 1:9,
  nrow = 3
)
B <- matrix(
  data = 1:10,
  ncol = 2
)
C <- diag(3)
# Returns TRUE
is.diag(X = C)
# Returns FALSE
is.diag(X = A)
is.diag(X = B)

jeksterslabds/jeksterslabRmatrix documentation built on Aug. 4, 2020, 5:18 a.m.