Commutation of several matrices using Do?

Hello Wolfram Community

I have a list of lists. That is a matrix (listSym) containing matrices (A[1], A[2], … , A[6]).

A[1] = {{0, 0, 2, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};
A[2] = {{0, 0, 0, 1, 0, 0}, {0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};
A[3] = {{0, 0, 2, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};
A[4] = {{0, 0, 0 , 1, 0, 0}, {0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};
A[5] = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 2, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};
A[6] = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};
listSym = {A[1], A[2], A[3], A[4], A[5], A[6]};
dim = Length[listSym];

The matrix commutation of A[5] with listSym is:

AdjointMatrixCommutator [i_] :=  TableForm[ Dot[A[5], listSym[[i]]] - Dot[ listSym[[i]], A[5]], {i, 1, dim}, TableHeadings -> Automatic]

I want to do a commutation of A[1] with listSym, A[2] with listSym, A[3] with listSym, etc.

The matrix commutation of each A[i] with listSym (using a Do Loop) is:

Do[Print[TableForm[   Dot[A[i], listSym[[i]]] - Dot[listSym[[i]], A[i]], {i, 1, 
    dim}]], {i, 1, dim}]; 

I am getting matrices which are all zeros and that is incorrect. Can anyone show how to use a Do loop with lists (of matrix commutation).

Ps: I can provide more information for a better answer.

Dot is commutative so this will always be zero.

Dot[A[i], listSym[[i]]] - Dot[listSym[[i]], A[i]]

Perhaps you meant

Do[Print[
   Table[
    Dot[A[i], listSym[[j]]] - Dot[listSym[[j]], A[i]], {i, 1, dim}]], {j, 1, dim}];

Note that TableForm, as with most Form wrappers is not computable. The definition of AdjointMatrixCommutator should not use TableForm, use Table instead, and apply TableForm to the result if you want formatted output.

Yes indeed it is sorted. Thank you.

May I ask why listSym varies in this case, meaning why you used listSym[j], { j, 1, dim} instead of listSym only ?