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
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.
- 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.
- Make sure every row has the same number of entries and the matrix is square, at most 10 × 10.
- 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 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.
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.
Frequently asked questions.
Is the trace of AB equal to the trace of A times the trace of B?
Why can tr(A²) come out negative?
How do the trace and determinant pin down a 2 × 2 matrix's eigenvalues?
Where does the trace turn up outside a linear algebra course?
Why is a non-square matrix rejected?
References& sources.
- [1]Encyclopedia of Mathematics (EMS Press), 'Trace of a square matrix'. Defines the trace as 'the sum of the entries on the main diagonal of this matrix' and lists linearity, the cyclic property tr(AB) = tr(BA), similarity invariance, and that the trace coincides with the sum of the roots of the characteristic polynomial. Retrieved 2026-07-29.
- [2]Encyclopedia of Mathematics (EMS Press), 'Characteristic polynomial'. States that the coefficient b1 is the trace of A (b1 = Tr A = a11 + ... + ann) and that the final coefficient bn is det A. Retrieved 2026-07-29.
- [3]Golub, G. H. & Van Loan, C. F. (2013). Matrix Computations, 4th ed., Johns Hopkins University Press — sections 2.1 and 2.3, including the identity tr(A transpose A) = the squared Frobenius norm. Print reference; publisher page linked.
How this page was produced
- Published by
- Quanta Calculator
- Overseen by
- Daniel, Quanta Calculator Researcher
- 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