Skip to main content

Matrix Trace Calculator

Calculate matrix trace instantly with our math tool. Shows detailed work, formulas used, and multiple solution methods.

Reviewed by Manoj Kumar, Mathematics Educator

Reviewed by Manoj Kumar, Mathematics Educator

Formula

tr(A) = A(1,1) + A(2,2) + ... + A(n,n)

The trace is the sum of the main diagonal elements of a square matrix. It equals the sum of all eigenvalues, is invariant under similarity transformations, and satisfies the cyclic property tr(ABC) = tr(CAB) = tr(BCA).

Worked Examples

Example 1: Trace of a 3x3 Matrix

Problem:Find the trace of A = [[5, 2, 1], [3, 7, 4], [6, 0, 9]].

Solution:Trace = sum of diagonal elements\ntr(A) = A(1,1) + A(2,2) + A(3,3)\ntr(A) = 5 + 7 + 9 = 21\nThe trace equals the sum of eigenvalues of A.

Result:Trace: 21 | Diagonal elements: 5, 7, 9 | Average diagonal: 7.0

Example 2: Trace of Identity Matrix

Problem:Verify that the trace of the 3x3 identity matrix equals 3.

Solution:I = [[1,0,0],[0,1,0],[0,0,1]]\ntr(I) = 1 + 1 + 1 = 3\nIn general, tr(I_n) = n for the n x n identity matrix.\nThis confirms that the identity has n eigenvalues all equal to 1.

Result:Trace: 3 | All diagonal elements: 1 | tr(I_n) = n

Frequently Asked Questions

What is the trace of a matrix?

The trace of a square matrix is the sum of its diagonal elements, that is, the elements where the row index equals the column index. For a matrix A of size n x n, the trace equals A(1,1) + A(2,2) + ... + A(n,n). Despite its simplicity, the trace is one of the most important matrix invariants in linear algebra. It equals the sum of all eigenvalues of the matrix, providing a quick way to check eigenvalue computations. The trace is invariant under similarity transformations, meaning tr(P^(-1)AP) = tr(A) for any invertible P. This invariance makes the trace useful for classifying matrices and analyzing linear operators independently of their coordinate representation.

What are the key properties of the trace operation?

The trace satisfies several elegant algebraic properties. It is linear: tr(A + B) = tr(A) + tr(B), and tr(kA) = k * tr(A) for any scalar k. It has the cyclic property: tr(ABC) = tr(CAB) = tr(BCA), though note that tr(ABC) does not generally equal tr(ACB). The trace of a transpose equals the original trace: tr(A^T) = tr(A). For the identity matrix, tr(I) = n, the dimension. The trace of the outer product of two vectors equals their inner product: tr(uv^T) = u^T v. These properties make the trace a powerful tool for simplifying matrix expressions and deriving theoretical results in linear algebra and functional analysis.

How does the trace relate to eigenvalues?

The trace of a matrix equals the sum of all its eigenvalues, counted with multiplicity. This is derived from the fact that the characteristic polynomial of an n x n matrix A is det(lambda*I - A) = lambda^n - tr(A)*lambda^(n-1) + ... + (-1)^n*det(A). Since the eigenvalues are roots of this polynomial, their sum equals the coefficient of lambda^(n-1) with appropriate sign, which is tr(A). This relationship provides a quick sanity check: if you compute eigenvalues, their sum should match the trace. For a 3x3 matrix with trace 15, the eigenvalues might be 5, 5, and 5, or 10, 3, and 2, but they must always sum to 15.

What is the cyclic property of the trace and why is it important?

The cyclic property states that tr(ABC) = tr(BCA) = tr(CAB). This means you can cyclically permute matrices inside a trace without changing the result. However, non-cyclic permutations like tr(ACB) generally give different values. This property is crucial in optimization, particularly in machine learning where loss functions involve traces of matrix products. It allows rearranging terms to simplify derivatives and computations. For example, when differentiating tr(X^T A X) with respect to X, the cyclic property helps derive that the gradient is (A + A^T)X. The cyclic property also underlies the similarity invariance of the trace, since tr(P^(-1)AP) = tr(APP^(-1)) = tr(A).

References

Reviewed by Manoj Kumar, Mathematics Educator ยท Editorial policy