Rev 75395 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/isSymmetric.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2025 R Core Team% Distributed under GPL 2 or later\name{isSymmetric}\alias{isSymmetric}\alias{isSymmetric.matrix}\title{Test if a Matrix or other Object is Symmetric (Hermitian)}\description{Generic function to test if \code{object} is symmetric or not.Currently only a matrix method is implemented, where a\code{\link{complex}} matrix \code{Z} must be \dQuote{Hermitian} for\code{isSymmetric(Z)} to be true, and(since \R >= 4.5.0),\code{isSymmetric(Z, trans = "T")} checks for \dQuote{simple} symmetry.}\usage{isSymmetric(object, \dots)\method{isSymmetric}{matrix}(object, tol = 100 * .Machine$double.eps,tol1 = 8 * tol, trans = "C", \dots)}\arguments{\item{object}{any \R object; a \code{\link{matrix}} for the matrix method.}\item{tol}{numeric scalar >= 0. Smaller differences are notconsidered, see \code{\link{all.equal.numeric}}.}\item{tol1}{numeric scalar >= 0. \code{isSymmetric.matrix()}\sQuote{pre-tests} the first and last few rows for fast detection of\sQuote{obviously} asymmetric cases with this tolerance. Setting itto length zero will skip the pre-tests.}\item{trans}{a single \code{\link{character}}, only relevant for a\code{\link{complex}} matrix \code{Z}: if it is \code{"C"} (as bydefault), \code{Conj(t(Z))} must be the same as \code{Z} whereasotherwise (typically it is \code{"T"}) \code{t(Z)} must equal\code{Z}. The argument name is inherited from LAPACK.}\item{\dots}{further arguments passed to methods; the matrix methodpasses these to \code{\link{all.equal}}. If the row and columnnames of \code{object} are allowed to differ for the symmetry checkdo use \code{check.attributes = FALSE}!}}\value{logical indicating if \code{object} is symmetric or not.}\details{The \code{\link{matrix}} method is used inside \code{\link{eigen}} bydefault to test symmetry of matrices \emph{up to rounding error}, using\code{\link{all.equal}}. It might not be appropriate in allsituations.Note that a matrix \code{m} is only symmetric if its \code{rownames} and\code{colnames} are identical. Consider using \code{\link{unname}(m)}.}\seealso{\code{\link{eigen}} which calls \code{isSymmetric} when its\code{symmetric} argument is missing.}\examples{isSymmetric(D3 <- diag(3)) # -> TRUED3[2, 1] <- 1e-100D3isSymmetric(D3) # TRUEisSymmetric(D3, tol = 0) # FALSE for zero-tolerance## Complex Matrices - Hermitian or notz <- sqrt(matrix(-1:2 + 0i, 2)); Z <- t(Conj(z)) \%*\% zZtZ <- t(z) \%*\% zZ ; ZtZisSymmetric(Z) # TRUEisSymmetric(Z + 1) # TRUEisSymmetric(Z + 1i) # FALSE -- a Hermitian matrix has a *real* diagonalcolnames(D3) <- c("X", "Y", "Z")isSymmetric(D3) # FALSE (as row and column names differ)isSymmetric(D3, check.attributes=FALSE) # TRUE (as names are not checked)}\keyword{array}\keyword{utilities}