# Find two matrices that commute with a given matrix but do not commute with each other

I've been able to find matrices B and C that commute with $$A=\pmatrix{1 & 2\cr3 & 4}$$ by solving the system AB=BA where $$B=\pmatrix{a & b\cr c & d}$$ However, when I substitute free variables into my solution, I get two different matrices B and C that commute with A, but B and C always seem to commute with one another.

Can I get a little help on this?

Thanks

Update

Matlab code (Uses Symbolic Toolbox) mentioned in my comment below.

clc
P=[1 0 1; 1 1 1;0 1 1];
D=[1 0 0;0 1 0;0 0 2]
A=P*D*inv(sym(P))
syms a b c d e f g h k
B=[a b c;d e f; g h k];
M=[A*B==B*A]
H=[0 1 1 1 0 0 -1 0 0 0;...
1 2 1 0 -1 0 0 1 0 0;...
1 1 0 0 0 1 0 0 -1 0;...
1 0 0 -2 -1 -1 1 0 0 0;...
0 1 0 1 0 1 0 1 0 0;...
0 0 1 -1 -1 -2 0 0 1 0;...
1 0 0 -1 0 0 0 -1 -1 0;...
0 1 0 0 -1 0 1 2 1 0;...
0 0 1 0 0 -1 -1 -1 0 0]
rref(sym(H))
B=[3 -3 3;1 1 1;1 1 1]
A*B
B*A
C=[5 -4 3;2 1 1;1 1 2]
C*A
A*C
B*C
C*B


Second Update

Let $$A$$ be a diagonalizable matrix. Then $$A=SDS^{-1}$$. Prove: $$B$$ commutes with $$A$$ if and only if $$S^{-1}BS$$ commutes with $$D$$.

Proof: If we replace $$A$$ with $$SDS^{-1}$$, we can write: \begin{align*} AB&=BA\\ (SDS^{-1})B&=B(SDS^{-1})\\ SDS^{-1}B&=BSDS^{-1} \end{align*} The last line follows because of the associative property of matrix multiplication. Now we will multiply both sides on the left by $$S^{-1}$$, then both sides on the right by $$S$$. \begin{align*} DS^{-1}B&=S^{-1}BSDS^{-1}\\ DS^{-1}BS&=S^{-1}BSD\\ D(S^{-1}BS)&=(S^{-1}BS)D \end{align*} And we've shown that $$B$$ commutes with $$A$$ if and only if $$S^{-1}BS$$ commutes with $$D$$. Now, if $$D$$ has distinct diagonal elements, and $$S^{-1}BS$$ commutes with $$D$$, $$S^{-1}BS$$ is a diagonal matrix. See also A Matrix Commuting With a Diagonal Matrix with Distinct Entries is Diagonal. Then if $$C$$ also commutes with $$A$$, $$S^{-1}CS$$ is also a diagonal matrix. Because all diagonal matrices commute with each other, we can write: \begin{align*} (S^{-1}BS)(S^{-1}CS)&=(S^{-1}CS)(S^{-1}BS)\\ S^{-1}BSS^{-1}CS&=S^{-1}CSS^{-1}BS\\ S^{-1}BICS&=S^{-1}CIBS\\ S^{-1}BCS&=S^{-1}CBS \end{align*} Now we can multiply both sides on the left by $$S$$, then both sides on the right by $$S^{-1}$$ in our second step. \begin{align*} BCS&=CBS\\ BC&=CB \end{align*}

• What is your solution for $B$? (Please do not ask people to work it out for themselves when you already have the answer.) Dec 17, 2018 at 4:38
If a square matrix $$A$$ has distinct eigenvalues, the matrices that commute with $$A$$ are all polynomials in $$A$$, and these always commute with each other. This is most easily seen by noticing that $$A$$ is diagonalizable, and all matrices that commute with a diagonal matrix whose diagonal entries are distinct are themselves diagonal.
Thus in order to give an example where two matrices that commute with $$A$$ don't commute with each other, you'll need $$A$$ to have a repeated eigenvalue. The easiest example is $$A=I$$. If you want a less trivial example (not a multiple of $$I$$) you'll need at least $$3 \times 3$$ matrices.
• I outlined the proof in that paragraph. If $A$ has distinct eigenvalues, it is diagonalizable, say $A = S D S^{-1}$ where $D$ is diagonal with the same eigenvalues as $A$. $B$ commutes with $A$ iff $S^{-1} B S$ commutes with $D$. If $C$ commutes with $D$, then $C_{ij} D_{jj} = (CD)_{ij} = (DC)_{ij} = D_{ii} C_{ij}$, so if $D_{ii} \ne D_{jj}$ we must have $C_{ij} = 0$. Thus the only matrices that commute with a diagonal matrix whose diagonal entries are all distinct is a diagonal matrix. And all diagonal matrices commute with each other. Dec 17, 2018 at 13:17