Function trace

trace(A) takes a square matrix $A$, and returns the trace $\text{tr}(A)$, equal to the sum of its diagonal entries.