forceSymmetric-methods | R Documentation |
Returns the symmetric matrix that results from reflecting one triangle of a square matrix onto the other.
forceSymmetric(x, ...)
## S4 method for signature 'denseMatrix'
forceSymmetric(x, uplo = NULL, trans = "C", ...)
## S4 method for signature 'CsparseMatrix'
forceSymmetric(x, uplo = NULL, trans = "C", ...)
## S4 method for signature 'RsparseMatrix'
forceSymmetric(x, uplo = NULL, trans = "C", ...)
## S4 method for signature 'TsparseMatrix'
forceSymmetric(x, uplo = NULL, trans = "C", ...)
## S4 method for signature 'diagonalMatrix'
forceSymmetric(x, uplo = "U", trans = "C", ...)
## S4 method for signature 'indMatrix'
forceSymmetric(x, ...)
## S4 method for signature 'matrix'
forceSymmetric(x, uplo = "U", trans = "C", ...)
x |
a square matrix or |
uplo |
a character string, |
trans |
a character string, |
... |
optional arguments passed from or to other methods. |
forceSymmetric(x)
can be understood as a coercion to virtual
class symmetricMatrix
.
However, unlike as(x, "symmetricMatrix")
,
methods for forceSymmetric
do not require that x
is already approximately symmetric.
An object inheriting from virtual class
symmetricMatrix
,
representing a Hermitian or symmetric matrix.
isSymmetric
, symmpart
, skewpart
.
## Hilbert matrix
i <- 1:6
h6 <- 1/outer(i - 1L, i, "+")
sd <- sqrt(diag(h6))
hh <- t(h6/sd)/sd # theoretically symmetric
isSymmetric(hh, tol=0) # FALSE; hence
try( as(hh, "symmetricMatrix") ) # fails, but this works fine:
H6 <- forceSymmetric(hh)
## result can be pretty surprising:
(M <- Matrix(1:36, 6))
forceSymmetric(M) # symmetric, hence very different in lower triangle
(tm <- tril(M))
forceSymmetric(tm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.