This function takes a matrix that is Kronecker product \(A \otimes B\) (Definition 3.5), where \(A\) is \(P x Q\) and \(B\) is \(N x M\), and outputs the matrix \(B \otimes A\).

reverse.kronecker(ab, p, qq)

Arguments

ab

The \((NP) \times (QM)\) matrix \(A \otimes B\).

p

The number of rows of \(A\).

qq

The number of columns of \(A\).

Value

The \((NP) \times (QM)\) matrix \(B \otimes A\).

See also

Examples


# Create matrices
(A <- diag(1, 3))
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    0    1    0
#> [3,]    0    0    1
(B <- matrix(1:6, ncol = 2))
#>      [,1] [,2]
#> [1,]    1    4
#> [2,]    2    5
#> [3,]    3    6

# Perform kronecker
(kron <- kronecker(A, B))
#>       [,1] [,2] [,3] [,4] [,5] [,6]
#>  [1,]    1    4    0    0    0    0
#>  [2,]    2    5    0    0    0    0
#>  [3,]    3    6    0    0    0    0
#>  [4,]    0    0    1    4    0    0
#>  [5,]    0    0    2    5    0    0
#>  [6,]    0    0    3    6    0    0
#>  [7,]    0    0    0    0    1    4
#>  [8,]    0    0    0    0    2    5
#>  [9,]    0    0    0    0    3    6

# Perform reverse kronecker product
(reverse.kronecker(kron, 3, 3))
#>       [,1] [,2] [,3] [,4] [,5] [,6]
#>  [1,]    1    0    0    4    0    0
#>  [2,]    0    1    0    0    4    0
#>  [3,]    0    0    1    0    0    4
#>  [4,]    2    0    0    5    0    0
#>  [5,]    0    2    0    0    5    0
#>  [6,]    0    0    2    0    0    5
#>  [7,]    3    0    0    6    0    0
#>  [8,]    0    3    0    0    6    0
#>  [9,]    0    0    3    0    0    6

# Perform kronecker again
(kron2 <- kronecker(B, A))
#>       [,1] [,2] [,3] [,4] [,5] [,6]
#>  [1,]    1    0    0    4    0    0
#>  [2,]    0    1    0    0    4    0
#>  [3,]    0    0    1    0    0    4
#>  [4,]    2    0    0    5    0    0
#>  [5,]    0    2    0    0    5    0
#>  [6,]    0    0    2    0    0    5
#>  [7,]    3    0    0    6    0    0
#>  [8,]    0    3    0    0    6    0
#>  [9,]    0    0    3    0    0    6