0
$\begingroup$

I have a list of matrices generated by the code

HZ = (0.03/4)*(KroneckerProduct[PauliMatrix[1], PauliMatrix[1]] + 
 KroneckerProduct[PauliMatrix[2], PauliMatrix[2]] + 
 KroneckerProduct[PauliMatrix[3], PauliMatrix[3]]);

UZ[t_] = MatrixExp[-I HZ*t];

rin = {{0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};

routZ[t_] = UZ[t].rin.ConjugateTranspose[UZ[t]];

matrices = Table[routZ[t], {t, 0, 5}]

I want to apply an operation to each matrix in this list individually. I can get the operation I need to work on the first matrix in the list by applying the code

matrices1 = ArrayFlatten[Part[matrices, {1}], 1];

matrices2 = Partition[matrices1, {2, 2}];

matrices3 = {{matrices2[[1, 1]], Transpose@matrices2[[1, 2]]}, 
{Transpose@matrices2[[2, 1]], matrices2[[2, 2]]}};

matrices4 = ArrayFlatten[matrices3];

but I'm not sure how to extend this to apply to all of the matrices in the list rather than just the first.

$\endgroup$
  • 1
    $\begingroup$ Map, Map, Map. $\endgroup$ – Henrik Schumacher Apr 27 '18 at 15:27
2
$\begingroup$

Condensing your operations into one single function first(following your notation and steps as much as possible):

operation[matrix_List] := 
  Module[{m2, m3}, m2 = Partition[matrix, {2, 2}]; 
   m3 = {{m2[[1, 1]], Transpose@m2[[1, 2]]}, {Transpose@m2[[2, 1]], 
      m2[[2, 2]]}}; ArrayFlatten[m3]];

Now, just use Mapto get the transformed set of matrices:

operation /@ matrices
$\endgroup$

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