Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pinv

Pseudoinverse or Generalized Inverse


Description

Computes the Moore-Penrose generalized inverse of a matrix.

Usage

pinv(A, tol=.Machine$double.eps^(2/3))

Arguments

A

matrix

tol

tolerance used for assuming an eigenvalue is zero.

Details

Compute the generalized inverse B of a matrix A using the singular value decomposition svd(). This generalized invers is characterized by this equation: A %*% B %*% A == A

The pseudoinverse B solves the problem to minimize |A x - b| by setting x = B b

s <- svd(A)
D <- diag(s\$d)
Dinv <- diag(1/s\$d)
U <- s\$u; V <- s\$v
X = V Dinv t(U)

Thus B is computed as s$v %*% diag(1/s$d) %*% t(s$u).

Value

The pseudoinverse of matrix A.

Note

The pseudoinverse or ‘generalized inverse’ is also provided by the function ginv() in package ‘MASS’. It is included in a somewhat simplified way to be independent of that package.

References

Ben-Israel, A., and Th. N. E. Greville (2003). Generalized Inverses - Theory and Applications. Springer-Verlag, New York.

See Also

MASS::ginv

Examples

A <- matrix(c(7,6,4,8,10,11,12,9,3,5,1,2), 3, 4)
b <- apply(A, 1, sum)  # 32 16 20  row sum
x <- pinv(A) %*% b
A %*% x              #=> 32 16 20  as column vector

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.