R/is.diag.R

is.diag <- function (c, EPS=1e-12) {
  #  tests a matrix for being diagonal
  #  C   ... matrix to be tested
  #  EPS ... testing criterion: max off-diagonal element over min diagonal
  #          element must be less than EPS
  if (!is.matrix(c)) return(FALSE)
  cd <- dim(c)
  if (cd[1] != cd[2]) return(FALSE)
  mindg <- min(abs(diag(c)))
  maxodg <- max(abs(c - diag(diag(c))))
  if (maxodg/mindg < EPS) return(TRUE) else return(FALSE)
}

Try the fda package in your browser

Any scripts or data that you put into this service are public.

fda documentation built on May 31, 2023, 9:19 p.m.