Matrix Trace Calculator

Compute the trace of a square matrix with property verification, eigenvalue connection, diagonal contribution bars, and two-matrix mode for cyclic property testing.

Matrix A (3×3)
Matrix B (3×3)
tr(A)
0.00
Sum of diagonal: 0.00 + 0.00 + 0.00
tr(B)
0.00
Sum of diagonal: 0.00 + 0.00 + 0.00
tr(Aᵀ)
0.00
tr(Aᵀ) = tr(A) = 0.00 ✓
tr(2A)
0.00
2 × tr(A) = 2 × 0.00 = 0.00
tr(A²)
0.00
Trace of A multiplied by itself
‖A‖_F via trace
0.0000
√tr(AᵀA) = √0.00 = 0.0000
Σ eigenvalues
0.00
tr(A) = sum of eigenvalues = 0.00
tr(AB) = tr(BA)
0.00 = 0.00
Cyclic property verified ✓

Diagonal Elements

Positiona(i,i)b(i,i)Running Sum (A)
(1, 1)0.000.000.00
(2, 2)0.000.000.00
(3, 3)0.000.000.00
Total0.000.000.00

Diagonal Contribution Bars

a(1,1)
0.00
a(2,2)
0.00
a(3,3)
0.00

Trace Properties Verification

PropertyFormulaResultStatus
Transpose invariancetr(Aᵀ) = tr(A)0.00 = 0.00
Scalar linearitytr(kA) = k·tr(A)0.00 = 2·0.00
Additivitytr(A+B) = tr(A)+tr(B)0.00 = 0.00+0.00
Cyclic propertytr(AB) = tr(BA)0.00 = 0.00
Eigenvalue sumtr(A) = Σλᵢtr(A) = 0.00✓ Always true
Frobenius norm‖A‖²_F = tr(AᵀA)0.0000² = 0.00
Planning notes, formulas, and examples

About the Matrix Trace Calculator

The trace of a square matrix is the sum of its diagonal elements. Despite its simplicity, the trace is one of the most important scalar invariants in linear algebra, appearing throughout mathematics, physics, and machine learning.

The trace satisfies remarkable algebraic properties. It is linear: tr(A + B) = tr(A) + tr(B) and tr(kA) = k·tr(A). It is invariant under transposition: tr(Aᵀ) = tr(A). Most strikingly, it satisfies the cyclic property: tr(AB) = tr(BA), even when AB ≠ BA. This extends to any number of factors: tr(ABC) = tr(BCA) = tr(CAB).

Perhaps the most profound connection is to eigenvalues: the trace always equals the sum of all eigenvalues (counted with multiplicity). Combined with the fact that the determinant equals the product of eigenvalues, the trace and determinant together capture key spectral information.

In physics, the trace appears in the stress-energy tensor, moment of inertia calculations, and quantum mechanics (where the trace of the density matrix equals 1). In machine learning, the Frobenius norm satisfies ‖A‖²_F = tr(AᵀA), connecting the trace to matrix norms used everywhere in optimization and regularization.

When This Page Helps

While summing diagonal entries seems straightforward, the trace’s importance lies in its algebraic properties — verifying the cyclic identity tr(AB) = tr(BA), confirming eigenvalue sums, and computing the Frobenius norm via tr(AᵀA). This calculator sums the diagonal for matrices up to 5×5, supports optional two-matrix trace identities (tr(A + B), tr(AB), tr(BA)), shows each diagonal element’s contribution, and summarizes the six key trace properties. It turns a simple sum into a full property audit.

How to Use the Inputs

  1. Set the matrix size (1–5)
  2. Enter matrix elements or click a preset
  3. View the trace and diagonal elements in the output
  4. Enable two-matrix mode to verify cyclic and additive properties
  5. Check the diagonal contribution bars for visual insight
  6. Review the properties verification table for all trace identities
Formula used
tr(A) = Σᵢ aᵢᵢ = a₁₁ + a₂₂ + … + aₙₙ — the sum of diagonal elements.

Example Calculation

Result: tr(A) = 4 + 5 + 6 = 15

The trace is the sum of the diagonal elements: 4 + 5 + 6 = 15. This also equals the sum of the eigenvalues of A.

Tips & Best Practices

  • The trace of the identity matrix Iₙ is n
  • Nilpotent matrices always have trace = 0 (all eigenvalues are 0)
  • tr(AB) = tr(BA) even when AB ≠ BA — this is the cyclic property
  • For symmetric matrices, the trace equals the sum of real eigenvalues directly
  • The Frobenius norm squared equals tr(AᵀA) — useful for optimization

Algebraic Properties of the Trace

The trace is **linear**: tr(A + B) = tr(A) + tr(B) and tr(cA) = c·tr(A). It is **cyclic**: tr(ABC) = tr(BCA) = tr(CAB) (but ≠ tr(ACB) in general). These two properties make the trace one of the few truly coordinate-invariant quantities of a matrix — similar matrices P⁻¹AP always have the same trace as A. The trace of the identity I_n is n, and the trace of a nilpotent matrix is always 0 because all its eigenvalues are zero.

Connection to Eigenvalues and the Characteristic Polynomial

The trace equals the **sum of the eigenvalues** (counted with algebraic multiplicity): tr(A) = λ₁ + λ₂ + … + λₙ. For a 2×2 matrix, this gives the shortcut: eigenvalues are (λ₁, λ₂) where λ₁ + λ₂ = tr(A) and λ₁λ₂ = det(A). Similarly, the characteristic polynomial p(λ) = λⁿ − tr(A)λⁿ⁻¹ + … + (−1)ⁿ det(A). This makes the trace the simplest spectral invariant to compute.

Trace in Optimization and Machine Learning

The **Frobenius norm** is defined via the trace: ‖A‖_F² = tr(AᵀA) = Σaᵢⱼ², which connects matrix norms to eigenvalues. In machine learning, the trace appears in **dimensionality reduction** (maximizing tr(WᵀSW) in PCA), **regularization** (nuclear norm = trace of singular values), and **kernel methods** (tr(K) is the total variance captured). In physics, the trace of a density matrix equals 1 (probability conservation), and in differential geometry, the Ricci scalar is a trace of the curvature tensor.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • The trace is the sum of the diagonal elements of a square matrix. It is denoted tr(A) and equals a₁₁ + a₂₂ + … + aₙₙ.