kronecker.prod: Kronecker product on matrices

Description Usage Arguments Details Value References See Also Examples

View source: R/kronecker.R

Description

Computes the kronecker product of two matrices, x and y.

Usage

1
kronecker.prod(x, y = x)

Arguments

x

a numeric matrix or vector.

y

a numeric matrix or vector.

Details

Let \bold{X} be an m\times n and \bold{Y} a p\times q matrix. The mp\times nq matrix defined by

≤ft[{\begin{array}{*{20}{c}} x_{11}\bold{Y} & … & x_{1n}\bold{Y} \\ \vdots & & \vdots \\ x_{m1}\bold{Y} & … & x_{mn}\bold{Y} \end{array}}\right],

is called the Kronecker product of \bold{X} and \bold{Y}.

Value

An array with dimensions dim(x) * dim(y).

References

Magnus, J.R., Neudecker, H. (2007). Matrix Differential Calculus with Applications in Statistics and Econometrics, 3rd Edition. Wiley, New York.

See Also

kronecker function from base package is based on outer. Our C version is slightly faster.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# block diagonal matrix:
a <- diag(1:3)
b <- matrix(1:4, ncol = 2)
kronecker.prod(a, b)

# examples with vectors
ones <- rep(1, 4)
y <- 1:3
kronecker.prod(ones, y) # 12-dimensional vector
kronecker.prod(ones, t(y)) # 3 x 3 matrix

Example output

     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    3    0    0    0    0
[2,]    2    4    0    0    0    0
[3,]    0    0    2    6    0    0
[4,]    0    0    4    8    0    0
[5,]    0    0    0    0    3    9
[6,]    0    0    0    0    6   12
      [,1]
 [1,]    1
 [2,]    2
 [3,]    3
 [4,]    1
 [5,]    2
 [6,]    3
 [7,]    1
 [8,]    2
 [9,]    3
[10,]    1
[11,]    2
[12,]    3
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    1    2    3
[3,]    1    2    3
[4,]    1    2    3

fastmatrix documentation built on Oct. 18, 2021, 5:08 p.m.