Learn R Programming

fBasics (version 4041.97)

tr: Trace of a matrix

Description

Computes the trace of a matrix.

Usage

tr(x)

Arguments

x

a numeric matrix.

Details

tr computes the trace of a square matrix, i.e., the sum of its diagonal elements.

If the matrix is not square, tr returns NA.

References

Golub, van Loan, (1996); Matrix Computations, 3rd edition. Johns Hopkins University Press.

Examples

Run this code
## Create Pascal Matrix:
P = pascal(3)
P
  
tr(P)                                  

Run the code above in your browser using DataLab