In linear algebra, the trace of a square matrix , denoted , is defined as a sum of the elements on its main diagonal, . It is only defined for a square matrix ().
It can be shown that the trace of a matrix is equal to the sum of its eigenvalues (counted with algebraic multiplicities), see below. Also, for any matrices and 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).
Definition The trace of an square matrix is defined as
where denotes the entry on the row and column of . The entries of can be real numbers, complex numbers, or more generally elements of a field . The trace is not defined for non-square matrices.
Example Let be a matrix, with
Then
Properties
Basic properties The trace is a linear mapping. That is,
for all square matrices and , and all scalars .
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.
Trace of a product The trace of a square matrix which is the product of two matrices can be rewritten as the sum of entry-wise products of their elements, i.e. as the sum of all elements of their Hadamard product. Phrased directly, if and are two matrices, then:
If one views any real matrix as a vector of length (an operation called vectorization) then the above operation on and coincides with the standard dot product. According to the above expression, is a sum of squares and hence is nonnegative, equal to zero if and only if is zero. Furthermore, as noted in the above formula, . These demonstrate the positive-definiteness and symmetry required of an inner product; it is common to call the Frobenius inner product of and . This is a natural inner product on the vector space of all real matrices of fixed dimensions. The norm derived from this inner product is called the Frobenius norm, and it satisfies a submultiplicative property, as can be proven with the Cauchy–Schwarz inequality:
if and are real matrices such that is a square matrix. The Frobenius inner product and norm arise frequently in matrix calculus and statistics.
The Frobenius inner product may be extended to a hermitian inner product on the complex vector space of all complex matrices of a fixed size, by replacing by its complex conjugate.
The symmetry of the Frobenius inner product may be phrased more directly as follows: the matrices in the trace of a product can be switched without changing the result. If and are and real or complex matrices, respectively, thenThis is immediate from the definition of the matrix product:
This is notable both for the fact that does not usually equal , and also since the trace of either does not usually equal .For example, if
then the product is
and the traces are . The similarity-invariance of the trace, meaning that for any square matrix and any invertible matrix of the same dimensions, is a fundamental consequence. This is proved by
Similarity invariance is the crucial property of the trace in order to discuss traces of linear transformations as below.
Additionally, for real column vectors and , the trace of the outer product is equivalent to the inner product:
Cyclic property More generally, the trace is invariant under circular shifts, that is,
This is known as the cyclic property.
Arbitrary permutations are not allowed: in general,
However, if products of three symmetric matrices are considered, any permutation is allowed, since:
where the first equality is because the traces of a matrix and its transpose are equal. Note that this is not true in general for more than three factors.
Trace of a Kronecker product The trace of the Kronecker product of two matrices is the product of their traces:
Characterization of the trace The following three properties:
characterize the trace up to a scalar multiple; in other words: If is a linear functional on the space of square matrices that satisfies then and are proportional.Proof: Let the standard basis and note that if and
More abstractly, this corresponds to the decomposition
as (equivalently, ) defines the trace on which has complement the scalar matrices, and leaves one degree of freedom: any such map is determined by its value on scalars, which is one scalar parameter and hence all are multiple of the trace, a nonzero such map.
For matrices, imposing the normalization makes equal to the trace.
Trace as the sum of eigenvalues Given any matrix , there is
where are the eigenvalues of counted with algebraic multiplicity. This holds true even if is a real matrix and some (or all) of the eigenvalues are complex numbers, or more generally over any field with eigenvalues taken in an algebraic closure. The identity follows from the fact that is always similar to its Jordan form, an upper triangular matrix having on the main diagonal, together with the similarity-invariance of the trace discussed above. In contrast, the determinant of is the product of its eigenvalues; that is,
Trace of commutator When both and are matrices, the trace of the (ring-theoretic) commutator of and vanishes: , because and is linear. One can state this as "the trace is a map of Lie algebras from operators to scalars", as the commutator of scalars is trivial (it is an Abelian Lie algebra). In particular, using similarity invariance, it follows that the identity matrix is never similar to the commutator of any pair of matrices.
Conversely, any square matrix with zero trace is a linear combination of the commutators of pairs of matrices.Proof: is a semisimple Lie algebra and thus every element in it is a linear combination of commutators of some pairs of elements, otherwise the derived algebra would be a proper ideal. Moreover, any square matrix with zero trace is unitarily equivalent to a square matrix with diagonal consisting of all zeros.
Traces of special kinds of matrices
Relationship to the characteristic polynomial
The trace of an matrix is the coefficient of in the characteristic polynomial, possibly changed of sign, according to the convention in the definition of the characteristic polynomial.
Derivative relationships If is a square matrix with small entries and denotes the identity matrix, then we have approximately
Precisely this means that the trace is the derivative of the determinant function at the identity matrix. Jacobi's formula
is more general and describes the differential of the determinant at an arbitrary square matrix, in terms of the trace and the adjugate of the matrix.
From this (or from the connection between the trace and the eigenvalues), one can derive a relation between the trace function, the matrix exponential function, and the determinant:
A related characterization of the trace applies to linear vector fields. Given a matrix , define a vector field on by . The components of this vector field are linear functions (given by the rows of ). Its divergence is a constant function, whose value is equal to .
By the divergence theorem, one can interpret this in terms of flows: if represents the velocity of a fluid at location and is a region in , the net flow of the fluid out of is given by , where is the volume of .
The trace is a linear operator, hence it commutes with the derivative:
Trace of a linear operator In general, given some linear map of finite rank (where is a vector space), we can define the trace of this map by considering the trace of a matrix representation of , that is, choosing a basis for and describing as a matrix relative to this basis, and taking the trace of this square matrix. The result will not depend on the basis chosen, since different bases will give rise to similar matrices, allowing for the possibility of a basis-independent definition for the trace of a linear map.
Such a definition can be given using the canonical isomorphism between the space of linear endomorphisms of of finite rank and , where is the dual space of . Let be in and let be in . Then the trace of the decomposable element is defined to be ; the trace of a general element is defined by linearity. The trace of a linear map of finite rank can then be defined as the trace, in the above sense, of the element of corresponding to f under the above-mentioned canonical isomorphism. Using an explicit basis for and the corresponding dual basis for , one can show that this gives the same definition of the trace as given above.
In the language of tensor products
Given a vector space over the field , there is a natural bilinear map given by sending to the scalar . The universal property of the tensor product automatically implies that this bilinear map is induced by a linear functional on .
Similarly, there is a natural bilinear map given by sending to the linear map . The universal property of the tensor product, just as used previously, says that this bilinear map is induced by a linear map . If is finite-dimensional, then this linear map is a linear isomorphism. This fundamental fact is a straightforward consequence of the existence of a (finite) basis of , and can also be phrased as saying that any linear map can be written as the sum of (finitely many) rank-one linear maps. Composing the inverse of the isomorphism with the linear functional obtained above results in a linear functional on . This linear functional is exactly the same as the trace, providing a definition in coordinate-free terms.
Using the definition of trace as the sum of diagonal elements, the matrix formula is straightforward to prove, and was given above. In the present perspective, one is considering linear maps and , and viewing them as sums of rank-one maps, so that there are linear functionals and and nonzero vectors and such that and for any in . Then
for any in . The rank-one linear map has trace and so
Following the same procedure with and reversed, one finds exactly the same formula, proving that equals .
The above proof can be regarded as being based upon tensor products, given that the fundamental identity of with is equivalent to the expressibility of any linear map as the sum of rank-one linear maps. As such, the proof may be written in the notation of tensor products. Then one may consider the multilinear map given by sending to . Further composition with the trace map then results in , and this is unchanged if one were to have started with instead. One may also consider the bilinear map given by sending to the composition , which is then induced by a linear map . It can be seen that this coincides with the linear map . The established symmetry upon composition with the trace map then establishes the equality of the two traces.
For any finite dimensional vector space , there is a natural linear map ; in the language of linear maps, it assigns to a scalar the linear map . Sometimes this is called coevaluation map, and the trace is called evaluation map. These structures can be axiomatized to define categorical traces in the abstract setting of category theory. In particular, traces can be defined for endomorphisms of a finitely generated projective module over a ring, see .
Numerical algorithms
Stochastic estimator The trace can be estimated unbiasedly by "Hutchinson's trick":Given any matrix , and any random with , we have .
For a proof expand the expectation directly.
Usually, the random vector is sampled from (normal distribution) or (Rademacher distribution).
More sophisticated stochastic estimators of trace have been developed.
Applications If a 2 x 2 real matrix has zero trace, its square is a diagonal matrix.