trace
Sum of the diagonal elements of a square matrix.
Category: Mathematics > Linear Algebra
Syntax
t = trace(A)
Returns sum(diag(A)).
Description
The trace is invariant under similarity transformations and satisfies trace(A*B) = trace(B*A) whenever both products are defined. Together with the determinant it gives the eigenvalues of a 2-by-2 matrix.
A non-square matrix is an error.
Input arguments
A- Square numeric matrix.
Output arguments
t- Scalar equal to the sum of the diagonal, which is also the sum of the eigenvalues of
A.
Example
Trace equals the sum of eigenvalues
A = magic(3);
trace(A)
sum(eig(A))
Output
ans = 15
ans = 15