# The Trace of a Square Matrix

Before we look at what the trace of a matrix is, let’s first define what the main diagonal of a square matrix is.

Definition: If $A$ is an square $n \times n$ matrix, then the Main Diagonal of $A$ consists of the entries $a_{11}, a_{22}, …, a_{nn}$ (entries whose row number is the same as their column number). |

The following image is a graphical representation of the main diagonal of a square matrix.

We are now ready to looking at the definition of the trace of a square matrix.

Definition: If $A$ is a square $n \times n$ matrix, then the Trace of $A$ denoted $\mathrm{tr}(A)$ is the sum of all of the entries in the main diagonal, that is $tr(A) = \sum_{i=1}^n a_{ii}$. If $A$ is not a square matrix, then the trace of $A$ is undefined. |

Calculating the trace of a matrix is relatively easy. For example, given the following $4 \times 4$ matrix $A = \begin{bmatrix} 3 & 2 & 0 & 4\\ 4 & 1 & -2 & 3\\ -3 & -2 & -4 & 7 \\ 3 & 1 & 1 & 5 \end{bmatrix}$ then $\mathrm{tr}(A) = 3 + 1 + (-4) + 5 = 5$.

## Example 1

**Given the following matrix $B$, calculate $\mathrm{tr}(B)$:**

(1)

We note that there are five entries of the main diagonal, that is $b_{11} = 1, \: b_{22} = 11, \: b_{33} = 3, \: b_{44} = 1, \: b_{55} = 14$. The sum of these entries is the trace of $B$, that is $\mathrm{tr}(B) = 1 + 11 + 3 + 1 + 14 = 30$.

## Example 2

**Find all values of $n$ such that $\mathrm{tr}(C) = 23$.**

(2)

We only give notice to entries in the main diagonal. By the definition of a trace of a matrix, it follows that $\mathrm{tr}(C) = 3 + n^2 + 4$. We were given that $\mathrm{tr}(C) = 23$, and we can therefore solve for $n$ as follows:

(3)

Hence $n = \pm 4$ then $\mathrm{tr} (C) = 23$.

## Example 3

**Prove that if $C = A + B$, then $\mathrm{tr}(C) = \mathrm{tr}(A) + \mathrm{tr}(B)$ (assume $A, \: B, \: C$ are all $n \times n$ square matrices).**

**Proof:**If $C = A + B$, then:

(4)

- And therefore we have that:

(5)