bdiag | R Documentation |
Creates a sparse block-diagonal matrix.
bdiag.spam(...)
... |
Arrays to be binded together |
This is a small helper function to create block diagonal sparse matrices. In the two matrix case,
bdiag.spam(A,B)
, this is equivalent to a complicated rbind(cbind(A, null), cbind(B, t(null)))
,
where null
is a null matrix of appropriate dimension.
It is recursively defined.
The arrays are coerced to sparse matrices first.
This function is similar to the function bdiag
from the package
Matrix
. It is also similar to the function adiag
from the package
magic
. However, here no padding is done and all the dimnames are
stripped.
Returns a spam
matrix as described above.
Reinhard Furrer
diag.spam
.
A <- diag.spam(2, 4) # 2*I4
B <- matrix(1,3,3)
AB <- bdiag.spam(A,B)
# equivalent to:
ABalt <- rbind(cbind( A, matrix(0,nrow(A),ncol(B))),
cbind( matrix(0,nrow(B),ncol(A)), B))
norm(AB-ABalt)
# Matrices do not need to be square:
bdiag.spam(1,2:5,6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.