# Lease-squares Solution and QR Factorization

Least-squares solutions are usually computed for an over-determined system of linear equations Am x n x = b, where m > n. A least-squares solution x minimizes the Euclidean length of the residual vector r = Ax – b. The IMSL_QRSOL function computes a unique least-squares solution for x when A has full-column rank. If A is rank-deficient, then the base solution for some variables is computed. These variables consist of the resulting columns after the interchanges. The QR decomposition, with column interchanges or pivoting, is computed such that AP = QR. Here, Q is orthogonal, R is upper-trapezoidal with its diagonal elements nonincreasing in magnitude, and P is the permutation matrix determined by the pivoting. The base solution xB is obtained by solving R(PT)x = QTb for the base variables. You can compute the QR factorization of a matrix A, such that AP = QR with a user-specified P, using the IMSL_QRFAC procedure.