Solve and Pseudo-Inverse with QR Decomposition

DESCRIPTION:
Given the QR decomposition of a matrix, either solves a system of linear equations with that matrix as coefficient matrix (in the least-squares sense if the system is underdetermined) or else computes the pseudo-inverse of the matrix.

USAGE:
solve.qr.Matrix(a, b, tol=0)

REQUIRED ARGUMENTS:
a:
An object of class qr.Matrix, representing the QR decomposition of a matrix.

OPTIONAL ARGUMENTS:
b:
A matrix or vector. If transpose=T The number of rows of b must equal the number of rows of a, while if transpose=F the number of rows of b must equal the number of columns of a.
tol:
Tolerance for reciprocal condition estimation. If tol is negative, no condition estimation is done. Otherwise, the reciprocal one norm condition estimate is computed and the solve or inverse computation is done only if the condition estimate is greater than tol. By default tol = 0.
transpose:
A logical variable indicating whether or not the transpose (conjugate transpose if complex) of a is to be used in the solve or inverse operation. The default is to use the untransposed matrix. The method does not allow a solve using the transpose of an underdetermined system.

VALUE:
If A is the matrix whose QR decomposition is represented by a, an object of class Matrix" is returned that is a least-squares solution x to the system of equations A %*% x = b if A has at least as many rows as columns and a basic solution to the system of equations if A has fewer rows than columns. If b is not supplied, the pseudo-inverse of A is returned. Attributes include a copy of the call to solve, and the one norm reciprocal condition estimate if tol is nonnegative.

DETAILS:
Can be used for matrices that are rank-deficient, i.e., whose rank is less than their minimum dimension.

REFERENCES:
Golub, G. H., and C. F. Van Loan (1989), Matrix Computations, 2nd edition, Johns Hopkins, Baltimore.

SEE ALSO:
rcond.qr.Matrix , solve , solve.Matrix , solve.svd.Matrix .

EXAMPLES:
m <- sample(1:9, 1); n <- sample(1:9, 1)
a <- Matrix( sample(-9:9, m*n, replace = T), nrow = m, ncol = n)
b <- rnorm(m)
z <- qr(a)                               # QR decomposition of a
if (m > n) t(a) %*% (a %*% solve(a,b) - b) else a %*% solve(a,b) - b