QRSOL Function
Solves a real linear least-squares problem Ax = b.
Usage
result = QRSOL(b[, a])
Input Parameters
b—Matrix containing the right-hand side.
a—(Optional) Two-dimensional matrix containing the coefficient matrix. Element A (i, j) contains the jth coefficient of the ith equation.
Returned Value
result—The solution, x, of the linear least-squares problem Ax = b.
Input Keywords
Auxqr—Specifies a named variable in which the matrix containing the scalars τk of the Householder transformations that define the decomposition, as computed in the procedure QRFAC, is stored. Keywords Auxqr, Pivot, and Qr must be used together.
Double—If present and nonzero, double precision is used.
Qr—Specifies a named variable which stores the matrix containing Householder transformations that define the decomposition, as computed in the procedure QRFAC. Keywords Auxqr, Pivot, and Qr must be used together.
Tolerance—Nonnegative tolerance used to determine the subset of columns of A to be included in the solution. Default: Tolerance = SQRT(ε), where ε is machine precision
Output Keywords
Residual—Specifies a named variable in which the matrix containing the residual vector b – Ax is stored.
Basis—Named variable containing an integer specifying the number of columns used in the solution. The value Basis = k, if |rk,k| < Tolerance*|r0,0| and |ri,i| Tolerance*|r0,0| for i = 0, 1, ..., k – 1. For more information on the use of this option, see the Discussion section below.
Input/Output Keywords
Pivot—Specifies a named variable in which the array containing the desired variable order and usage information is stored. Keywords Auxqr, Pivot, and Qr must be used together.
*On input, if Pivot (k) > 0, then column k of A is an initial column. If Pivot (k) = 0, then the column of A is a free column and can be interchanged in the column pivoting. If Pivot (k) < 0, then column k of A is a final column. If all columns are specified as initial (or final) columns, then no pivoting is performed. (The permutation matrix P is the identity matrix in this case.)
*On output, Pivot (k) contains the index of the column of the original matrix that has been interchanged into column k.
*Default: Pivot (*) = 0
 
note
If QRSOL is used to solve a problem previously factored in procedure QRFAC, the matrix specified by Pivot should contain the same information that parameter pivot of QRFAC contained upon output.
Discussion
QRSOL solves a system of linear least-squares problems Ax = b with column pivoting. It computes a QR factorization of the matrix AP, where P is the permutation matrix defined by the pivoting, and computes the smallest integer k satisfying |rk,k| < Tolerance*|r0,0| to the output keyword Basis.
Householder transformations:
Qk = IτkukukT, k = 0, ..., min(m – 1, n) – 1
compute the factorization. The decomposition is computed in the form Qmin (m – 1, n) – 1 ... Q0 AP = R, so AP = QR where Q = Q0 ... Qmin (m – 1, n) – 1. Since each Householder vector uk has zeros in the first k + 1 entries, it is stored as part of column k of Qr. The upper-trapezoidal matrix R is stored in the upper-trapezoidal part of the first min(m, n) rows of Qr. The solution x to the least-squares problem is computed by solving the upper-triangular system of linear equations R (0:k, 0:k) y (0:k) = (QTb) (0:k) with k = Basis – 1. The solution is completed by setting y (k:n – 1) to zero and rearranging the variables, x = Py.
If Qr and Auxqr are specified, then the function computes the least-squares solution to Ax = b given the QR factorization previously defined. There are Basis columns used in the solution. Hence, in the case that all columns are free, x is computed as described in the default case.
Example
This example illustrates the least-squares solution of four linear equations in three unknowns by using column pivoting. This is equivalent to least-squares quadratic polynomial fitting to four data values. The polynomial is written as p(t) = x0 + tx1 + t2x2 and the data pairs (ti, bi ), ti = 2(i + 1), i = 0, 1, 2, 3. The solution to Ax = b is returned by function QRSOL.
; Define the coefficient matrix.
RM, a, 4, 3
row 0:  1 2 4
row 1:  1 4 16
row 2:  1 6 36
row 3:  1 8 64
; Define the right-hand side.
RM, b, 4, 1
row 0:  4.999
row 1:  9.001
row 2:  12.999
row 3:  17.001
; Call QRSOL.
x = QRSOL(b, a)
PM, x, Title = 'Solution', Format = '(f8.5)'
; PV-WAVE prints the following:
; Solution
; 0.99900
; 2.00020
; 0.00000
PM, a # x - b, Title = 'Residual', Format = '(f10.7)'
; PV-WAVE prints the following:
; Residual
; 0.0004015
; -0.0011997
; 0.0012007
; -0.0004005
Fatal Errors
MATH_SINGULAR_TRI_MATRIX—Input triangular matrix is singular. The index of the first zero diagonal term is #.