finds the trace of the matrix or tensor list.


finds a generalized trace, combining terms with f instead of Plus.


goes down to level n in list.


  • Tr[list] sums the diagonal elements list[[i,i,]].
  • Tr works for rectangular as well as square matrices and tensors.
  • Tr can be used on SparseArray objects. »


open allclose all

Basic Examples  (1)

The trace of a matrix is the sum of the diagonal elements:

Scope  (2)

Symbolic trace:

Trace of a numerical matrix:

Trace of a sparse matrix:

Generalizations & Extensions  (6)

For a vector Tr gives the sum of the elements:

For a higherrank tensor, Tr gives the sum of elements with equal indices:

Apply a function to the diagonal elements of a matrix:

Extract the diagonal of a matrix as a list:

Only consider down to level 1; this adds the rows of the matrix:

Only consider down to level 2:

Applications  (2)

Find the determinant of a triangular matrix:

Define an inner product for the cone of positive definite matrices using :

Project the matrix onto the space spanned by the matrix :

Properties & Relations  (3)

The trace of a matrix is invariant under similarity transformations:

The invariance means that the sum of the eigenvalues must equal the trace:

The Frobenius norm is defined as :

Tr[m,List] is equivalent to Diagonal[m] for a matrix m:

Introduced in 1999
Updated in 2003