Kronecker product {tensorEVD} | R Documentation |
Kronecker product
Description
Computes the direct Kronecker product between two matrices
Usage
Kronecker(A, B, rows = NULL, cols = NULL,
make.dimnames = FALSE, drop = TRUE,
inplace = FALSE)
Arguments
A |
(numeric) Left numeric matrix |
B |
(numeric) Right numeric matrix |
rows |
(integer) Index which rows of the Kronecker are to be returned. They must range from 1 to |
cols |
(integer) Index which columns of the Kronecker are to be returned. They must range from 1 to |
drop |
Either |
make.dimnames |
|
inplace |
|
Details
For any two matrices A={aij} of dimensions m × n and B={bij} of dimensions p × q, the direct Kronecker product between them is a matrix defined as the block matrix
A⊗B = {aijB}
which is of dimensions mp × nq.
Selecting specific rows and columns from the Kronecker can be done by pre- and post- multiplication with incidence matrices
R (A⊗B) C'
where
R is an incidence matrix for rows that can be formed by an integer vector rows
, and
C is an incidence matrix for columns that can be formed by an
integer vector cols
.
This sub-matrix of the Kronecker can be obtained by matrix indexing using rows
and cols
as
Kronecker(A,B)[rows,cols]
The function computes this sub-matrix of the Kronecker product directly from A and B without forming the whole Kronecker product. This is very useful if a relatively small number of row/columns are to be selected.
Value
Returns the Kronecker product matrix. It can be a sub-matrix of it as per the rows
and cols
arguments.
Examples
require(tensorEVD)
# Kronecker product of 2 vectors
A = rnorm(3)
B = rnorm(2)
(K = Kronecker(A, B))
# it must equal when using from the R-base package:
(K0 = kronecker(A, B))
# Kronecker product of 2 matrices
A = matrix(rnorm(12), ncol=3)
B = matrix(rnorm(4), ncol=2)
K = Kronecker(A, B)
# (it must equal (but faster) to:)
K0 = kronecker(A, B)
all.equal(K,K0)
# Subsetting rows/columns from the Kronecker
A = matrix(rnorm(100*150), ncol=150)
B = matrix(rnorm(100*120), ncol=120)
rows = c(1,3,5,7)
cols = c(10,20,30,50)
K = Kronecker(A, B, rows=rows, cols=cols)
# (it must equal (but much faster) to:)
K0 = kronecker(A, B)[rows,cols]
all.equal(K,K0)