Last chance! 50% off unlimited learning
Sale ends in
diagonalMatrix
.Diagonal(n, x = NULL)
.symDiagonal(n, x = rep.int(1,n), uplo = "U")
length(x)
is used..symDiagonal
, the resulting sparse
symmetricMatrix
will have slot uplo
set
from this argument, either "U"
or "L"
. Only rarely
will it make sense tDiagonal()
returns an object of class
ddiMatrix
or ldiMatrix
(with diagonalMatrix
). .symDiagonal()
returns an object of class
or
,
i.e., a sparse symmetric matrix. This can be
more efficient than Diagonal(n)
when the result is combined
with further symmetric (sparse) matrices, however not for
matrix multiplications where Diagonal()
is clearly preferred.
diag
for extraction
of the diagonal from a matrix works for all Matrix
, class diagonalMatrix
.Diagonal(3)
Diagonal(x = 10^(3:1))
Diagonal(x = (1:4) >= 2)#-> "ldiMatrix"
## Use Diagonal() + kronecker() for "repeated-block" matrices:
M1 <- Matrix(0+0:5, 2,3)
(M <- kronecker(Diagonal(3), M1))
(S <- crossprod(Matrix(rbinom(60, size=1, prob=0.1), 10,6)))
(SI <- S + 10*.symDiagonal(6)) # sparse symmetric still
stopifnot(is(SI, "dsCMatrix"))
Run the code above in your browser using DataLab