Computes the MoorePenrose generalized inverse.
1 2 
mat 
a real matrix. 
tolerance 
A positive scalar which determines the tolerance for detecting zeroes among the singular values. 
rank 
Either 
method 
Character, one of 
Realvaluedness is not checked, neither is symmetry when method
= "chol"
.
A matrix, with an additional attribute named "rank"
containing
the numerically determined rank of the matrix.
David Firth and Heather Turner
Harville, D. A. (1997). Matrix Algebra from a Statistician's Perspective. New York: Springer.
Courrieu, P. (2005). Fast computation of MoorePenrose inverse matrices. Neural Information Processing 8, 25–29
ginv
1 2 3 4 5 6 7 8 9 10 11 12  A < matrix(c(1, 1, 0,
1, 1, 0,
2, 3, 4), 3, 3)
B < MPinv(A)
A %*% B %*% A  A # essentially zero
B %*% A %*% B  B # essentially zero
attr(B, "rank") # here 2
## demonstration that "svd" and "chol" deliver essentially the same
## results for symmetric matrices:
A < crossprod(A)
MPinv(A)  MPinv(A, method = "chol") ## (essentially zero)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.