Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Mathematica] Ordered matrix multiplication

  1. Sep 30, 2010 #1
    Hello everyone,

    I have a list, let's call it L1, of length N. Each element of this list is a square matrix.
    I would like to :
    1/ Apply MatrixExp[] to each element of L1 (I know how to do that)
    2/ Multiply each element of the subsequent list _in an ordred fashion_ i.e. from element N to element 1. In this order (!) because none of the matrices commute.

    To recap, I have


    and want the matrix M equal to


    What would be a nice "one liner" which does that ?
    Thanks in advance :)
  2. jcsd
  3. Sep 30, 2010 #2
    This isn't elegant...
    First create an example list of 5 random 2x2 matrices
    (working symbolically would be very slow)
    In[1]:= l[i_][__]:=-Random[]
    In[2]:= L[i_]:=Array[l,{2,2}]
    In[3]:= LL=Array[L,5];

    Now combine them together the way you wanted:
    In[4]:= MatrixExp[Dot@@(MatrixExp/@Reverse[LL])]
    Out[4]= {{1.12427,-0.100453},{-0.206832,1.17472}}

    Note that for very many large matrices, you might want to use a different solution that does not have to store each element in MatrixExp/@Reverse[LL].
  4. Sep 30, 2010 #3
    Thanks for your message :)
    Yeah, I ended up doing more or less what you suggested. I wrote M=L1//MatrixExp/@#&//Reverse//Dot@@#&.
    That was the Dot part I wasn't sure about : I thought for some reason that Dot[] accepted only two arguments. But no... It nicely "threads" over any number of arguments :)
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook