How to obtain 3x3 matrices as output from the computation of 2x2 matrices

Please help me to achieve the 3 x 3 from the steps I undertook. I did line1 since ad A1 (2 x 2 matrix). I attempted to equate line 2, hoping to get line 3 (output which is 3 x 3 matrix). I attempted to equate line 2, hoping to get line 3 (output which is 3 x 3 matrix). I added the ‘commented out’ part of the code which I suspect it is a direction in moving from a 2x2 to 3x3 matrix, it’s just that I don’t have the right Mathematica syntax. See attachment.

(*_____ This is how one enters the input : {A1={{1,0},{0,-1}}, \
A2={{0,1},{0,0}}, A3={{0,0},{1,0}}}  __________*)

(*_____ Note that the order in which one inputs matters  _______*)
newlistSym = Input["Please input a basis in a list form"];
dim = Length[newlistSym];
AdjointMatrixCommutator[A1, A3] = Dot[A1, A3] - Dot[A3, A1]
(* adA3 = AdjointMatrixCommutator[A1,A3] == Table[c[1, 3, k], {k, 1, \
dim}]*)
AdjointMatrixCommutator[A1, A2] = Dot[A1, A2] - Dot[A2, A1]
(*ad A2 = AdjointMatrixCommutator[A1,A2] == c[1, 2, k], {k, 1, dim}*)
AdjointMatrixCommutator[A1, A1] = Dot[A1, A1] - Dot[A1, A1]
(*ad A1 = AdjointMatrixCommutator[A1,A3] == c[1, 1, k], {k, 1, dim}*)

Practice4.1.nb (12.7 KB)

From reading your code, I suggest that you implement {\tt adjointMatrixCommutator} as a function to avoid code duplication.

adjointMatrixCommutator[x_, basis_] := Module[{vars, f},
    vars = Array[f, Length[basis]];
    Flatten[  vars /. Solve[ Flatten[Plus @@ (vars*basis)] == Flatten[Dot[x, #] - Dot[#, x]], vars]]] &;

In the definition, I have used the built-in functions {\tt Flatten}, {\tt Solve} and {\tt Dot}. Please use the help menu to learn how these functions work. Next, I will define a function {\tt adjoint} that will generate the matrices that you want.

 adjoint[basis_][x_] := Transpose[Map[adjointMatrixCommutator[x, basis], basis]//MatrixForm;

In the above code, I have used three build-in functions: {\tt Transpose}, {\tt Map} and {\tt MatrixForm}. As before, use the help menu do see what these functions do. If you wish to use the result of the function {\tt adjoint} in subsequent calculations, remove {\tt // MatrixForm} at the end of the definition.

Finally, let’s test the function {\tt adjoint} by using the example that you commented in your file.

a1 = {{1, 0}, {0, -1}}; a2 = {{0, 1}, {0, 0}}; a3 = {{0, 0}, {1, 0}};
basis = {a1, a2, a3};  ad = adjoint[basis];
ad[a1]
ad[a2]
ad[a3]

I hope that, my suggestions address your problem.

Thank you for responding.
The reason of doing duplication for each computation was to show that the outputs were correct, however, the outputs must be in a 3 x 3 matrix. So that means for , the output ad[A3] should be

ad [A3] = {{0, 0, 0}, {0, 2, 0}, {0, 0, - 2}}

ad [A2] = {{0, 0, 0}, { 0, 2, 0}, {0, 0, 0}} 
ad [A1] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}

See updated attachment.
For the rest of the code in terms of using functions you are very correct and I appreciate your helpful input. If I used a similar definition of function array

adjointMatrixCommutator[x_, newlistSym _] := 
 Module[{vars, f}, vars = Array[f, Length[newlistSym ]]

in the earlier part of the code wouldn’t that confuse the rest of the code or is it a subsequent computation?