Prove:$A B$ and $B A$ has the same characteristic polynomial. Suppose $A B$ are all $n\times n$ matrix. Prove:$A B$ and $B A$ has the same characteristic polynomial.


*

*If A is invertible



\begin{align}P(A B)=|\lambda  E-A B|=\left|\lambda  A\cdot A^{-1}-A B\right|=\left|A\left(\lambda  A^{-1}-B\right)\right|=\left|A\left\|\text{$\lambda $A}^{-1}-B\right.\right|\end{align}
\begin{align}P(B A)=|\lambda  E-B A|=\left|\lambda  A^{-1}\cdot A-B A\right|=\left|\left(\lambda  A^{-1}-B\right)A\right|=\left|\left.\text{$\lambda $A}^{-1}-B\right\|A\right|\end{align}

Is it true?



*

*If A is not invertible



How to prove?
Edit:
I found a proof by Block Matrix Multiplication, it's more straightforward, is it right?
\begin{align}\left(
\begin{array}{cc}
 E & 0 \\
 -A & E \\
\end{array}
\right).\left(
\begin{array}{cc}
 \lambda  E & B \\
 \lambda  A & \lambda  E \\
\end{array}
\right)=\left(
\begin{array}{cc}
 \lambda  E & B \\
 0 & \lambda  E-A B \\
\end{array}
\right)\end{align}
\begin{align}\left(
\begin{array}{cc}
 \lambda  E & B \\
 \lambda  A & \lambda  E \\
\end{array}
\right).\left(
\begin{array}{cc}
 E & 0 \\
 -A & E \\
\end{array}
\right)=\left(
\begin{array}{cc}
 \lambda  E-B A & B \\
 0 & \lambda  E \\
\end{array}
\right)\end{align}
Another proof is by Sylvester determinant theorem which uses LU block decomposition.
 A: One way to do this is to note that $P(AB)-P(BA)$ is a polynomial in the entries of $A$ and $B$. You have shown that this vanishes for all invertible $A$, and want to show that it is precisely the zero polynomial. It suffices to note that the set of invertible $n\times n$ matrices over $\mathbb R$ or $\mathbb C$ is dense, and since polynomials are continuous it follows that $P(AB)-P(BA)$ is zero everywhere and thus the zero polynomial.
A: Fill two matrices $A$ and $B$ with $2n^2$ distinct indeterminates. Observe $A$ and $B$ are invertible in the field $F=K(a_{ij},b_{ij})$ formed by adjoining these formal variables. Hence $\chi_{AB}(T)=\chi_{BA}(T)$ holds in the field $F[T]$ and so in the subring $K[a_{ij},b_{ij}][T]$, after which we can simply apply the evaluation map so that $\chi_{AB}(T)=\chi_{BA}(T)$ holds for any two matrices $A$ and $B$ with entries taken in $K$.
The beauty of this "universal" argument is that it bypasses the analytic concept of density, instead working purely algebraically and applying to any desired field $K$.
A: If $A$ is not invertible, $A_t=A+tI_n$ is invertible except for finitely
many values of $t$. In particular, there is $\varepsilon > 0$ such that
$A_t$ is invertible for every $t\in ]0,\varepsilon[$.
We therefore have $P(A_tB)=P(BA_t)$. Making $t\to 0$, we deduce
$P(AB)=P(BA)$.
