psolve | R Documentation |
This generic function solves the equation a %*% x = b
for x
, where b
can be either a vector or a matrix. This implementation is similar to solve
, but uses a pseudo-inverse if the system is computationally singular.
psolve(a, b, tol)
a |
a rectangular numeric matrix containing the coefficients of the linear system. |
b |
a numeric vector or matrix giving the right-hand side(s) of the linear system. If missing, |
tol |
the tolerance for detecting linear dependencies in the columns of a. The default is |
If a
is a symmetric matrix, eigen
is used to compute the (pseudo-)inverse. This assumes that a
is a positive semi-definite matrix. Otherwise svd
is used to compute the (pseudo-)inverse for rectangular matrices.
If b
is missing, returns the (pseudo-)inverse of a
. Otherwise returns psolve(a) %*% b
.
The pseudo-inverse is calculated by inverting the eigen/singular values that are greater than the first value multiplied by tol * min(dim(a))
.
Nathaniel E. Helwig <helwig@umn.edu>
Moore, E. H. (1920). On the reciprocal of the general algebraic matrix. Bulletin of the American Mathematical Society, 26, 394-395. doi: 10.1090/S0002-9904-1920-03322-7
Penrose, R. (1955). A generalized inverse for matrices. Mathematical Proceedings of the Cambridge Philosophical Society, 51(3), 406-413. doi: 10.1017/S0305004100030401
msqrt
# generate X set.seed(0) X <- matrix(rnorm(100), 20, 5) X <- cbind(X, rowSums(X)) # pseudo-inverse of X (dim = 6 by 20) Xinv <- psolve(X) # pseudo-inverse of crossprod(X) (dim = 6 by 6) XtXinv <- psolve(crossprod(X))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.