trace(): sum a matrix diagonal
trace(A) adds the main diagonal entries of a square matrix. For [[a,b],[c,d]], the trace is a+d.
Why it matters
Trace is invariant under a change of basis and equals the sum of eigenvalues, counted with multiplicity. It appears in linear systems, statistics, and matrix calculus.
Related matrix tools
Use det() for the determinant, transpose() to reflect a matrix, diag() to work with diagonal entries, and sum() for general aggregation. identity() has trace equal to its dimension.
Caveat
Trace requires a square matrix; check dimensions first with size().