The trace of a square matrix is the sum of the diagonal elements.

tr(x, ...)

# S3 method for default
tr(x, ...)

Arguments

x

If yac_symbol treat as such, else call tr.default().

...

further arguments passed to tr.default()

Examples

(x <- matrix(1:4, ncol = 2))
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
tr(x)
#> [1] 5
tr(ysym(x))
#> y: 5