Audited 29 Jul 2026·Last updated 28 Oct 2026·3 citations·Tier 3·0 uses

Matrix Trace Calculator

Find the trace of a square matrix up to 10 × 10, the sum of its main diagonal, with the diagonal entries, their mean and tr(A²), the sum of squared eigenvalues.

Matrix Trace Calculator

One row per line. Separate entries with commas or spaces.
Trace tr(A)
6
Sum of the main-diagonal entries, equal to the sum of the matrix's eigenvalues.
Matrix size (n)
3
Main-diagonal entries
2, -4, 8
Mean diagonal entry
2
tr(A squared)
138

Background.

Add the numbers running from the top-left corner of a square matrix to the bottom-right and you have its trace. For the 3 × 3 matrix in the example, with rows (2, 7, 1), (3, −4, 5) and (6, 0, 8), that is 2 + (−4) + 8 = 6. Nothing off the diagonal counts.

For something so easy to compute, the trace carries a surprising amount of information. It equals the sum of the matrix's eigenvalues, counted with multiplicity, so you know the total of all n eigenvalues without solving for any of them. It stays the same under any change of basis, which means it describes the linear map itself rather than the coordinates chosen to write it down. It is linear, so the trace of a sum is the sum of the traces, and it obeys the cyclic rule tr(AB) = tr(BA) even when AB and BA are different matrices.

Alongside the trace you get the diagonal entries that were added, so a mistyped row shows up at once, their mean, which is the average eigenvalue, and tr(A²), the sum of the squared eigenvalues. Matrices can be typed one row per line with commas or spaces, separated by semicolons, or pasted in bracket form such as [[1, 2], [3, 4]].

What is matrix trace calculator?

The trace of an n × n matrix A, written tr(A) or Tr A, is a₁₁ + a₂₂ + … + aₙₙ, the sum of the entries whose row and column numbers agree. It is defined only for square matrices. In the characteristic polynomial of A it appears as the coefficient of the second-highest power, up to sign, while the determinant is the constant term; that is why the trace is the sum of the eigenvalues and the determinant their product. Transposing a matrix leaves its trace unchanged.

How to use this calculator.

  1. Type or paste the matrix, one row per line, with entries separated by commas or spaces; semicolons and bracketed rows also work, as do decimals and forms like 2e3.
  2. Make sure every row has the same number of entries and the matrix is square, at most 10 × 10.
  3. Check the listed diagonal entries against what you meant to enter, then read the trace and, if you need it, tr(A²).

The formula.

tr(A) = Σᵢ aᵢᵢ = a₁₁ + a₂₂ + … + aₙₙ

tr(A) = Σᵢ aᵢᵢ, a single pass down the diagonal; the mean diagonal entry is tr(A) ÷ n.

For tr(A²) no product matrix is formed. The i-th diagonal entry of A² is row i of A multiplied into column i, Σⱼ aᵢⱼ aⱼᵢ, so tr(A²) = Σᵢ Σⱼ aᵢⱼ aⱼᵢ. Each diagonal entry contributes its square, and each off-diagonal pair aᵢⱼ and aⱼᵢ contributes twice their product. Because the eigenvalues of A² are the squares of A's eigenvalues, tr(A²) = Σλᵢ².

A second route gives the same number: tr(A²) = (tr A)² − 2 × the sum of the 2 × 2 principal minors, the determinants left after keeping any two rows and the matching two columns. For a real matrix with complex eigenvalues the squares can be negative, so tr(A²) can be smaller than (tr A)² ÷ n or even below zero.

A worked example.

Example

With rows (2, 7, 1), (3, −4, 5) and (6, 0, 8), the diagonal is 2, −4, 8. The trace is 2 − 4 + 8 = 6, and the mean diagonal entry is 6 ÷ 3 = 2. For tr(A²): the squared diagonal entries give 4 + 16 + 64 = 84. The off-diagonal pairs are 7 with 3, 1 with 6, and 5 with 0, contributing 2 × (21 + 6 + 0) = 54. So tr(A²) = 84 + 54 = 138. Multiplying out A² instead gives diagonal entries 31, 37 and 70, which also add to 138. The eigenvalues of this matrix, found numerically, are about 10.758, −4.7186 and −0.0394. They add to 6, matching the trace, and their squares, roughly 115.73 + 22.26 + 0.0016, add to 138. Three equal eigenvalues of 2 would have given only 12, so the large tr(A²) shows a widely spread spectrum.

matrix2, 7, 1 3, -4, 5 6, 0, 8

Frequently asked questions.

Is the trace of AB equal to the trace of A times the trace of B?
No. The trace adds across sums, tr(A + B) = tr A + tr B, and scales, tr(kA) = k tr A, but it does not multiply. What does hold is tr(AB) = tr(BA), even when A is m × n and B is n × m so the two products are different sizes.
Why can tr(A²) come out negative?
Because a real matrix can have complex eigenvalues. The 90° rotation matrix with rows (0, −1) and (1, 0) has eigenvalues i and −i; its trace is 0 and tr(A²) is −2, since i² + (−i)² = −2. Only when all eigenvalues are real is tr(A²) guaranteed to be at least zero.
How do the trace and determinant pin down a 2 × 2 matrix's eigenvalues?
For a 2 × 2 matrix the characteristic polynomial is λ² − (tr A)λ + det A, so the eigenvalues are the two numbers whose sum is the trace and whose product is the determinant. For larger matrices the middle coefficients matter too, so the trace and determinant alone are not enough.
Where does the trace turn up outside a linear algebra course?
The total variance of several variables is the trace of their covariance matrix. A projection matrix's trace equals its rank, which is how regression counts fitted parameters. In quantum mechanics a density matrix has trace 1, and tr(ρ²), its purity, equals 1 only for a pure state.
Why is a non-square matrix rejected?
Only a square matrix has a main diagonal running corner to corner, and the eigenvalue meaning of the trace needs a square matrix too. For a rectangular matrix the related quantity is tr(AᵀA), which is square and equals the sum of every entry squared, the squared Frobenius norm.

How this page was produced

Published by
Quanta Calculator
Primary sources
3 cited below
Method
tr(A) = Σᵢ aᵢᵢ = a₁₁ + a₂₂ + … + aₙₙ
Published
Last verified

Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 1560 calculators remain free
  • No billing is enabled
Coming soon