Takes the traces of a matrix by extracting the diagonal entries and then summing over.

tr(x)

Arguments

x

Square matrix (\(Q \times Q\))

Value

Returns a single-value double.

See also

Examples


# Identity Matrix of size 4, gives trace of 4.
tr(diag(4))
#> [1] 4