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


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]?

  • 1
    $\begingroup$ Why not just put parentheses around the matrix multiplications according to the desired order? $\endgroup$ Feb 8, 2017 at 17:29
  • $\begingroup$ 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 $\endgroup$ Feb 8, 2017 at 17:36
  • $\begingroup$ I'm sorry David G. Stork, you are totally right, that can be done by making: M1....M4(M5...M11(M12...M15[x])) $\endgroup$ Feb 8, 2017 at 17:55
  • $\begingroup$ Incidentally this question may be useful: mathematica.stackexchange.com/q/83412/121 $\endgroup$
    – Mr.Wizard
    Feb 8, 2017 at 20:01

1 Answer 1


[Just so we can close this question as being solved:]

Place parentheses around the grouped matrices, e.g.,

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



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