1001Ferramentas
Calculators

Matrix Trace

Computes the trace (main diagonal sum) of a square matrix of any order entered inline.

Matrix trace

The trace of a square matrix A is just the sum of the entries down its main diagonal: tr(A) = a₁₁ + a₂₂ + … + aₙₙ. A couple of properties make it useful. It's linear (tr(A+B) = tr(A)+tr(B) and tr(cA) = c·tr(A)), and it stays the same under similarity: tr(P⁻¹AP) = tr(A). In other words, the trace belongs to the linear operator itself and doesn't care which basis you wrote the matrix in. One more handy fact is that it equals the sum of the eigenvalues, counted with multiplicity.

Example: for A = [[1,2,3],[4,5,6],[7,8,9]], tr(A) = 1 + 5 + 9 = 15.

Applications

You'll run into the trace all over the place. In PCA it gives the total variance, since that's the trace of the covariance matrix. Machine learning normalizations such as BatchNorm and LayerNorm lean on it when they center by per-feature mean. In spectral theory it hands you the eigenvalue sum without making you diagonalize anything. And in physics it shows up as the partial trace of density matrices in quantum mechanics, or the trace of the stress tensor in continuum mechanics.

FAQ

Why is trace invariant under similarity? It comes down to one fact: tr(AB) = tr(BA) holds for any compatible A and B. Group the factors as tr(P⁻¹·(AP)) = tr((AP)·P⁻¹) = tr(A) and you're done.

Does trace work for non-square matrices? No. It's defined only for square matrices, because you need a main diagonal where the row and column indices line up.

Trace vs determinant? The trace adds the eigenvalues up; the determinant multiplies them together. Both are scalars that don't depend on the basis, but each tells you something the other doesn't.

Related Tools