Linear Algebra

Matrix Trace

The trace of a square matrix A, written tr(A), is the sum of the entries on its main diagonal. It equals the sum of A's eigenvalues and is a fundamental invariant under similarity transforms.

Matrix Trace

Sum of the diagonal entries of a square matrix.

Try:
Answertr(A) = 15
  1. Matrix3×3 [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  2. Diagonal entries(1, 5, 9)
  3. Sum the diagonaltr(A) = 1 + 5 + 9 = 15

A quantity that survives a change of basis

The trace is the easiest quantity to compute from a square matrix: add up the entries running from the top left to the bottom right and ignore everything else. What makes it interesting is how much survives that apparently careless discarding.

This calculator lists the diagonal entries and sums them, for a square matrix of any size.

A matrix is a description of a transformation in some chosen coordinate system, and changing that system changes almost every entry. The trace is one of the few things that does not move: describe the same transformation in different coordinates and the diagonal entries will all differ while their total stays put.

That invariance is what makes it a property of the transformation rather than of the notation. It also explains the identity that gives the trace its real weight — the trace equals the sum of the eigenvalues, which are themselves basis-independent.

How to use this calculator

  1. Enter the matrix Commas between entries, semicolons between rows. It must be square, since the diagonal is only defined when the two dimensions agree.
  2. Check the diagonal entries line The entries picked out are listed before they are added. Confirming they are the ones you expected catches a mistyped row before the total is read.
  3. Read the sum Shown as an explicit addition rather than only as a total, so the arithmetic can be followed at a glance.

The formula, and where it comes from

tr(A) = Σᵢ Aᵢᵢ = A₁₁ + A₂₂ + ⋯ + Aₙₙ = Σ λᵢ

The definition is the shortest in linear algebra: sum the entries whose row index equals their column index. Nothing off the diagonal is consulted, which is why two very different matrices can share a trace.

The identity with the eigenvalues is not obvious from that definition, and it is where the usefulness comes from. Expanding the characteristic polynomial shows that the coefficient next to the highest power is the negated sum of the diagonal entries — and that same coefficient is the negated sum of the roots. The two sums are therefore equal.

The trace is linear in the matrix: the trace of a sum is the sum of the traces, and scaling a matrix scales its trace by the same factor. Both follow immediately from the definition, since addition and scaling act entry by entry and the diagonal is picked out afterwards.

The identity worth remembering beyond those is that the trace of a product is unchanged when the factors are swapped, even though the product itself usually changes. That is what makes the trace invariant under a change of basis, since a basis change conjugates the matrix and the two conjugating factors then cancel inside the trace.

What each input means

A Matrix — form field “Square matrix (rows separated by ;)”
A square matrix of any size, entered row by row. Rectangular input is rejected, since it has no well-defined diagonal.
Aᵢᵢ Diagonal entries
The entries whose row and column indices agree, running from the top-left corner to the bottom-right one.
tr(A) Trace
Their sum. It equals the total of the eigenvalues, whether or not those eigenvalues are real.

Worked examples

Every number below is produced by the same calculation engine the tool above runs. Nothing here is typed by hand, so the walkthrough cannot drift from what you get when you enter the same values yourself.

A 3×3 matrix

The matrix with rows (1, 2, 3), (4, 5, 6) and (7, 8, 9). Only three of its nine entries affect the answer.

Inputs Square matrix (rows separated by ;) = 1, 2, 3; 4, 5, 6; 7, 8, 9

  1. Matrix 3×3 [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  2. Diagonal entries (1, 5, 9)
  3. Sum the diagonal tr(A) = 1 + 5 + 9 = 15

Result tr(A) = 15

The diagonal entries are 1, 5 and 9, so the trace is 15. The other six entries could be anything at all without changing that — which is a useful reminder of how little the trace pins down on its own.

This matrix is singular, with a zero determinant, and yet its trace is comfortably non-zero. The two invariants are independent: neither constrains the other, and both are needed to characterise even a 2×2 matrix.

A 2×2 matrix with a negative entry

Rows (5, −1) and (2, 3). The off-diagonal entries include a negative one, which the trace ignores entirely.

Inputs Square matrix (rows separated by ;) = 5, -1; 2, 3

  1. Matrix 2×2 [[5, -1], [2, 3]]
  2. Diagonal entries (5, 3)
  3. Sum the diagonal tr(A) = 5 + 3 = 8

Result tr(A) = 8

The trace is 8, from 5 and 3 alone. The −1 sits off the diagonal and plays no part, though it would certainly affect the determinant and the eigenvalues individually.

For a 2×2 matrix the trace and determinant together determine the characteristic polynomial completely, and therefore both eigenvalues. At this size the two numbers really do capture the essentials.

The identity matrix

A 4×4 identity. Every diagonal entry is 1 and everything else is 0.

Inputs Square matrix (rows separated by ;) = 1,0,0,0; 0,1,0,0; 0,0,1,0; 0,0,0,1

  1. Matrix 4×4 [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
  2. Diagonal entries (1, 1, 1, 1)
  3. Sum the diagonal tr(A) = 1 + 1 + 1 + 1 = 4

Result tr(A) = 4

The trace is 4, which is simply the size of the matrix. That holds for every identity: the trace counts the dimension of the space it acts on.

All four eigenvalues are 1, and they sum to 4 as the identity requires. This is the simplest case where the eigenvalue relationship can be checked without computing anything.

Reading the result

What the trace does not tell you

Almost everything about the off-diagonal structure. Two matrices with the same trace can behave completely differently, and one can be invertible while the other is not. It is one number extracted from many.

A zero trace is unremarkable

Unlike a zero determinant, it carries no implication about invertibility. It says only that the eigenvalues sum to zero, which happens routinely — for instance whenever they come in a pair of opposite signs.

Using it as a check on eigenvalues

Because the eigenvalues must sum to the trace, computing them and adding them up is a cheap independent verification. A mismatch means an eigenvalue is wrong or one has been missed.

When you would use this

Verifying an eigenvalue computation

The trace is far easier to compute than a characteristic polynomial, so comparing it against the sum of the eigenvalues found is a quick way to catch an error before proceeding.

Recognising equivalent transformations

Two matrices representing the same transformation in different bases must share a trace. A difference proves they are not related that way, though agreement alone does not prove they are.

Assumptions and limitations

What this calculator assumes

  • The matrix is square; the trace is undefined for any other shape.
  • Entries are real numbers, with commas between columns and semicolons between rows.
  • The sum is taken over the main diagonal, from the top-left entry to the bottom-right one.
  • Only the diagonal is read; the remaining entries are not consulted at all.

Where it stops being the right tool

  • Square matrices only, unlike the rank, which any shape possesses.
  • The anti-diagonal sum is not computed, and it is not an invariant in any case.
  • Eigenvalues are not found here — the trace only constrains their total.
  • No related invariants such as the determinant or the Frobenius norm are reported alongside.

Common mistakes

Summing the anti-diagonal instead

Why it happens. Both diagonals look equally natural, and for a symmetric-looking matrix the two sums can even coincide, which hides the error.

How to avoid it. Start at the top-left corner and move down and to the right. The diagonal entries line shows exactly which entries were used.

Reading a zero trace as significant

Why it happens. A zero determinant carries a strong meaning, so a zero trace is assumed to carry one as well.

How to avoid it. Treat it as an ordinary value. It only says the eigenvalues cancel out in total, which constrains nothing about invertibility.

Expecting the trace to distinguish matrices

Why it happens. It is easy to compute and often quoted, which makes it feel like a summary of the matrix rather than one coordinate of one.

How to avoid it. Use it alongside the determinant and, where needed, the eigenvalues. Two matrices agreeing on the trace alone may have nothing else in common.

Frequently asked questions

Why is the trace useful?

Because it is invariant under a change of basis and equals the sum of the eigenvalues. That makes it a property of the underlying transformation rather than of the coordinates chosen, and a cheap check on any eigenvalue calculation.

Does the trace require a square matrix?

Yes. It sums the entries where the row index equals the column index, and a rectangular matrix has no such well-defined diagonal running corner to corner.

Is the trace linear?

Yes. The trace of a sum of two matrices is the sum of their traces, and scaling a matrix scales its trace by the same factor. Both follow directly from addition and scaling acting entry by entry.

Does the trace of a product depend on the order?

No — swapping the two factors leaves the trace unchanged, even though the product itself generally changes. This is what makes the trace survive a change of basis, since the conjugating factors cancel inside it.