Definition.
Trace of a square matrix
The trace of an $n\times{n}$ matrix is defined as the sum of its diagonals:
$$\mathrm{tr}(\boldsymbol{A})=\sum^n_{i=1}a_{ii}$$
Where $a_{ii}$ is the value of the matrix $\boldsymbol{A}$ at row $i$ column $i$ .
Example.
Computing the trace of a 2x2 matrix
Compute the trace of the following matrix:
$$\boldsymbol{A}=
\begin{pmatrix}
1&2\\
5&7\\
\end{pmatrix}$$
Solution . The trace of $\boldsymbol{A}$ is simply the sum of its diagonals:
$$\begin{align*}
\mathrm{tr}(\boldsymbol{A})
&=1+7\\
&=8
\end{align*}$$
Theorem.
Matrix and its transpose have the same trace
If $\boldsymbol{A}$ is a square matrix, then:
$$\mathrm{tr}(\boldsymbol{A})=
\mathrm{tr}(\boldsymbol{A}^T)$$
Proof . Let $\boldsymbol{A}$ be a square matrix. The transpose $\boldsymbol{A}^T$ has the same diagonal entries as $\boldsymbol{A}$ by theorem link , which means that the sum of the diagonals of $\boldsymbol{A}^T$ and $\boldsymbol{A}$ are the same. We therefore conclude that $\mathrm{tr}(\boldsymbol{A}^T)=
\mathrm{tr}(A)$ . This completes the proof.
Theorem.
Trace of cA where c is a scalar
If $\boldsymbol{A}$ is any matrix and $c$ is any scalar, then:
$$\mathrm{tr}(c\boldsymbol{A})=
c\cdot\mathrm{tr}(\boldsymbol{A})$$
Proof . Let $\boldsymbol{A}$ be the following square matrix:
$$\boldsymbol{A}=\begin{pmatrix}
a_{11}&a_{12}&\cdots&a_{1n}\\
a_{21}&a_{22}&\cdots&a_{2n}\\
\vdots&\vdots&\smash\ddots&\vdots\\
a_{n1}&a_{n2}&\cdots&a_{nn}\\
\end{pmatrix}$$
The trace of $\boldsymbol{A}$ is:
$$\begin{equation}\label{eq:o9IsYjUgzEbeq8g84Fn}
\mathrm{tr}(\boldsymbol{A})=
a_{11}+a_{22}+\cdots+a_{nn}
\end{equation}$$
If $c$ is any scalar, then $c\boldsymbol{A}$ is:
$$c\boldsymbol{A}=\begin{pmatrix}
ca_{11}&ca_{12}&\cdots&ca_{1n}\\
ca_{21}&ca_{22}&\cdots&ca_{2n}\\
\vdots&\vdots&\smash\ddots&\vdots\\
ca_{n1}&ca_{n2}&\cdots&ca_{nn}\\
\end{pmatrix}$$
The trace of $c\boldsymbol{A}$ is:
$$\begin{align*}
\mathrm{tr}(c\boldsymbol{A})
&=ca_{11}+
ca_{22}+
\cdots+
ca_{nn}\\
&=c(a_{11}+
a_{22}+
\cdots+
a_{nn})\\
&=c\cdot\mathrm{tr}(\boldsymbol{A})
\end{align*}$$
This completes the proof.
Theorem.
Trace of the sum of two matrices
If $\boldsymbol{A}$ and $\boldsymbol{B}$ are square matrices of the same shape, then:
$$\begin{align*}
\mathrm{tr}(\boldsymbol{A}+\boldsymbol{B})=
\mathrm{tr}(\boldsymbol{A})+
\mathrm{tr}(\boldsymbol{B})
\end{align*}$$
Solution . Let $\boldsymbol{A}$ and $\boldsymbol{B}$ be the following square matrices:
$$\boldsymbol{A}=
\begin{pmatrix}
a_{11}&a_{12}&\cdots&a_{1n}\\
a_{21}&a_{22}&\cdots&a_{2n}\\
\vdots&\vdots&\smash\ddots&\vdots\\
a_{n1}&a_{n2}&\cdots&a_{nn}\\
\end{pmatrix},\;\;\;\;
\boldsymbol{B}=
\begin{pmatrix}
b_{11}&b_{12}&\cdots&b_{1n}\\
b_{21}&b_{22}&\cdots&b_{2n}\\
\vdots&\vdots&\smash\ddots&\vdots\\
b_{n1}&b_{n2}&\cdots&b_{nn}\\
\end{pmatrix}$$
The sum $\boldsymbol{A}+\boldsymbol{B}$ is:
$$\boldsymbol{A}+\boldsymbol{B}=
\begin{pmatrix}
a_{11}+b_{11}&a_{12}+b_{12}&\cdots&a_{1n}+b_{1n}\\
a_{21}+b_{21}&a_{22}+b_{22}&\cdots&a_{2n}+b_{2n}\\
\vdots&\vdots&\smash\ddots&\vdots\\
a_{n1}+b_{n1}&a_{n2}+b_{n2}&\cdots&a_{nn}+b_{nn}\\
\end{pmatrix}$$
The trace of $\boldsymbol{A}+\boldsymbol{B}$ is:
$$\begin{align*}
\mathrm{tr}(\boldsymbol{A}+\boldsymbol{B})
&=(a_{11}+b_{11})+
(a_{22}+b_{22})+
\cdots+
(a_{nn}+b_{nn})\\
&=(a_{11}+a_{22}+\cdots+a_{nn})+
(b_{11}+b_{22}+\cdots+b_{nn})\\
&=\mathrm{tr}(\boldsymbol{A})+
\mathrm{tr}(\boldsymbol{B})
\end{align*}
$$
This completes the proof.
Theorem.
Trace of AB is equal to the trace of BA
If $\boldsymbol{A}$ and $\boldsymbol{B}$ are matrices, then the trace of $\boldsymbol{AB}$ is equal to the trace of $\boldsymbol{BA}$ , that is:
$$\mathrm{tr}(\boldsymbol{AB})=
\mathrm{tr}(\boldsymbol{BA})$$
Proof . Suppose we have the following matrices:
$$\boldsymbol{A}=
\begin{pmatrix}
a_{11}&a_{12}&\cdots&a_{1m}\\
a_{21}&a_{22}&\cdots&a_{2m}\\
\vdots&\vdots&\smash\ddots&\vdots\\
a_{n1}&a_{n2}&\cdots&a_{nm}\\
\end{pmatrix},\;\;\;\;
\boldsymbol{B}=
\begin{pmatrix}
b_{11}&b_{12}&\cdots&b_{1n}\\
b_{21}&b_{22}&\cdots&b_{2n}\\
\vdots&\vdots&\smash\ddots&\vdots\\
b_{m1}&b_{m2}&\cdots&b_{mn}\\
\end{pmatrix}$$
Since $\boldsymbol{A}$ is an $n\times{m}$ matrix and $\boldsymbol{B}$ is an $m\times{n}$ matrix, their product $\boldsymbol{AB}$ will be an $n\times{n}$ matrix.
By definition of traces, we have that:
$$\begin{align*}
\mathrm{tr}(\boldsymbol{AB})&=
\sum^n_{i=1}(\boldsymbol{AB})_{ii}\\
&=(\boldsymbol{AB})_{11}+(\boldsymbol{AB})_{22}+\cdots+(\boldsymbol{AB})_{nn}\\
\end{align*}$$
Here, $(\boldsymbol{AB})_{11}$ represents the value at row $1$ column $1$ in matrix $\boldsymbol{AB}$ . By matrix multiplication, we can compute each of these terms like so:
$$\begin{gather*}
(\boldsymbol{AB})_{11}=
a_{11}b_{11}+
a_{12}b_{21}+
\cdots+
a_{1m}b_{m1}\\
(\boldsymbol{AB})_{22}=
a_{21}b_{12}+
a_{22}b_{22}+
\cdots+
a_{2m}b_{m2}\\
\vdots\\
(\boldsymbol{AB})_{nn}=
a_{n1}b_{1n}+
a_{n2}b_{2n}+
\cdots+
a_{nm}b_{mn}
\end{gather*}$$
The trick here is to take the sum column-wise instead of row-wise:
$$\begin{gather*}
a_{11}b_{11}+a_{21}b_{12}+\cdots+a_{n1}b_{1n}=(\boldsymbol{BA})_{11}\\
a_{12}b_{21}+a_{22}b_{22}+\cdots+a_{n2}b_{2n}=(\boldsymbol{BA})_{22}\\
\vdots\\
a_{1m}b_{m1}+a_{2m}b_{m2}+\cdots+a_{nm}b_{mn}=(\boldsymbol{BA})_{mm}\\
\end{gather*}$$
Therefore, we can say that:
$$\begin{align*}
\mathrm{tr}(\boldsymbol{AB})
&=(\boldsymbol{AB})_{11}+(\boldsymbol{AB})_{22}+\cdots+(\boldsymbol{AB})_{nn}\\
&=(\boldsymbol{BA})_{11}+(\boldsymbol{BA})_{22}+\cdots+(\boldsymbol{BA})_{mm}\\
&=\mathrm{tr}(\boldsymbol{BA})
\end{align*}$$
This completes the proof.
Practice problems Consider the following matrix:
$$\boldsymbol{A}=
\begin{pmatrix}
1&2&3\\
5&7&8\\
1&3&2\\
\end{pmatrix}$$
Compute the trace of $\boldsymbol{A}$ .
Your answer
Submit answer
Show solution
The trace of $\boldsymbol{A}$ is simply the sum of its diagonals:
$$\mathrm{tr}(\boldsymbol{A})=1+7+2=10$$