The R Project SVN R

Rev

Rev 75395 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 75395 Rev 88000
Line 1... Line 1...
1
% File src/library/base/man/isSymmetric.Rd
1
% File src/library/base/man/isSymmetric.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2018 R Core Team
3
% Copyright 1995-2025 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{isSymmetric}
6
\name{isSymmetric}
7
\alias{isSymmetric}
7
\alias{isSymmetric}
8
\alias{isSymmetric.matrix}
8
\alias{isSymmetric.matrix}
9
\title{Test if a Matrix or other Object is Symmetric (Hermitian)}
9
\title{Test if a Matrix or other Object is Symmetric (Hermitian)}
10
\description{
10
\description{
11
  Generic function to test if \code{object} is symmetric or not.
11
  Generic function to test if \code{object} is symmetric or not.
12
  Currently only a matrix method is implemented, where a
12
  Currently only a matrix method is implemented, where a
13
  \code{\link{complex}} matrix \code{Z} must be \dQuote{Hermitian} for
13
  \code{\link{complex}} matrix \code{Z} must be \dQuote{Hermitian} for
14
  \code{isSymmetric(Z)} to be true.
14
  \code{isSymmetric(Z)} to be true, and
-
 
15
  (since \R >= 4.5.0),
-
 
16
  \code{isSymmetric(Z, trans = "T")} checks for \dQuote{simple} symmetry.
15
}
17
}
16
\usage{
18
\usage{
17
isSymmetric(object, \dots)
19
isSymmetric(object, \dots)
18
\method{isSymmetric}{matrix}(object, tol = 100 * .Machine$double.eps,
20
\method{isSymmetric}{matrix}(object, tol = 100 * .Machine$double.eps,
19
            tol1 = 8 * tol, \dots)
21
            tol1 = 8 * tol, trans = "C", \dots)
20
}
22
}
21
\arguments{
23
\arguments{
22
  \item{object}{any \R object; a \code{\link{matrix}} for the matrix method.}
24
  \item{object}{any \R object; a \code{\link{matrix}} for the matrix method.}
23
  \item{tol}{numeric scalar >= 0.  Smaller differences are not
25
  \item{tol}{numeric scalar >= 0.  Smaller differences are not
24
    considered, see \code{\link{all.equal.numeric}}.}
26
    considered, see \code{\link{all.equal.numeric}}.}
25
  \item{tol1}{numeric scalar >= 0.  \code{isSymmetric.matrix()}
27
  \item{tol1}{numeric scalar >= 0.  \code{isSymmetric.matrix()}
26
    \sQuote{pre-tests} the first and last few rows for fast detection of
28
    \sQuote{pre-tests} the first and last few rows for fast detection of
27
    \sQuote{obviously} asymmetric cases with this tolerance.  Setting it
29
    \sQuote{obviously} asymmetric cases with this tolerance.  Setting it
28
    to length zero will skip the pre-tests.}
30
    to length zero will skip the pre-tests.}
-
 
31
  \item{trans}{a single \code{\link{character}}, only relevant for a
-
 
32
    \code{\link{complex}} matrix \code{Z}: if it is \code{"C"} (as by
-
 
33
    default), \code{Conj(t(Z))} must be the same as \code{Z} whereas
-
 
34
    otherwise (typically it is \code{"T"}) \code{t(Z)} must equal
-
 
35
    \code{Z}.  The argument name is inherited from LAPACK.}
29
  \item{\dots}{further arguments passed to methods; the matrix method
36
  \item{\dots}{further arguments passed to methods; the matrix method
30
    passes these to \code{\link{all.equal}}.  If the row and column
37
    passes these to \code{\link{all.equal}}.  If the row and column
31
    names of \code{object} are allowed to differ for the symmetry check
38
    names of \code{object} are allowed to differ for the symmetry check
32
    do use \code{check.attributes = FALSE}!}
39
    do use \code{check.attributes = FALSE}!}
33
}
40
}
Line 53... Line 60...
53
D3
60
D3
54
isSymmetric(D3) # TRUE
61
isSymmetric(D3) # TRUE
55
isSymmetric(D3, tol = 0) # FALSE for zero-tolerance
62
isSymmetric(D3, tol = 0) # FALSE for zero-tolerance
56
 
63
 
57
## Complex Matrices - Hermitian or not
64
## Complex Matrices - Hermitian or not
58
Z <- sqrt(matrix(-1:2 + 0i, 2)); Z <- t(Conj(Z)) \%*\% Z
65
z <- sqrt(matrix(-1:2 + 0i, 2)); Z <- t(Conj(z)) \%*\% z
-
 
66
ZtZ <- t(z) \%*\% z
59
Z
67
Z ; ZtZ
60
isSymmetric(Z)      # TRUE
68
isSymmetric(Z)      # TRUE
61
isSymmetric(Z + 1)  # TRUE
69
isSymmetric(Z + 1)  # TRUE
62
isSymmetric(Z + 1i) # FALSE -- a Hermitian matrix has a *real* diagonal
70
isSymmetric(Z + 1i) # FALSE -- a Hermitian matrix has a *real* diagonal
63
 
71
 
64
colnames(D3) <- c("X", "Y", "Z")
72
colnames(D3) <- c("X", "Y", "Z")