Matrix Trace Calculator

Calculate the trace of a square matrix by summing its main diagonal entries.

Calculate matrix trace
Enter a square matrix to find its diagonal sum instantly.

Separate columns with commas and rows with semicolons.

About the matrix trace

The trace of a square matrix is the sum of the entries on its main diagonal, running from the upper-left corner to the lower-right corner. For a 2 by 2 matrix with diagonal values a and d, the trace is simply a plus d. Off-diagonal values do not contribute directly. This makes trace one of the fastest important matrix quantities to compute. Trace is defined only for square matrices because only they have a main diagonal that pairs every row with a corresponding column. The result is a scalar and may be positive, negative, or zero. A zero trace does not mean the matrix is a zero matrix or a singular matrix; positive and negative diagonal entries may simply cancel. The trace has several valuable algebraic properties. It is linear, so the trace of A plus B equals the trace of A plus the trace of B, and scaling a matrix scales its trace. It is also invariant under similarity transformations. Similar matrices represent the same linear transformation in different bases, yet their traces agree. This makes trace a useful coordinate-independent summary. Another key identity is that the trace of a product A times B equals the trace of B times A whenever both products are defined and square. Matrix multiplication itself is not commutative, but trace permits this cyclic rearrangement. For longer products, factors can be rotated cyclically without changing the trace, a fact used frequently in statistics, optimization, and quantum mechanics. The trace also equals the sum of a matrix's eigenvalues, counted with algebraic multiplicity, even when those eigenvalues are complex. It appears in characteristic polynomials, divergence calculations, covariance analysis, expected quadratic forms, and descriptions of quantum states. In differential equations, trace can help characterize local expansion or contraction of a dynamical system. This calculator validates that every row has the same length and that the matrix is square, then adds the diagonal entries directly. Integers, negative numbers, and decimals are accepted. Because only one addition per diagonal entry is needed, the method remains immediate even as matrix size grows. The displayed value is rounded only to remove insignificant floating-point noise.

Matrix trace examples

Only the main diagonal contributes to each result.

MatrixTraceExplanation
[[1,2],[3,4]]5Add diagonal entries 1 and 4.
[[2,1,0],[4,-3,8],[7,5,6]]5The diagonal sum is 2 minus 3 plus 6.
[[-2,0],[0,2]]0Opposite diagonal values cancel.

How to calculate matrix trace

  1. Enter a square matrix with commas between entries.
  2. Use semicolons to separate one row from the next.
  3. Click Calculate Trace to add the main diagonal.
  4. Read the resulting diagonal sum.

Frequently asked questions

What is the trace of a matrix?

Trace is the sum of entries on a square matrix's main diagonal. It produces one scalar value.

Can a rectangular matrix have a trace?

The standard matrix trace is defined only for square matrices. This ensures rows and columns represent the same dimensional space.

Does zero trace mean a matrix is singular?

No, trace and invertibility measure different properties. An invertible matrix can have trace zero.

How is trace related to eigenvalues?

Trace equals the sum of all eigenvalues counted with algebraic multiplicity. This remains true when some eigenvalues are complex.

Do off-diagonal entries affect trace?

They do not enter the direct diagonal sum. They can still affect other matrix properties such as eigenvectors and determinant.