0
$\begingroup$

I wanted to create the following matrix by using block partition of matrices.

$\left[\begin{array}{c} I_D \otimes \text{Col}(K,1)\\ \vdots\\ I_D \otimes \text{Col}(K,T) \end{array}\right]$

Let

D=2
B = {{1, 1}, {1, 4}}

I used at first this function:

mat[T_, K_] := 
  ArrayFlatten[
   Table[KroneckerProduct[IdentityMatrix[2], K[[;; , i]]], {i, 1, 
     T}]];

The problem with this function is that the result has some () where they shouldn't be...

We can see that from mat[2, B] // MatrixForm

I have this function which solves the problem

mat2[T_, K_] := 
  Transpose[
   ArrayFlatten[{Table[
      KroneckerProduct[IdentityMatrix[2], K[[;; , i]]], {i, 1, 
       T}]}]];

When I do mat[2, B] // MatrixForm , I clearly see that the extra () have disappeared.

I think the problem starts with K[[;; , i]]] which returns a list which the kronecker thinks its a row, when I wanted a column...

Is there a way for K[[;; , i]]] to return a column?

$\endgroup$
  • 3
    $\begingroup$ Both mat[;;, 1]] and mat[[1, ;;]] return a one-dimensional array (assuming that mat is a two-dimensional array). "Row" and "column" make no sense in this context. {1, 2, 3} is a vector. {{1, 2, 3}} and {{1},{2},{3}} are matrices, not vectors (even though they are sometimes confusingly referred to as row-vector and column-vector). Some other systems, such as MATLAB, do not support vectors at all, and will always return the matrix, thus they force the "row/column vector" distinction. Mathematica does not. $\endgroup$ – Szabolcs Nov 19 '18 at 12:57
  • 2
    $\begingroup$ D has built-in meanings. Try to avoid starting one's own namings with capital letters in Mathematica. $\endgroup$ – Αλέξανδρος Ζεγγ Nov 19 '18 at 13:15
  • $\begingroup$ @Szabolcs but mathematically, the kronecker product will give a different matrix, with different dimensions... $\endgroup$ – An old man in the sea. Nov 19 '18 at 13:36
  • $\begingroup$ @ΑλέξανδροςΖεγγ Thanks I forgot that. ;) $\endgroup$ – An old man in the sea. Nov 19 '18 at 13:36
  • $\begingroup$ the obvious answer to the last question is Transpose[{K[[;;,i]]}]; you could also try ArrayFlatten[{KroneckerProduct[iN, Transpose[{#}]]} & /@ Transpose[B]] as an alternative, where iN=IdentityMatrix[n] $\endgroup$ – user42582 Nov 19 '18 at 13:39
0
$\begingroup$
newmat[idim_Integer, oldmat_?MatrixQ] :=
  Catenate[Transpose[KroneckerProduct[IdentityMatrix[idim], #]] &
    /@ Transpose@oldmat]
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.