In linear algebra, the trace of an n-by-n square matrix A is defined to be the sum of the elements on the main diagonal (the diagonal from the upper left to the lower right) of A, i.e.,
where aii denotes the entry on the ith row and ith column of A. The trace of a matrix is the sum of the (complex) eigenvalues, and it is invariant with respect to a change of basis. This characterization can be used to define the trace of a linear operator in general. Note that the trace is only defined for a square matrix (i.e., n × n).
The trace (often abbreviated to "tr") is related to the derivative of the determinant (see Jacobi's formula).
Let A be a matrix, with
Then
The trace is a linear mapping. That is,
for all square matrices A and B, and all scalars c.
A matrix and its transpose have the same trace:
This follows immediately from the fact that transposing a square matrix does not affect elements along the main diagonal.
The trace of a product can be rewritten as the sum of entry-wise products of elements:
This means that the trace of a product of matrices functions similarly to a dot product of vectors. For this reason, generalizations of vector operations to matrices (e.g. in matrix calculus and statistics) often involve a trace of matrix products.
For real matrices, the trace of a product can also be written in the following forms:
The matrices in a trace of a product can be switched without changing the result: If A is an m × n matrix and B is an n × m matrix, then
More generally, the trace is invariant under cyclic permutations, i.e.,