Learn R Programming

Matrix (version 0.999375-42)

rankMatrix: Rank of a Matrix

Description

Compute the rank of matrix, a well-defined functional in theory, somewhat ambigous in practice. We provide several methods, the default corresponding to Matlab's definition.

Usage

rankMatrix(x, tol = NULL,
           method = c("tolNorm2", "qrLINPACK", "useGrad", "maybeGrad"),
           sval = svd(x, 0, 0)$d)

Arguments

x
numeric matrix, of dimension $n \times m$, say.
tol
nonnegative number specifying a tolerance for practically zero with specific meaning depending on method; by default, max(dim(x)) * .Machine$double.eps * abs(max(sval))
method
a character string specifying the computational method, can be abbreviated: [object Object],[object Object],[object Object],[object Object]
sval
numeric vector of non-increasing singular values of x; typically unspecified and computed from x.

Value

  • positive integer in 1:min(dim(x)), with attributes detailing the method used.

See Also

qr, svd.

Examples

Run this code
rankMatrix(cbind(1, 0, 1:3)) # 2

(meths <- eval(formals(rankMatrix)$method))

## a "border" case:
H12 <- Hilbert(12)
rankMatrix(H12, tol = 1e-20) # 12;  but  11  with default method & tol.
sapply(meths, function(.m.) rankMatrix(H12, method = .m.))
## tolNorm2 qrLINPACK   useGrad maybeGrad
##       11        12        11        11

Run the code above in your browser using DataLab