Matrix Operations
10+ solvers available
Basic Operations
Multiplication
Properties
Advanced
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.
Learn About Trace
Understanding the concepts behind the calculations.
📑 Quick Navigation
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:
Only square matrices have a trace!
Visual Example:
The red entries (diagonal) are summed.
The Formula
For 2×2 Matrices
For 3×3 Matrices
For 4×4 Matrices
💡 Important: Off-diagonal entries (all entries NOT on the diagonal) DO NOT affect the trace!
Properties of Trace
1. Linearity
The trace is a linear function.
2. Trace of Transpose
Transposing doesn't change diagonal entries.
3. Trace of Product (Cyclic Property)
This holds even when AB ≠ BA!
4. Trace of Scalar Multiple
Factor out constants.
5. Trace of Identity
Identity matrix has n ones on diagonal.
6. Trace and Similarity
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:
Step 1: Identify diagonal entries: a₁₁ = 4, a₂₂ = -3
Step 2: Add them together:
Answer: The trace is 1
Example 2: 3×3 Matrix
Problem: Find the trace of B:
Step 1: Identify diagonal entries:
- b₁₁ = 2
- b₂₂ = -4
- b₃₃ = 7
Step 2: Sum them:
Answer: The trace is 5
Example 3: Off-Diagonal Entries Don't Matter
Problem: Show that trace ignores off-diagonal entries.
✓ 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)
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!
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
- Including off-diagonal entries: Only diagonal entries count! Off-diagonals are ignored.
- Applying to non-square matrices: Trace is only defined for SQUARE matrices.
- Confusing trace with determinant: Trace sums diagonal, determinant is entirely different.
- Wrong order for product trace: Remember tr(AB) = tr(BA), but tr(ABC) = tr(BCA) = tr(CAB) (cyclic).
- 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
-
Find the trace of:
$$ A = \begin{bmatrix} 3 & -2 \\\\ 5 & 7 \end{bmatrix} $$ -
Find the trace of:
$$ B = \begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9 \end{bmatrix} $$ -
What is tr(I₄) (4×4 identity matrix)?
Intermediate
-
If λ₁ = 3, λ₂ = 5, λ₃ = -2 are eigenvalues of a 3×3 matrix A, what is tr(A)?
-
For
A = [[2, 1], [0, 3]]andB = [[1, 2], [1, 0]], verify that tr(AB) = tr(BA). -
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:
- Enter your square matrix - Any size up to 10×10
- 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!