dsyMatrix-class.Rd
The "dsyMatrix"
class is the class of symmetric, dense matrices
in non-packed storage and
"dspMatrix"
is the class of symmetric dense matrices in
packed storage, see pack()
. Only the upper
triangle or the lower triangle is stored.
Objects can be created by calls of the form new("dsyMatrix",
...)
or new("dspMatrix", ...)
, respectively.
uplo
:Object of class "character"
. Must be
either "U", for upper triangular, and "L", for lower triangular.
x
:Object of class "numeric"
. The numeric
values that constitute the matrix, stored in column-major order.
Dim
,Dimnames
:The dimension (a length-2
"integer"
) and corresponding names (or NULL
), see the
Matrix
.
factors
:Object of class "list"
. A named
list of factorizations that have been computed for the matrix.
"dsyMatrix"
extends class "dgeMatrix"
, directly, whereas"dspMatrix"
extends class "ddenseMatrix"
, directly.
Both extend class "symmetricMatrix"
, directly,
and class "Matrix"
and others, indirectly, use
showClass("dsyMatrix")
, e.g., for details.
signature(x = "dspMatrix", type = "character")
, or
x = "dsyMatrix"
or type = "missing"
: Computes the
matrix norm of the desired type, see, norm
.
signature(x = "dspMatrix", type = "character")
, or
x = "dsyMatrix"
or type = "missing"
: Computes the
reciprocal condition number, rcond()
.
signature(a = "dspMatrix", b = "....")
, and
signature(a = "dsyMatrix", b = "....")
: x
<- solve(a,b)
solves \(A x = b\) for \(x\); see
solve-methods
.
signature(x = "dsyMatrix")
: Transpose; swaps from
upper triangular to lower triangular storage, i.e., the uplo slot
from "U"
to "L"
or vice versa, the same as for all
symmetric matrices.
## Only upper triangular part matters (when uplo == "U" as per default)
(sy2 <- new("dsyMatrix", Dim = as.integer(c(2,2)), x = c(14, NA,32,77)))
#> 2 x 2 Matrix of class "dsyMatrix"
#> [,1] [,2]
#> [1,] 14 32
#> [2,] 32 77
str(t(sy2)) # uplo = "L", and the lower tri. (i.e. NA is replaced).
#> Formal class 'dsyMatrix' [package "Matrix"] with 5 slots
#> ..@ Dim : int [1:2] 2 2
#> ..@ Dimnames:List of 2
#> .. ..$ : NULL
#> .. ..$ : NULL
#> ..@ x : num [1:4] 14 32 NA 77
#> ..@ uplo : chr "L"
#> ..@ factors : list()
chol(sy2) #-> "Cholesky" matrix
#> 2 x 2 Matrix of class "dtrMatrix"
#> [,1] [,2]
#> [1,] 3.741657 8.552360
#> [2,] . 1.963961
(sp2 <- pack(sy2)) # a "dspMatrix"
#> 2 x 2 Matrix of class "dspMatrix"
#> [,1] [,2]
#> [1,] 14 32
#> [2,] 32 77
## Coercing to dpoMatrix gives invalid object:
sy3 <- new("dsyMatrix", Dim = as.integer(c(2,2)), x = c(14, -1, 2, -7))
try(as(sy3, "dpoMatrix")) # -> error: not positive definite
#> Error in asMethod(object) :
#> not a positive definite matrix (and positive semidefiniteness is not checked)
## 4x4 example
m <- matrix(0,4,4); m[upper.tri(m)] <- 1:6
(sym <- m+t(m)+diag(11:14, 4))
#> [,1] [,2] [,3] [,4]
#> [1,] 11 1 2 4
#> [2,] 1 12 3 5
#> [3,] 2 3 13 6
#> [4,] 4 5 6 14
(S1 <- pack(sym))
#> 4 x 4 Matrix of class "dspMatrix"
#> [,1] [,2] [,3] [,4]
#> [1,] 11 1 2 4
#> [2,] 1 12 3 5
#> [3,] 2 3 13 6
#> [4,] 4 5 6 14
(S2 <- t(S1))
#> 4 x 4 Matrix of class "dspMatrix"
#> [,1] [,2] [,3] [,4]
#> [1,] 11 1 2 4
#> [2,] 1 12 3 5
#> [3,] 2 3 13 6
#> [4,] 4 5 6 14
stopifnot(all(S1 == S2)) # equal "seen as matrix", but differ internally :
str(S1)
#> Formal class 'dspMatrix' [package "Matrix"] with 5 slots
#> ..@ uplo : chr "U"
#> ..@ Dim : int [1:2] 4 4
#> ..@ Dimnames:List of 2
#> .. ..$ : NULL
#> .. ..$ : NULL
#> ..@ x : num [1:10] 11 1 12 2 3 13 4 5 6 14
#> ..@ factors : list()
S2@x
#> [1] 11 1 2 4 12 3 5 13 6 14