Calculates the trace of a matrix
tr(M)
M
a matrix
returns the sum of the diagonal elements
Michael Friendly
M <- matrix(sample(1:9), 3,3) tr(M)