Find all $n$ for which there exist A, B, matrices of size n with real entries, such that $A^2B-BA^2=A$. Find all positive integers $n$ for which there exist two square matrices of size $n$, with real entries, shall we denote them by A and B, such that $A^2B-BA^2=A$ and $A\neq O_n$ and $B\neq O_n$.
So far, I have obtained that $A^{2m}B-BA^{2m}=mA^{2m-1}$ and $tr(A^{2m-1})=0$, for every $m \geq 1$. I believe this problem can be dealt with by (wisely) multiplying multiple matricial relationships, at left and at right with A, B or powers of them, however this is only a guess. 
 A: The given condition means that the commutator $[A^2,B]$ is equal to $A$. Hence $A^2$ commutes with $[A^2,B]$. By Jacobson's lemma, $[A^2,B]$ is nilpotent. Therefore $A$ is nilpotent.
It follows that no solution exists when $n\le2$, otherwise $A=[A^2,B]=[0,B]=0$, which is a contradiction.
When $n\ge3$, there is always a solution pair $(A,B)$ with
$$
A=\pmatrix{0&1&0\\ 0&0&1\\ 0&0&0}\oplus0\ \text{ and }\ B=\pmatrix{0&0&0\\ -1&0&0\\ 0&1&0}\oplus0.
$$
Remarks.


*

*In hindsight, we don't need Jacobson's lemma. Clearly the equation is not solvable when $n=1$. When $n=2$, the equation implies that $A$ is traceless. Therefore, by Cayley-Hamilton theorem, $A^2=-\det(A)I$. But then the equation will imply that $A=[A^2,B]=-\det(A)[I,B]=0$, which is a contradiction. Hence the equation is not solvable when $n=2$.

*Nevertheless, by Jacobson's lemma, $A$ is nilpotent. Let $2m$ be the least even positive integer such that $A^{2m}=0$. From $A^{2m}B-BA^{2m}=mA^{2m-1}$, we infer that $A^{2m-1}=0$. Therefore the index of nilpotence of $A$ must be odd. That is, in the Jordan form of $A$, the largest-sized Jordan block has an odd size.

A: As others have observed, it follows that $A$ is nilpotent. Fiddling with the entries,
$$
A=\pmatrix{0&1&0\\ 0&0&1\\0&0&0},\quad
B=\pmatrix{0&0&0\\ -1&0&0\\0&1&0}
$$
is a valid pair. Hence for all $n\ge3$ such matrix pairs exist.
For $n\le 2$, such pairs do not exist: then $A$ nilpotent implies $A^2=0$, and $A=0$ from the equation.
