Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

How to Find the Trace of a Matrix

The trace of a square matrix is the sum of its main-diagonal entries. Its properties give the trace of sums and products without computing the whole matrix.

Recognize the task

tr⁡(A)\operatorname{tr}(A), "the sum of the diagonal", "the sum of the eigenvalues", or the trace of a sum or product: tr⁡(31−20547−12)\operatorname{tr}\begin{pmatrix} 3 & 1 & -2 \\ 0 & 5 & 4 \\ 7 & -1 & 2 \end{pmatrix}, tr⁡(AB)\operatorname{tr}(AB), tr⁡(2A−3B)\operatorname{tr}(2A - 3B). Test: the matrix must be square.
The trace is defined in the trace lesson; see the trace formula.

Ways to do it

Diagonal sumone matrix
tr⁡(A)=a11+a22+⋯+ann\operatorname{tr}(A) = a_{11} + a_{22} + \cdots + a_{nn}
Add the entries from top left to bottom right. Nothing else in the matrix matters.
Linearitysums and multiples
tr⁡(αA+βB)=αtr⁡(A)+βtr⁡(B)\operatorname{tr}(\alpha A + \beta B) = \alpha\operatorname{tr}(A) + \beta\operatorname{tr}(B)
Find each trace first, then combine (trace linearity).
Cyclic propertyproducts
tr⁡(AB)=tr⁡(BA)=∑i,jaij bji\operatorname{tr}(AB) = \operatorname{tr}(BA) = \sum_{i,j} a_{ij}\, b_{ji}
Only the diagonal of the product is needed (cyclic property).

Steps

StepOn A=(31−20547−12)A = \begin{pmatrix} 3 & 1 & -2 \\ 0 & 5 & 4 \\ 7 & -1 & 2 \end{pmatrix}
1Check that the matrix is square. The trace of a non-square matrix is not defined.3×33 \times 3 ✓
2Pick out the main diagonal. The entries a11,a22,…,anna_{11}, a_{22}, \dots, a_{nn}, from top left to bottom right.33, 55, 22
3Add them. The off-diagonal entries play no part.tr⁡(A)=3+5+2=10\operatorname{tr}(A) = 3 + 5 + 2 = 10
4Use the trace as a check on eigenvalues. The trace equals the sum of the eigenvalues, counted with multiplicity.the three eigenvalues of AA add up to 1010

Worked examples

Example 1 · a linear combination

linearity
A=(1234)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, B=(2013)B = \begin{pmatrix} 2 & 0 \\ 1 & 3 \end{pmatrix}: tr⁡(A)=5\operatorname{tr}(A) = 5, tr⁡(B)=5\operatorname{tr}(B) = 5
tr⁡(2A−3B)=2⋅5−3⋅5=−5\operatorname{tr}(2A - 3B) = 2 \cdot 5 - 3 \cdot 5 = -5
no need to form 2A−3B2A - 3B

Example 2 · a product

only the diagonal
tr⁡(AB)=∑i,jaij bji\operatorname{tr}(AB) = \sum_{i,j} a_{ij}\, b_{ji}
same AA and BB
=1⋅2+2⋅1+3⋅0+4⋅3=16= 1 \cdot 2 + 2 \cdot 1 + 3 \cdot 0 + 4 \cdot 3 = 16
diagonal entries of ABAB only
tr⁡(AB)=tr⁡(BA)=16\operatorname{tr}(AB) = \operatorname{tr}(BA) = 16
even though AB≠BAAB \neq BA

Example 3 · checking eigenvalues

2 × 2
(4123)\begin{pmatrix} 4 & 1 \\ 2 & 3 \end{pmatrix}: claimed eigenvalues 55 and 22
tr⁡=4+3=7=5+2\operatorname{tr} = 4 + 3 = 7 = 5 + 2 ✓; det⁡=12−2=10=5⋅2\det = 12 - 2 = 10 = 5 \cdot 2 ✓
trace adds, determinant multiplies
the claim passes both checks

See it happen

The trace ignores everything off the diagonal, yet it does not depend on the basis: similar matrices AA and P−1APP^{-1}AP have the same trace. That is why it equals the sum of the eigenvalues, which are basis-free too. Try it in the matrix trace visualizer.

Common mistakes

Adding the wrong diagonal

✗ tr⁡(31−20547−12)=−2+5+7\operatorname{tr}\begin{pmatrix} 3 & 1 & -2 \\ 0 & 5 & 4 \\ 7 & -1 & 2 \end{pmatrix} = -2 + 5 + 7
✓ main diagonal only: 3+5+2=103 + 5 + 2 = 10

Trace of a product as a product of traces

✗ tr⁡(AB)=tr⁡(A)tr⁡(B)=25\operatorname{tr}(AB) = \operatorname{tr}(A)\operatorname{tr}(B) = 25
✓ tr⁡(AB)=16\operatorname{tr}(AB) = 16 for the matrices above

Reordering three factors freely

✗ tr⁡(ABC)=tr⁡(BAC)\operatorname{tr}(ABC) = \operatorname{tr}(BAC)
✓ only cyclic shifts: tr⁡(ABC)=tr⁡(BCA)=tr⁡(CAB)\operatorname{tr}(ABC) = \operatorname{tr}(BCA) = \operatorname{tr}(CAB)

Trace of a non-square matrix

✗ tr⁡(123456)=1+5\operatorname{tr}\begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix} = 1 + 5
✓ undefined: the trace needs a square matrix