A matrix trace is a scaler attached to a matrix that gives quick insights into matrix regularities such as similarity and other properties. We then propose to recall some properties of the trace and to propose a nice worksheet on the matrix trace to help understand this concept.

We assume that the reader is familiar with matrix operations and vector spaces.

What is a matrix trace?

Throughout the following the field $\mathbb{K}$ is the real numbers set $\mathbb{R}$ or the complex numbers set $\mathbb{C}$. We also denote by $\mathscr{M}_n(\mathbb{K})$ the space of all square matrices of order $n$ with coefficients in $\mathbb{K}$. If $A$ is matrix in $\mathscr{M}_n(\mathbb{K})$ with coefficients $\{a_{ij}: 1\le i,j\le n\},$ then we denote $A=(a_{ij})_{1\le i,j\le n}$, or sometimes just $A=(a_{ij})$ if there is no notational ambiguity.

Definition: A trace of the matrix $A=(a_{ji})\in\mathscr{M}_n(\mathbb{K})$ is the followin scalar number \begin{align*}{\rm Tr}(A)=\sum_{i=1}^n a_{ii}.\end{align*}

Example: The trace of the identity matrix $I_n$ of order $n$ is ${\rm Tr}(I_n)=1+\cdots+1=n$.

The following is one of the fundamental properties of trace matrices.

Theorem: Let $A\in\mathscr{M}_{n,p}(\mathbb{K})$ and $B\in\mathscr{M}_{p,n}(\mathbb{K})$ be two matrices. Prove that \begin{align*} {\rm Tr}(AB)={\rm Tr}(BA). \end{align*}

Proof: let $a_{ij},$ $b_{ij}$, $c_{ij}$ and $d_{ij}$ be the entries of the matrices $A,B,AB$ and $BA$ respectively. Observe that $AB$ is a square matrix of order $n$ and $BA$ is a matrix of order $p$. We have \begin{align*} c_{ij}=\sum_{k=1}^p a_{ik}b_{kj},\quad d_{ij}=\sum_{k=1}^n b_{ik}a_{kj}. \end{align*} Then by definition of the trace, we have \begin{align*} {\rm Tr}(AB)=\sum_{i=1}^n c_{ii}= \sum_{i=1}^n \left(\sum_{k=1}^p a_{ik}b_{ki}\right). \end{align*} On the other hand, \begin{align*} {\rm Tr}(BA)&=\sum_{i=1}^n d_{ii}= \sum_{i=1}^p \left(\sum_{k=1}^n b_{ik}a_{ki}\right)\cr&= \sum_{i=1}^n \left(\sum_{k=1}^p a_{ik}b_{ki}\right)\cr & ={\rm Tr}(AB). \end{align*}

Corollary: If two matrices $A$ and $B$ are similar, then they have the same trace.

Proof: By similarity of $A$ and $B,$ there exists an invertible matrix $P$ such that $A=P^{-1}BP$. Thus \begin{align*} {\rm Tr}(A)={\rm Tr}(P^{-1}(BP))={\rm Tr}((BP)P^{-1})={\rm Tr}(B).\end{align*}


Exercice: Does exist matrices $A,B\in\mathscr{M}_n(\mathbb{C})$ such that $AB-BA=I_n$?

Solution: Assume that $AB-BA=I_n$. As the trace operation is a linear map “linear forme” and ${\rm Tr}(I_n)=n,$ then \begin{align*} {\rm Tr}(AB)-{\rm Tr}(BA)=n. \end{align*} According to the Theorem above, we have ${\rm Tr}(AB)={\rm Tr}(BA)$, so that $n=0$. Absurd!!!

Exercise: Assume that matrices $A,B\in\mathscr{M}_n(\mathbb{C})$ satisfy \begin{align*} (AB-BA)^2=AB-BA. \end{align*} Show that $AB=BA$.

Solution: We put $N=AB-BA,$ so that $N^2=N$. This means that $N$ is the matrix associated with a projector $p$. Then ${\rm Tr}(p)={\rm Tr(N)}=0$. But it is known that ${\rm Tr}(p)={\rm Rank}$ “rank of $p$ which is the dimension of the range ${\rm Im}(p)$”. Hence ${\rm Rank}(p)=0$. This implies that $\ker(p)=\mathbb{C}$ “we recall that for a projector we have the direct sum $\mathbb{C}^n=\ker(p)+\mathcal{R}(p)$”. This means that $N=0_n$ “is the null matrix”. Finally, $AB=BA$.

Exercise: Let $A,B\in\mathscr{M}_n(\mathbb{R})$. Solve, in $\mathscr{M}_n(\mathbb{R}),$ the following matrices equation \begin{align*} X={\rm Tr}(X)A+B. \end{align*}

Solution: To solve the equation it suffices to determine ${\rm Tr}(X)$. By taking trace of $X$ and ${\rm Tr}(X)A+B,$ we obtain \begin{align*} {\rm Tr}(X)={\rm Tr}(X){\rm Tr}(A)+{\rm Tr}(B). \end{align*} This implies that \begin{align*}\tag{H} (1-{\rm Tr}(A)){\rm Tr}(X)={\rm Tr}(B) \end{align*} We distinct two cases:

If ${\rm Tr}(A)\neq 1$, then we have \begin{align*} {\rm Tr}(X)=\frac{{\rm Tr}(B)}{1-{\rm Tr}(A)}. \end{align*} This implies that the solution of the matrix equation is \begin{align*} X=\frac{{\rm Tr}(B)}{1-{\rm Tr}(A)}; A+B. \end{align*}

Assume that ${\rm Tr}(A)=1$. If ${\rm Tr}(B)\neq 0$, then the equation is not compatible and there is no solutions to the matrix equation. Now if ${\rm Tr}(B)= 0,$ then the condition (H) is verified for any condition on $X$. In particular if $\lambda={\rm Tr}(X)$, then $X=\lambda A+B$ is a solution.