MatrixCalc

Matrix trace calculator

Sum the main diagonal of a square matrix. The trace equals the sum of the eigenvalues, which makes it a quick check on any eigenvalue computation.

Matrix A
rows: 3
cols: 3
Matrix B
rows: 3
cols: 3
Operations
Result
Pick an operation to see the result here. Errors will show up in this area.

Tips: adjust sizes (max 50×50). For A×B, cols(A)=rows(B). det/inverse/trace/power require square matrices.

React, Tailwind & shadcn/ui. No external math deps. — English

The trace is the sum of the entries on the main diagonal — the ones where the row index equals the column index. Press tr(A) for the value. It is the simplest number you can extract from a matrix, and considerably more useful than its definition suggests.

Why such a simple sum is useful

The trace equals the sum of the eigenvalues, counted with multiplicity. That single fact turns it into a free check: compute the eigenvalues, add them, and compare with the diagonal sum. If they disagree, something went wrong. Paired with the determinant — which equals the product of the eigenvalues — the trace pins down both eigenvalues of any 2×2 matrix without solving anything.

It also has a property multiplication almost never offers: tr(A·B) = tr(B·A), even though A·B and B·A are usually different matrices. And unlike the determinant, the trace is linear — tr(A + B) = tr(A) + tr(B) and tr(k·A) = k·tr(A) — which is why it appears throughout statistics and physics wherever an average over a system is needed.

Worked example

271
035
494
tr = 2 + 3 + 4 = 9

Only the highlighted diagonal contributes; every other entry is ignored. For a triangular matrix the eigenvalues sit on that same diagonal, so the trace and the eigenvalue sum are visibly the same number.

Common mistakes

  • Summing the anti-diagonal. The trace runs top-left to bottom-right, always.
  • Taking the trace of a rectangular matrix. It is defined for square matrices only.
  • Expecting tr(A·B) = tr(A)·tr(B). False in general. The trace is linear over addition, not multiplication.
  • Confusing it with the determinant. The trace adds the eigenvalues; the determinant multiplies them. A zero trace says nothing about invertibility.

Frequently asked questions

What is the trace of a matrix?
The sum of the entries on the main diagonal, from the top-left corner to the bottom-right one.
Can a rectangular matrix have a trace?
No. Without a square shape there is no main diagonal running corner to corner, so the trace is undefined.
Why does the trace equal the sum of the eigenvalues?
Both appear as coefficients of the characteristic polynomial. Expanding det(A − λI) makes the coefficient of the second-highest power equal to the negative of the diagonal sum, and by the factor theorem that same coefficient is the negative of the eigenvalue sum.
Can the trace be zero for an invertible matrix?
Yes. Trace and invertibility are unrelated: a matrix with eigenvalues 3 and −3 has trace 0 and determinant −9, so it inverts perfectly well.

Want the full explanation? Read the guide: How to calculate the determinant of a matrix

Other calculators