powered by
pinv(A)
A
B
svd()
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 U <- s$u; V <- s$v X = V Dinv U'
Thus B is computed as s$v %*% diag(1/s$d) %*% t(s$u).
s$v %*% diag(1/s$d) %*% t(s$u)
MASS::ginv
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
Run the code above in your browser using DataLab