TITLE: Finding all matrices $B$ such that $AB=BA$ for a fixed matrix $A$
QUESTION [13 upvotes]: Let 
$$ A=\begin{pmatrix}
1 & 0 & 0 \\
0& 1 & 0 \\
3 & 1 & 2
\end{pmatrix}
 $$
Find all matrices $B$ such that $AB=BA$.
Attempt at solution: I can show that $A$ is invertible so its inverse must be one of the elements. But how do I go about showing there are more of them? or not?. I can set set up the unknown matrix to be a matrix with 9 unknowns and then (at least in principle) try to solve or this system. But I think this is not a very productive way to do this. If these were $2 \times 2$ matrces that would be ok. How should I proceed? Any hints?
Thanks for your time and help.

REPLY [18 votes]: Here's another approach.  Notice that if $A$ and $B$ commute and if $C$ is any invertible matrix, then $C^{-1}AC$ and $C^{-1}BC$ commute.  This is because $$(C^{-1}AC)( C^{-1}BC) = C^{-1}ABC = C^{-1}BAC = (C^{-1}BC)(C^{-1}AC).$$
If we let $C$ be the matrix consisting of eigenvectors of $A$, then one can calculate that $$CAC^{-1} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0\\ 0 & 0& 2\end{bmatrix}.$$
So, what commutes with $CAC^{-1}$?  Multiplying a matrix on the left by $CAC^{-1}$ multiplies the rows by $1$, $1$, and $2$ respectively.  Multiplying a matrix on the right by $CAC^{-1}$ multiplies the columns by $1$, $1$, and $2$ respectively.  The only way these can be equal is if the spots which are multiplied by both $1$ and $2$ are $0$.  It follows that all of the matrices which commute with $CAC^{-1}$ have the form $$\begin{bmatrix} a & b & 0\\ c&d&0\\ 0&0&e\end{bmatrix}$$ and one easily checks that all of these do in fact commute with $C^{-1}AC$.
To turn this back into an answer for $A$ (instead of $C^{-1}AC$), multiply this general form on the left by $C$ and on the right by $C^{-1}$.
Doing this on maple, I find that the matrices which commute with $A$ are precisely those of the form $$\begin{bmatrix} a+c & \frac{1}{3}(a+c-b-d) & 0 \\ -3c & -c+d & 0 \\ -3a+3e & -a+b+e & e\end{bmatrix}. $$

REPLY [3 votes]: Let $$B = \begin{bmatrix}b_{11} & b_{12} & b_{13}\\ b_{21} & b_{22} & b_{23}\\ b_{31} & b_{32} & b_{33} \end{bmatrix}$$
We have $$A = \begin{bmatrix}1 & 0 & 0\\ 0 & 1 & 0\\ 3 & 1 & 2 \end{bmatrix}$$ Hence,
\begin{align}
AB & = \begin{bmatrix}1 & 0 & 0\\ 0 & 1 & 0\\ 3 & 1 & 2 \end{bmatrix}\begin{bmatrix}b_{11} & b_{12} & b_{13}\\ b_{21} & b_{22} & b_{23}\\ b_{31} & b_{32} & b_{33} \end{bmatrix}\\
& = \begin{bmatrix}b_{11} & b_{12} & b_{13}\\ b_{21} & b_{22} & b_{23}\\ 3b_{11} + b_{21} +2b_{31} & 3b_{12} + b_{22} +2b_{32} & 3b_{13} + b_{23} +2b_{33} \end{bmatrix}
\end{align}
\begin{align}
BA & = \begin{bmatrix}b_{11} & b_{12} & b_{13}\\ b_{21} & b_{22} & b_{23}\\ b_{31} & b_{32} & b_{33} \end{bmatrix}\begin{bmatrix}1 & 0 & 0\\ 0 & 1 & 0\\ 3 & 1 & 2 \end{bmatrix}\\
& = \begin{bmatrix}b_{11} + 3b_{13} & b_{12} + b_{13} & 2b_{13}\\ b_{21} + 3b_{23} & b_{22} + b_{23} & 2b_{23}\\ b_{31} + 3b_{33} & b_{32} + b_{33} & 2b_{33}\end{bmatrix}
\end{align}
Hence, we get that
$$\begin{bmatrix}b_{11} & b_{12} & b_{13}\\ b_{21} & b_{22} & b_{23}\\ 3b_{11} + b_{21} +2b_{31} & 3b_{12} + b_{22} +2b_{32} & 3b_{13} + b_{23} +2b_{33} \end{bmatrix} = \begin{bmatrix}b_{11} + 3b_{13} & b_{12} + b_{13} & 2b_{13}\\ b_{21} + 3b_{23} & b_{22} + b_{23} & 2b_{23}\\ b_{31} + 3b_{33} & b_{32} + b_{33} & 2b_{33}\end{bmatrix}$$
This gives us
$$b_{13} = b_{23} = 0$$
Hence, we have
$$B = \begin{bmatrix} b_{11} & b_{12} & 0\\ b_{21} & b_{22} & 0 \\ 3(b_{33} - b_{11})-b_{21} & b_{33} - b_{22} - 3b_{12} & b_{33}\end{bmatrix}$$
where $b_{ij} \in \mathbb{R}$.