symmpart-methods: Symmetric and Skew-Symmetric Parts of a Square Matrix

symmpart-methodsR Documentation

Symmetric and Skew-Symmetric Parts of a Square Matrix

Description

symmpart and skewpart compute the symmetric and skew symmetric parts (x + t(x))/2 and (x - t(x))/2 of a square matrix x. symmpart(x) + skewpart(x) is equal to x for all finite square matrices x.

Usage

symmpart(x, ...)
skewpart(x, ...)

## S4 method for signature 'denseMatrix'
symmpart(x, uplo = "U", trans = "C", ...)
## S4 method for signature 'CsparseMatrix'
symmpart(x, uplo = "U", trans = "C", ...)
## S4 method for signature 'RsparseMatrix'
symmpart(x, uplo = "U", trans = "C", ...)
## S4 method for signature 'TsparseMatrix'
symmpart(x, uplo = "U", trans = "C", ...)
## S4 method for signature 'diagonalMatrix'
symmpart(x, trans = "C", ...)
## S4 method for signature 'indMatrix'
symmpart(x, ...)
## S4 method for signature 'matrix'
symmpart(x, trans = "C", ...)

## Methods for 'skewpart' are parallel, but without 'uplo'

Arguments

x

a square matrix or Matrix.

uplo

a character string, "U" or "L", indicating which of the upper and lower triangles of the symmetric part is stored in the result.

trans

a character string, "C" or "T", indicating either the conjugate transpose or transpose, i.e., whether the result is (skew) Hermitian or symmetric. It matters only in the complex case. The default is "C", for consistency with methods for isSymmetric.

...

optional arguments passed from or to other methods.

Value

symmpart(x) returns a symmetric or Hermitian matrix, inheriting from symmetricMatrix or diagonalMatrix if x inherits from Matrix.

skewpart(x) returns a skew-symmetric or skew-Hermitian matrix, inheriting from generalMatrix, symmetricMatrix or diagonalMatrix if x inherits from Matrix.

See Also

isSymmetric, forceSymmetric.

Examples

m <- Matrix(1:4, 2,2)
symmpart(m)
skewpart(m)

stopifnot(all(m == symmpart(m) + skewpart(m)))

dn <- dimnames(m) <- list(row = c("r1", "r2"), col = c("var.1", "var.2"))
stopifnot(all(m == symmpart(m) + skewpart(m)))
colnames(m) <- NULL
stopifnot(all(m == symmpart(m) + skewpart(m)))
dimnames(m) <- unname(dn)
stopifnot(all(m == symmpart(m) + skewpart(m)))


## investigate the current methods:
showMethods(skewpart, include = TRUE)

Matrix documentation built on Aug. 13, 2024, 3:01 p.m.