Calculates the trace of a square numeric matrix, i.e., the sum of its diagonal elements
tr(X)
X
a numeric matrix
a numeric value, the sum of diag(X)
diag(X)
X <- matrix(1:9, 3, 3) tr(X)