Learn R Programming

robustbase (version 0.99-4-1)

rankMM: Simple Matrix Rank

Description

Compute the rank of a matrix A in simple way, based on the SVD, svd(), and “the same as Matlab”.

Usage

rankMM(A, tol = NULL, sv = svd(A, 0, 0)$d)

Value

an integer from the set 0:min(dim(A)).

Arguments

A

a numerical matrix, maybe non-square. When sv is specified, only dim(A) is made use of.

tol

numerical tolerance (compared to singular values). By default, when NULL, the tolerance is determined from the maximal value of sv and the computer epsilon.

sv

vector of non-increasing singular values of A, (to be passed if already known).

Author

Martin Maechler, Date: 7 Apr 2007

See Also

There are more sophisticated proposals for computing the rank of a matrix; for a couple of those, see rankMatrix in the Matrix package.

Examples

Run this code
rankMM # - note the simple function definition

hilbert <- function(n) { i <- seq_len(n); 1/outer(i - 1L, i, "+") }
hilbert(4)
H12 <- hilbert(12)
rankMM(H12)        # 11 - numerically more realistic
rankMM(H12, tol=0) # -> 12
## explanation :
round(log10(svd(H12, 0,0)$d), 1)

Run the code above in your browser using DataLab