# Splitting a chain of matrix multiplications [closed]

I have defined a matrix function in terms of a chain of matrix multiplications:

f[x_]:=M1.M2[x].M3...M15[x]


where just some of the 15 matrices M depend on x. However, I want to define this function by parts, putting together groups of matrices, for instance:

In order to compute f[x] I want, by definition of f[x], that Mathematica computes it in the follow order

1. M12.M13...M15[x]
2. M5.M6...M11.(result of 1.)
3. M1.M2[2]...M4.(result of 2.)

How can I include this procedure in the definition of f[x]?

## closed as off-topic by MarcoB, march, corey979, Feyre, m_goldbergFeb 8 '17 at 19:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, march, corey979, Feyre, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

• Why not just put parentheses around the matrix multiplications according to the desired order? – David G. Stork Feb 8 '17 at 17:29
• Because that makes the computation as difficult as to perform the whole chain at once. The idea is to use memory to save computational time, storing partial results instead of computing the chain as a whole – NessunDorma Feb 8 '17 at 17:36
• I'm sorry David G. Stork, you are totally right, that can be done by making: M1....M4(M5...M11(M12...M15[x])) – NessunDorma Feb 8 '17 at 17:55
• Incidentally this question may be useful: mathematica.stackexchange.com/q/83412/121 – Mr.Wizard Feb 8 '17 at 20:01

f[x_] := M1.((M2.M3[x]).(M4.M5[x])).M6