-
Notifications
You must be signed in to change notification settings - Fork 16
/
is_square.R
46 lines (42 loc) · 945 Bytes
/
is_square.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' Test for square matrix
#'
#' @param x A numeric matrix
#'
#' @return \code{TRUE} if \code{x} is a square matrix, else \code{FALSE}
#' @keywords internal
#' @rdname is_square
#' @export
#'
is_square_matrix <- function (x)
{
return(is.matrix(x) && nrow(x) == ncol(x))
}
#' Test for square, symmetric matrix
#'
#' @param x A numeric matrix
#'
#' @return \code{TRUE} if \code{x} is a square, symmetric matrix, else \code{FALSE}
#' @keywords internal
#' @export
#' @rdname is_square
#'
is_symmetric_matrix <- function (x)
{
tol <- 10*sqrt(.Machine$double.eps)
return (is_square_matrix(x) && all(abs(x - t(x)) < tol))
}
#' Test for orthogonal matrix
#'
#' @param x A numeric matrix
#'
#' @return \code{TRUE} if \code{x} is an orthogonal matrix, else \code{FALSE}
#'
#' @export
#' @rdname is_square
is_orthogonal_matrix <- function (x)
{
tol <- 10*sqrt(.Machine$double.eps)
xx <- crossprod(x)
diag(xx) <- 0
return(all(xx < tol))
}