Obtain the trace of a matrix if the matrix is diagonal, otherwise raise an error.
h_tr(x)
x
(matrix) square matrix input.
matrix
The trace of the square matrix.