In linear algebra, the trace of a square matrix A, denoted tr(A), is the sum of the elements on its main diagonal, a 11 + a 22 + ⋯ + a n n {\displaystyle a_{11}+a_{22}+\dots +a_{nn}} . It is only defined for a square matrix (n × n).
The trace of a matrix is the sum of its eigenvalues (counted with multiplicities). Also, tr(AB) = tr(BA) for any matrices A and B of the same size. Thus, similar matrices have the same trace. As a consequence, one can define the trace of a linear operator mapping a finite-dimensional vector space into itself, since all matrices describing such an operator with respect to a basis are similar.
The trace is related to the derivative of the determinant (see Jacobi's formula).