2
$\begingroup$

I am trying to compute the matrix product of all the elements of a table of the following form :

tableofmonodromy[csize_, x_, q_] := Table[ArrayFlatten[( {
   {ArrayFlatten[
      IdentityMatrix[2^(csize - i)]\[TensorProduct]a[x, 
        q]]\[TensorProduct]IdentityMatrix[2^(i - 1)], 
    ArrayFlatten[
      IdentityMatrix[2^(csize - i)]\[TensorProduct]b[x, 
        q]]\[TensorProduct]IdentityMatrix[2^(i - 1)]},
   {ArrayFlatten[
      IdentityMatrix[2^(csize - i)]\[TensorProduct]c[x, 
        q]]\[TensorProduct]IdentityMatrix[2^(i - 1)], 
    ArrayFlatten[
      IdentityMatrix[2^(csize - i)]\[TensorProduct]d[x, 
        q]]\[TensorProduct]IdentityMatrix[2^(i - 1)]}
  } )],{i, 1, csize}];

such that the definition of a,b,c,d is the following :

a[x_, q_] := ( {
    {(1/2) (x q - (x q)^-1) , 0},
    {0, 1/2 (x - x^-1)}
   } );

b[x_, q_] := ( {
    {0, 0},
    {1/2 (q - q^-1), 0}
   } ); 

c[x_, q_] := ( {
    {0, 1/2 (q - q^-1)},
    {0, 0}
   } );

d[x_, q_] := ( {
    {1/2 (x - x^-1), 0},
    {0, (1/2) (x q - (x q)^-1) }
   } );

Basically I am creating a series of 2x2 matrices with elements that are also matrices (operators) and storing them. Now that I have all my matrices inside of the table, I want to compute the matrix product of all of them.

My first approach was to do : Dot@@tableofmonodromy[csize,x,q] which gave me the error Dot: Tensors. I knew that it wouldn't work because my desired product is of the following form:

tableofmonodromy[3,x,q][[1]].tableofmonodromy[3,x,q][[2]].tableofmonodromy[3,x,q][[3]]

My second approach was to store the elements of the table (tableofmondromy[[i]]) in a list using a for loop, like so :

dummyarray=Array[f,csize]
For[i = 1, i < csize + 1, i++,dummyarray[[i]] = ArrayFlatten[tableofmonodromy[csize, x, q][[i]]]];
Dot@@dummyarray 

Which worked for calculating the product however I lost the "function" aspect of my calculations.

Is there a way to calculate the product of all of the elements of the table without losing the "function" aspect of the calculation and getting the result also as a function ?

$\endgroup$
9
  • 2
    $\begingroup$ Hello, when I copy-paste your code for the function "tableofmonodromy", I see that there is a missing comma near the end "--- ]*here*{i, 1, csize}]". After inserting the comma, when evaluating tableofmondromy[3,x,q] I receive an error from ArrayFlatten. $\endgroup$ Commented Jul 27, 2022 at 13:40
  • $\begingroup$ Do the functions a, b, c, and d have definitions as well? If so it might be easier to help if their definitions are included. $\endgroup$ Commented Jul 27, 2022 at 13:47
  • $\begingroup$ I just copy pasted exactly the code on my mathematica sheet. In all cases my problem is not specific to my code. I just want to know in case I have a table that has elements and these elements are matrices. How do I make the product of all these matrices (that have the function structure) and end up with a matrix that has also the function structure \ $\endgroup$
    – Ceethemez
    Commented Jul 27, 2022 at 13:47
  • $\begingroup$ yes a,b,c,d have definitions I will add those as an edit. (they are matrices as well and funcitons) $\endgroup$
    – Ceethemez
    Commented Jul 27, 2022 at 13:47
  • 1
    $\begingroup$ @user293787 It wasn't really clear to me at first thanks for clarifying it ! $\endgroup$
    – Ceethemez
    Commented Jul 27, 2022 at 14:18

1 Answer 1

4
$\begingroup$

The For-loop given by OP can be replaced by Map as follows:

newFunction[csize_,x_,q_] := Dot@@Map[ArrayFlatten,tableofmonodromy[csize,x,q]];

For example, calling

newFunction[3,x,q]

produces a certain $16 \times 16$ matrix.

$\endgroup$
2
  • $\begingroup$ Thank you so much ! $\endgroup$
    – Ceethemez
    Commented Jul 27, 2022 at 15:10
  • 1
    $\begingroup$ You are welcome. I am sure this question is a duplicate, or more like a ConstantArray["dupli-",{100}]<>"cate"... Anyhow, welcome to Map-world. $\endgroup$
    – user293787
    Commented Jul 27, 2022 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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