# Basis For Centralizer of Matrices

Given a square matrix $A \in \mathbb{R}^{n \times n}$, we can compute its centralizer $C(A) := \{ X \in \mathbb{R}^{n \times n} : XA = AX \}$ as follows

Reduce[{{x11, x12}, {x21, x22}}.{{1, 3}, {0, 2}} == {{1, 3}, {0,
2}}.{{x11, x12}, {x21, x22}}, {x11, x12, x21, x22}]


and as answer one gets something like

x21 == 0 && x22 == x11 + x12/3


How can I turn this description into a basis for the linear subspace $C(A)$ of $\mathbb{R}^{n \times n}$?

• Can you show the specific form C(A) should take for this example? – bill s Oct 23 '17 at 13:33

First let's write down the general solution of this system of linear equations:

sol = {{x11, x12}, {x21, x22}} /.
First@Solve[x21 == 0 && x22 == x11 + x12/3] /. {x11 -> s, x12 -> t,x21 -> u, x22 -> w}


{{s, t}, {0, s + t/3}}

Note that you do not have to rename your variables but I did this, because you see this a lot. We get a basis by setting one of the free variables to 1 and all others to 0.

vars = Variables[sol];
sol /. Table[vars[[j]] -> KroneckerDelta[i, j], {i, Length[vars]}, {j,Length[vars]}]


{{{1, 0}, {0, 1}}, {{0, 1}, {0, 1/3}}}

The first basis operator (identity) obviously commutes with your matrix, and you can check that the second one commutes with it, too. I think this is a clean and general solution, but I want to mention that your matrix is diagonalizable, so there is a simpler way to achieve this. Because any matrix that is diagonal in the eigenbasis of your matrix commutes with it, you can easily write down a basis of diagonal matrices in that basis and transform it back to the canonical basis.