Disclaimer: I'm new to Mathematica.

I have an array $\gamma[i]$ of length $n$, each element of which holds an $m\times m$-matrix. I would like to multiply all of them, $$\prod_{i=1}^n \gamma[i].$$ I started out thinking this should be incredibly simple but after searching through the documentation and on StackExchange for over an hour, the only information I could find is this post, in which the best answer suggests Apply[Dot, matrixList]. Since my matrices are not in a list this doesn't seem to help me much.

  • $\begingroup$ In Mathematica lingo an array is a list. Do you mean each matrix is store in a separate "variable" named gamma[1], gamma[2], and so forth (not gamma[[1]] as in a list-array)? $\endgroup$ – Michael E2 Aug 11 '16 at 1:11
  • $\begingroup$ @MichaelE2 Correct. $\endgroup$ – Casimir Aug 11 '16 at 1:12
  • 1
    $\begingroup$ Apply[Dot, Array[gamma, n]]? $\endgroup$ – Michael E2 Aug 11 '16 at 1:12
  • $\begingroup$ Module[{res = gamma[1]}, Do[res = res . gamma[i], {i, 2, n}]; res] is a C-like way to go....The previous might be more efficient. Would have to test. $\endgroup$ – Michael E2 Aug 11 '16 at 1:16
  • 2
    $\begingroup$ Yes, AFAIK there is no KroneckerPower-like function. I would use KroneckerProduct @@ Table[m, {n}]. (@@ is short infix for Apply.) Table will copy only pointers to m, so it's memory-efficient. But the Kronecker product will be so much bigger, that's not a major consideration here. $\endgroup$ – Michael E2 Aug 11 '16 at 11:21

For a sequence of matrices, gamma[1], gamma[2],..., gamma[n], you can use Array and apply `Dot as in the linked question, I need to multiply a series of matrices:

Apply[Dot, Array[gamma, n]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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