I would like to create a function to matrix multiply (dot product) n matrices together, where n is large, for example
M1*M2*M3*M4*M5*...*Mn
I know there is the 'product' function that can do this for standard multiplication but I cannot seem to find a version for dot products. I have tried using a loop but this takes forever to run when n becomes large. Is there a way around this? Thanks in advance.
Dot[M1, M2, M3, M4, M5, ..., Mn]
? However, when the matrices vary much in size the order ofDot
ting should be optimized. $\endgroup$ – Henrik Schumacher Apr 25 at 19:04Dot @@ MList
comes to mind whereMList
is a list of matrices. $\endgroup$ – Henrik Schumacher Apr 25 at 19:12Fold[Dot[#1, M[#2]] &, M[1], Range[2, n]]
? $\endgroup$ – Henrik Schumacher Apr 26 at 14:24