# Multiply all matrices in an array

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.

• 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)? Aug 11, 2016 at 1:11
• @MichaelE2 Correct. Aug 11, 2016 at 1:12
• Apply[Dot, Array[gamma, n]]? Aug 11, 2016 at 1:12
• 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. Aug 11, 2016 at 1:16
• 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. Aug 11, 2016 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]]

• …or, Array[gamma, n, 1, Dot]`. Aug 11, 2016 at 5:40