1

I want to calculate the Kronecker product of several matrices in different orders. the

number of these matrices must be changeable.

sysdim = 5;(* number of matrices I want to multiply. this number must be changeable*)

id = IdentityMatrix[sysdim];

sp = (* it's a matrix. It can be anything. It's size is sysdim by sysdim*)

Do[Subscript[variable, i] = ReplacePart[KroneckerProduct[id, id, id, id, id], {i ->
sp}], {i, 1, sysdim}]

By this I can get all different Kronecker products corresponding to different orderings. However, I want to

change the number of these matrices as I wish. So, I thought the solution could be

something like this:

KroneckerProduct[Table[id,{i,1,sysdim}]]

The problem here is that the Tablecommand returns:

{id, id, id, id, id}

which KroneckerProductis not happy with. I need to get rid of the outermost braces to

get the KroneckerProductto work.

MOON
  • 3,864
  • 23
  • 49

1 Answers1

3

From the docs on Apply:

Apply[f,expr] or f@@expr replaces the head of expr by f.

So you can use Apply (@@) to replace the Head of Table[...] (which is List) with KroneckerProduct:

KroneckerProduct @@ Table[id, {sysdim}]
kglr
  • 394,356
  • 18
  • 477
  • 896
  • Since the index of the Table is not used in the table's expression you can use the more compact form: KroneckerProduct @@ Table[id, {sysdim}] – Bob Hanlon Jun 03 '14 at 17:16
  • Good point, thank you @BobHanlon -- edited the post with your suggestion. – kglr Jun 03 '14 at 17:18
  • @kguler. Thank you. When I use {i, {sysdim}}, Mathematica returns error but if I use {i,1,sysdim} or {sysdim} as Bob suggested everything is O.K. – MOON Jun 03 '14 at 17:44
  • @yashar, it took three edits to get from {i, 1, sysdim} to {sysdim} :) fixed now.. – kglr Jun 03 '14 at 17:48