Skip to content
Math

Matrix Trace Calculator

Enter your square matrix values and select its size to compute the trace instantly. The trace is the sum of the main diagonal elements - a fundamental quantity in linear algebra that equals the sum of a matrix's eigenvalues. This calculator supports matrices from 2x2 up to 6x6, shows every diagonal term explicitly, and walks through the arithmetic step by step.

Your details

The trace is only defined for square matrices (same number of rows and columns).
Row 1, Column 1 (diagonal)
Row 1, Column 2
Row 1, Column 3
Row 2, Column 1
Row 2, Column 2 (diagonal)
Row 2, Column 3
Row 3, Column 1
Row 3, Column 2
Row 3, Column 3 (diagonal)
Trace tr(A)
3

Sum of all main-diagonal elements a₁₁ + a₂₂ + ... + aₙₙ

Diagonal elementsa11 = 4, a22 = -3, a33 = 2
Matrix dimension3 x 3
Average diagonal element1
Trace tr(A)3
Average diagonal1

tr(A) = 3

  • The trace equals 3, which is the sum of all eigenvalues of this 3 x 3 matrix.
  • The average diagonal element is 1, which equals the average of all eigenvalues.
  • The trace is invariant under similarity transformations: tr(P⁻¹AP) = tr(A) for any invertible P.

Next stepA positive trace indicates the eigenvalues average to a positive value, but individual eigenvalues can still be negative.

What is the trace of a matrix?

The trace of a square matrix A, written tr(A), is the sum of all elements on the main diagonal - the elements where the row index equals the column index. For a 3x3 matrix with diagonal entries a11, a22, and a33, the trace is simply a11 + a22 + a33. The trace is defined only for square matrices (n x n), because non-square matrices have no well-defined main diagonal. It is one of the most fundamental scalar quantities in linear algebra, appearing in physics, machine learning, statistics, and differential equations.

How to calculate the matrix trace

Calculating the trace is straightforward. Identify the main diagonal entries (those at position (i, i) for each row i), then add them together. For example, if your 3x3 matrix has diagonal elements 4, -3, and 2, the trace is 4 + (-3) + 2 = 3. Off-diagonal elements are completely ignored. This simplicity is what makes the trace useful: it extracts a key scalar property from the full matrix in O(n) time, far faster than computing the determinant or eigenvalues.

The trace and eigenvalues

The most important fact about the trace is that it equals the sum of all eigenvalues of the matrix, counted with multiplicity. This is a consequence of the characteristic polynomial: if the eigenvalues of an n x n matrix are lambda1 through lambdan, then tr(A) = lambda1 + lambda2 + ... + lambdan. This relationship holds even when the eigenvalues are complex numbers. In quantum mechanics, the trace of a density matrix is always 1, and the expected value of an observable is computed as tr(rho * O). In machine learning, the trace of a covariance matrix gives the total variance across all dimensions.

Cyclic property and similarity invariance

Two properties make the trace especially powerful in proofs and applications. First, cyclicity: for any matrices A, B, C where the product is defined, tr(ABC) = tr(BCA) = tr(CAB). Note that this only applies to cyclic permutations, not arbitrary reorderings - tr(ABC) can differ from tr(ACB). Second, similarity invariance: if B = P^-1 A P for any invertible matrix P, then tr(B) = tr(A). This means similar matrices always share the same trace, so the trace is a property of the linear transformation itself, not of the particular basis used to represent it. These two properties together make the trace a coordinate-free invariant used throughout representation theory and differential geometry.

Matrix trace properties

PropertyFormulaDescription
Linearitytr(A + B) = tr(A) + tr(B)Trace distributes over matrix addition
Scalar multipletr(cA) = c · tr(A)A constant factor pulls out of the trace
Cyclicitytr(ABC) = tr(BCA) = tr(CAB)Cyclic permutations leave the trace unchanged
Transposetr(Aᵀ) = tr(A)Transposing a matrix does not change its trace
Eigenvalue sumtr(A) = λ₁ + λ₂ + ... + λₙThe trace equals the sum of all eigenvalues
Identity matrixtr(Iₙ) = nThe n x n identity matrix has trace n
Frobenius linktr(AᵀA) = ||A||_F²Trace of AᵀA equals the squared Frobenius norm
Similarity invarianttr(P⁻¹AP) = tr(A)Similar matrices share the same trace

Core algebraic properties of the trace operator for square matrices A and B of the same size.

Frequently asked questions

Is the trace defined for non-square matrices?

No. The trace is only defined for square matrices (n x n). Non-square matrices have no main diagonal in the standard sense, so the operation is undefined. If you have a non-square matrix A, you can form the square matrix A^T A or A A^T and compute their traces (which equal the squared Frobenius norm), but the trace of A itself is not defined.

What does a zero trace mean?

A zero trace means the sum of the diagonal elements equals zero, and equivalently the sum of all eigenvalues is zero. Skew-symmetric matrices always have zero trace because their diagonal entries are all zero. In physics, trace-free (traceless) matrices arise naturally in the study of special unitary groups such as SU(2) and SU(3), which underlie the Standard Model. In general, a zero trace does not imply the matrix is zero or singular.

Does the trace equal the sum of eigenvalues?

Yes, always. For any square matrix A with eigenvalues lambda1, lambda2, ..., lambdan (counted with multiplicity), tr(A) = lambda1 + lambda2 + ... + lambdan. This follows because the trace equals the coefficient of the (n-1)-degree term in the characteristic polynomial det(A - lambdaI), with a sign convention that matches the sum of roots. This makes the trace a quick sanity check when you compute eigenvalues: they should sum to the trace.

What is the trace of a product? Does tr(AB) = tr(BA)?

Yes, tr(AB) = tr(BA) for any two matrices A and B where both products are defined (A is m x n and B is n x m). This is the two-matrix case of the cyclic property. For three or more matrices, only cyclic permutations preserve the trace: tr(ABC) = tr(BCA) = tr(CAB), but tr(ABC) can differ from tr(ACB) or tr(BAC).

What is the relationship between trace and the Frobenius norm?

The squared Frobenius norm of a matrix A (the sum of squares of all elements) equals tr(A^T A). This means ||A||_F^2 = tr(A^T A). The Frobenius norm is widely used in machine learning and numerical analysis because it is easy to compute, and its trace-based formula makes many theoretical results cleaner. For symmetric positive semidefinite matrices, all eigenvalues are non-negative, so the trace also equals the sum of eigenvalues, giving tr(A) = ||A||_F^2 in that special case only when A = A^T A.

How is the trace used in machine learning?

The trace appears in machine learning in several key ways. The trace of a covariance matrix gives the total variance (sum of variances across all features). In principal component analysis (PCA), the fraction of variance explained by the selected components equals the trace of the submatrix divided by the trace of the full covariance matrix. In Gaussian process regression, the trace formula is used to evaluate model log-likelihoods efficiently. Regularization penalties such as the nuclear norm and the Ky Fan norm are also expressed in terms of the trace.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…