Let $X \in \mathbb{R}^{3\times 3}$ be a diagonal matrix whose diagonal elements (from left to right) are $1$, $y$ and $-1$. For what values of $y$ will there exist matrices $A,B \in \mathbb{R}^{3\times 3}$ such that $AB-BA=X$?
So far using the properties of the trace function, I have deduced that $y$ cannot be non-zero, since $AB-BA=X$ implies $\text{tr}(AB-BA)=\text{tr}(X)$. Since $\text{tr}(AB-BA)=0$, the sum of diagonal elements of $X$ is also $0$. Therefore $1+y+(-1)=0$. How do I show that there exist or does not exist $A,B$ such that $AB-BA=X$, where $y=0$. The usual method of computing the product and difference to find the solution seems to be very tedious. I would be happy if someone can suggest a shorter method. Thanks.
In fact, it is a fact that a matrix $X$ can be expressed in the form $X = AB - BA$ if and only if $X$ has trace zero, as is proven here, for example.
I wouldn't necessarily use the full power of that proof here, though. Since $X$ has mostly zero, my bet would be that we should try making $A$ and $B$ out of mostly $0$s, possibly out of $0$s and $1$s.
And, with some experimenting of this kind, you'll find that we indeed have the example $$ A = \pmatrix{0&0&1\\0&0&0\\0&0&0}, \qquad B = A^T $$ Verify that $AB - BA$ produces the desired result.