How to create a dot product version of the product function

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 of Dotting should be optimized. – Henrik Schumacher Apr 25 at 19:04
• Also Dot @@ MList comes to mind where MList is a list of matrices. – Henrik Schumacher Apr 25 at 19:12
• That would work but I was hoping to automate this process. As you can imagine when n becomes quite, large manually entering all of the matrices would become tiresome so I am looking for a way to matrix multiply these matrices Mj with the index j running from 1 to n where i can input n to be any integer I need. – KJohn Apr 26 at 12:36
• Fold[Dot[#1, M[#2]] &, M[1], Range[2, n]]? – Henrik Schumacher Apr 26 at 14:24

matrixlist=Table[M[j],{j,1,n}]

• Dot @@ Array[M, n] – b3m2a1 May 27 at 3:19