Given Matrix $A \sim B$ , can the sum of the diagonals be equal? E.g $$ A = \begin{bmatrix} 0 & 2 & -3 \\ -1 & 3 & -3 \\ 1 & -2 & a \\ \end{bmatrix},\qquad\qquad B = \begin{bmatrix} 1 & -2 & 0 \\ 0 & b & 0 \\ 0 & 3 & 1 \\ \end{bmatrix} $$
Why $A \sim B$ can result $0+3+a=1+b+1$?
$\newcommand{\tr}{\operatorname{tr}}$ The sum of the numbers on the diagonal of a matrix $A$ is called the trace of $A$ which is denoted by $\tr(A)$. The trace of a product of three square matrices of the same size $A,B,C$ satisfies $$\tr(ABC)=\tr(BCA),\qquad \text{(cyclicity)}$$ Then if $A$ and $B$ are similar matrices, i.e. there exists an invertible matrix $P$ such that $A=PBP^{-1}$, then we have that $$\tr(A)=\tr(PBP^{-1})=\tr(BP^{-1}P)=\tr(BI)=\tr(B)$$