Description Usage Arguments Details Value Examples
Trace of a matrix is the sum of the diagonal elements of the given matrix.
1 | tr(x)
|
x |
a matrix or a polynomial matrix |
If the given matrix is a polynomial matrix, the result will be a polynomial.
Returns the trace of the given matrix as a number or a polynomial.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # numerical matrices
m <- matrix(1:12, 3, 4)
## [,1] [,2] [,3] [,4]
## [1,] 1 4 7 10
## [2,] 2 5 8 11
## [3,] 3 6 9 12
tr(m) ## 15
# polynomial matrix
pm <- parse.polyMatrix(
"-3 + x^2, 2 + 4 x, -x^2",
" 1, 2, 3 + x",
" 2*x, 0, 2 - 3 x"
)
tr(pm) ## 1 - 3*x + x^2
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.