TITLE: If $A,B \in \mathcal{M_2}(\mathbb{R})$ and $A^2+B^2=AB$, does it follow that $A$ and $B$ commute?
QUESTION [13 upvotes]: Let $A,B \in \mathcal{M_2}(\mathbb{R})$ such that $A^2+B^2=AB$. Is it necessary that $AB=BA$?
I could easily show that such matrices have the property that $(AB-BA)^2=O_2$ (this was actually the question I was asked, then I started wondering if it would be true that the matrices actually commute) by considering the matrix $M=A+\epsilon B$ and computing the determinat  of $M \cdot \overline{M}$($\epsilon \in \mathbb{C}\setminus \mathbb{R}$ is a cubic root of unity), but that's all I got. I tried to find some counterexamples, but I have a hard time finding any matrices with that property.
EDIT: To see that $(AB-BA)^2=O_2$ we do the following : by direct computations 
$$|\det M|^2=\det M \det \overline{M}=\epsilon^2 \det(AB-BA)$$ and this is a real number if and only if $\det(AB-BA)=0$. From the Cayley-Hamilton theorem we now get that $(AB-BA)^2=O_2$.

REPLY [5 votes]: Let $w$ be a primitive cubic root of unity and $X=A+wB$. If $A^2+B^2=AB$, then
$$
X\overline{X}=(A+wB)(A+w^2B)=wBA+(1+w^2)AB=w(BA-AB).
$$
Therefore $w^2\det(BA-AB)=|\det(X)|^2$ is real and $\det(BA-AB)$ must be zero. It follows that $X$ is singular. As it is also $2\times2$, we may write $X=uv^\ast$ for some $u,v\in\mathbb C^2$. Hence
$$
|v^\top u|^2=\operatorname{tr}\left(u(\overline{v^\top u})v^\top\right)
=\operatorname{tr}(X\overline{X})=w\operatorname{tr}(AB-BA)=0
$$
and $v^\top u=0$. Consequently, $w(AB-BA) = X\overline{X} = u(\overline{v^\top u})v^\top = 0$, i.e. $AB=BA$.