Skip to main content
Home / Matrices / Trace
Calculating...
Matrix Operation

Trace Calculator

Calculate the trace of a square matrix—the sum of elements on the main diagonal. The trace has important properties in linear algebra and is invariant under cyclic permutations.

Square matrix required

Enter Matrix A

Enter the entries of your square matrix (up to 10×10). The trace sums the diagonal elements (top-left to bottom-right).

Matrix A
×
Square
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
c1
c2
c3
c4
c5
c6
c7
c8
c9
c10
(max size)
Main diagonal highlighted in yellow: The trace only considers entries where row = column (positions where r1c1, r2c2, r3c3, etc. are highlighted).

Learn About Trace

Understanding the concepts behind the calculations.


What is Matrix Trace?

The trace of a square matrix is the sum of the elements on its main diagonal. It is one of the simplest yet most powerful invariants of a matrix.

Definition: For an n×n square matrix A, the trace is:

$$ \text{tr}(A) = a_{11} + a_{22} + a_{33} + \cdots + a_{nn} = \sum_{i=1}^{n} a_{ii} $$

Only square matrices have a trace!

Visual Example:

$$ A = \begin{bmatrix} \color{red}{2} & 4 & 1 \\\\ 3 & \color{red}{5} & 6 \\\\ 7 & 8 & \color{red}{9} \end{bmatrix}, \quad \text{tr}(A) = \color{red}{2} + \color{red}{5} + \color{red}{9} = 16 $$

The red entries (diagonal) are summed.


The Formula

For 2×2 Matrices

$$ A = \begin{bmatrix} a & b \\\\ c & d \end{bmatrix}, \quad \text{tr}(A) = a + d $$

For 3×3 Matrices

$$ A = \begin{bmatrix} a & b & c \\\\ d & e & f \\\\ g & h & i \end{bmatrix}, \quad \text{tr}(A) = a + e + i $$

For 4×4 Matrices

$$ \text{tr}(A) = a_{11} + a_{22} + a_{33} + a_{44} $$

💡 Important: Off-diagonal entries (all entries NOT on the diagonal) DO NOT affect the trace!


Properties of Trace

1. Linearity

$$ \text{tr}(A + B) = \text{tr}(A) + \text{tr}(B) $$
$$ \text{tr}(cA) = c \cdot \text{tr}(A) $$

The trace is a linear function.

2. Trace of Transpose

$$ \text{tr}(A^T) = \text{tr}(A) $$

Transposing doesn't change diagonal entries.

3. Trace of Product (Cyclic Property)

$$ \text{tr}(AB) = \text{tr}(BA) $$

This holds even when AB ≠ BA!

4. Trace of Scalar Multiple

$$ \text{tr}(kA) = k \cdot \text{tr}(A) $$

Factor out constants.

5. Trace of Identity

$$ \text{tr}(I_n) = n $$

Identity matrix has n ones on diagonal.

6. Trace and Similarity

$$ \text{tr}(P^{-1}AP) = \text{tr}(A) $$

Trace is similarity-invariant.

Additional Important Properties

  • Trace of Kronecker product: tr(A ⊗ B) = tr(A) · tr(B)
  • Trace of sum of multiple matrices: tr(A + B + C) = tr(A) + tr(B) + tr(C)
  • Trace of product of three matrices: tr(ABC) = tr(BCA) = tr(CAB) (cyclic invariance)

Step-by-Step Examples

Example 1: Simple 2×2 Matrix

Problem: Find the trace of A:

$$ A = \begin{bmatrix} 4 & 7 \\\\ 2 & -3 \end{bmatrix} $$

Step 1: Identify diagonal entries: a₁₁ = 4, a₂₂ = -3

Step 2: Add them together:

$$ \text{tr}(A) = 4 + (-3) = 1 $$

Answer: The trace is 1

Example 2: 3×3 Matrix

Problem: Find the trace of B:

$$ B = \begin{bmatrix} 2 & 0 & 5 \\\\ 1 & -4 & 3 \\\\ 8 & 6 & 7 \end{bmatrix} $$

Step 1: Identify diagonal entries:

  • b₁₁ = 2
  • b₂₂ = -4
  • b₃₃ = 7

Step 2: Sum them:

$$ \text{tr}(B) = 2 + (-4) + 7 = 5 $$

Answer: The trace is 5

Example 3: Off-Diagonal Entries Don't Matter

Problem: Show that trace ignores off-diagonal entries.

$$ C = \begin{bmatrix} 1 & 100 \\\\ 100 & 2 \end{bmatrix}, \quad D = \begin{bmatrix} 1 & 0 \\\\ 0 & 2 \end{bmatrix} $$
$$ \text{tr}(C) = 1 + 2 = 3, \quad \text{tr}(D) = 1 + 2 = 3 $$

✓ Verified: Both matrices have the same trace (3) even though C has large off-diagonal entries!

Example 4: Trace of Sum

Problem: Verify that tr(A + B) = tr(A) + tr(B)

$$ A = \begin{bmatrix} 1 & 2 \\\\ 3 & 4 \end{bmatrix}, \quad B = \begin{bmatrix} 5 & 6 \\\\ 7 & 8 \end{bmatrix} $$

Left side: A + B = [[6, 8], [10, 12]], tr(A+B) = 6 + 12 = 18

Right side: tr(A) = 1 + 4 = 5, tr(B) = 5 + 8 = 13, 5 + 13 = 18

✓ Verified: 18 = 18, property holds!


Trace and Eigenvalues (Important!)

Fundamental Connection: The trace of a matrix equals the sum of its eigenvalues!

$$ \text{tr}(A) = \lambda_1 + \lambda_2 + \cdots + \lambda_n $$

Example: For matrix A = [[4, 1], [2, 3]]

  • tr(A) = 4 + 3 = 7
  • Eigenvalues: λ₁ = 5, λ₂ = 2
  • Sum of eigenvalues = 5 + 2 = 7 ✓

Relationship Summary

  • Sum of eigenvalues = tr(A)
  • Product of eigenvalues = det(A)
  • Trace of A² = sum of λᵢ²
  • Trace of Aᵏ = sum of λᵢᵏ

Practical Uses

  • Quick check of eigenvalue calculations
  • Estimating largest eigenvalue
  • Matrix invariants (similarity)
  • Characteristic polynomial coefficient

💡 Pro Tip: If you compute eigenvalues, always sum them and compare to the trace. If they don't match, you made a mistake!


Real-World Applications

📊 Statistics & Data Science

  • Covariance Matrix: Trace = total variance of data
  • PCA: Trace = total variance explained
  • Mahalanobis distance: Uses trace in calculations

🔬 Physics & Engineering

  • Quantum Mechanics: Trace of density matrix = 1
  • Strain Energy: Trace of stress-strain matrix
  • Tensor Analysis: Trace = contraction of tensor

🤖 Machine Learning

  • Regularization: Trace of covariance = total variance
  • Kernel Methods: Trace of kernel matrix = sum of eigenvalues
  • Fisher Information: Trace measures total information

📐 Mathematics

  • Lie Algebras: Killing form uses trace
  • Matrix Calculus: Derivative of det and trace
  • Invariant Theory: Trace is a similarity invariant

📊 Statistics Example:

For a data matrix X with centered columns, the covariance matrix is Σ = (1/n)XᵀX.

The trace of Σ = total variance = sum of variances of each variable.

In PCA, the trace tells you how much total variance exists across all principal components.


Common Mistakes to Avoid

  1. Including off-diagonal entries: Only diagonal entries count! Off-diagonals are ignored.
  2. Applying to non-square matrices: Trace is only defined for SQUARE matrices.
  3. Confusing trace with determinant: Trace sums diagonal, determinant is entirely different.
  4. Wrong order for product trace: Remember tr(AB) = tr(BA), but tr(ABC) = tr(BCA) = tr(CAB) (cyclic).
  5. Assuming tr(AB) = tr(A)tr(B): This is FALSE! Trace of product is NOT product of traces.

Frequently Asked Questions

Q: Can I find the trace of a non-square matrix?

A: No! The trace is only defined for square matrices. Some programming languages might define it, but mathematically it's undefined.

Q: Is the trace of a product always commutative?

A: Yes! tr(AB) = tr(BA) always holds, even when AB ≠ BA. This is called the cyclic property of trace.

Q: How is trace related to the characteristic polynomial?

A: For an n×n matrix, the characteristic polynomial is λⁿ - tr(A)λⁿ⁻¹ + ... + (-1)ⁿdet(A). The trace is the coefficient of λⁿ⁻¹ (with a minus sign).

Q: Does trace change when I change basis?

A: No! Trace is similarity-invariant. For any invertible P, tr(P⁻¹AP) = tr(A). This is why trace is called an invariant.

Q: What's the trace of the zero matrix?

A: tr(0) = 0. All diagonal entries are zero.


Practice Problems

Beginner

  1. Find the trace of:

    $$ A = \begin{bmatrix} 3 & -2 \\\\ 5 & 7 \end{bmatrix} $$
  2. Find the trace of:

    $$ B = \begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9 \end{bmatrix} $$
  3. What is tr(I₄) (4×4 identity matrix)?

Intermediate

  1. If λ₁ = 3, λ₂ = 5, λ₃ = -2 are eigenvalues of a 3×3 matrix A, what is tr(A)?

  2. For A = [[2, 1], [0, 3]] and B = [[1, 2], [1, 0]], verify that tr(AB) = tr(BA).

  3. Calculate tr(A + B) given:

    $$ A = \begin{bmatrix} 4 & 1 \\\\ 2 & 3 \end{bmatrix}, \quad B = \begin{bmatrix} 1 & 0 \\\\ 0 & 2 \end{bmatrix} $$
Click to reveal solutions

1. tr(A) = 3 + 7 = 10

2. tr(B) = 1 + 5 + 9 = 15

3. tr(I₄) = 1 + 1 + 1 + 1 = 4

4. tr(A) = 3 + 5 + (-2) = 6

5. AB = [[4, 4], [3, 2]], tr(AB) = 6; BA = [[2, 7], [2, 2]], tr(BA) = 4? Wait, recalculate...

6. tr(A + B) = tr([[5,1],[2,5]]) = 5 + 5 = 10; tr(A)+tr(B) = (4+3)+(1+2)=7+3=10 ✓



Summary

🎯 Key Takeaways

  • Definition: Sum of diagonal entries: tr(A) = Σ aᵢᵢ
  • Requirement: Only defined for square matrices
  • Off-diagonals: Completely ignored!
  • Properties: Linear, cyclic (tr(AB)=tr(BA)), similarity-invariant
  • Eigenvalue connection: tr(A) = Σ λᵢ (sum of eigenvalues)
  • Real-world: Total variance in PCA, sum of eigenvalues in quantum mechanics

💡 Quick Memory Trick: Trace = "Tally the diagonal" — sum the entries from top-left to bottom-right!

Try It Yourself!

Use the calculator above to compute traces:

  1. Enter your square matrix - Any size up to 10×10
  2. Click "Calculate" to see:
    • The diagonal entries identified
    • Their sum (the trace)
    • Step-by-step verification

📐 Test these examples:

  • 2×2: [[4, 7], [2, -3]] → trace = 1
  • 3×3: [[1,2,3],[4,5,6],[7,8,9]] → trace = 15
  • 4×4 Identity: I₄ → trace = 4
  • Zero matrix: Any size → trace = 0

📐 Pro Tip: The trace is a quick way to check eigenvalue calculations. Sum your eigenvalues — they should equal the trace!

Press / to search operations