Let's say I have $A= \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \\ \end{bmatrix}$ and $B= \begin{bmatrix} b_{11} & b_{12} & b_{13} \\ b_{21} & b_{22} & b_{23} \\ b_{31} & b_{32} & b_{33} \\ \end{bmatrix}$. How do I figure out the elements of $M$ such that $M^{-1} A M = B$?
Note that in my case, $A$ and $B$ commute, and both are already diagonal and hermitian (they are elements of the Cartan subalgebra of SU(3)). Using these property I can't seem to obtain an expression for $M$ in terms of $A$ and $B$.
Note that "$A$, $B$ hermitian and diagonal" is not enough for $M$ to exist.
In fact, $M^{-1}AM=B$ implies that $A$ and $B$ have the same eigenvalues with the same multiplicities. In other words, the diagonal of $B$ should be a permutation of the diagonal of $A$. So you can take $M$ to be the permutation matrix that permutes the diagonal of $A$ into the diagonal of $B$.
For example, if $$ A=\begin{bmatrix}2&0&0\\0&3&0\\0&0&4\end{bmatrix}, \ \ \ B=\begin{bmatrix}2&0&0\\0&4&0\\0&0&3\end{bmatrix}, $$ you can take $$ M=\begin{bmatrix}1&0&0\\0&0&1\\0&1&0\end{bmatrix}. $$