The IMSL_QRFAC procedure computes the QR factorization of a real matrix A.

The IMSL_QRFAC procedure 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 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 ... Q0AP = 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.

When computing the factorization, the procedure computes the QR factorization of AP with P defined by the input pivot and by column pivoting among “free” columns. Before the factorization, initial columns are moved to the beginning of the array A and the final columns to the end. Neither initial nor final columns are permuted further during the computation. Only the free columns are moved.

## Examples

Using the same data as the first example given for the IMSL_QRSOL function, this sample computes the QR factorization of the coefficient. Using keywords, the factorization is returned in the full matrices, rather than the default condensed format.

`RM, a, 4, 3`
`; Define the coefficient matrix.`
`row 0: 1 2 4`
`row 1: 1 4 16`
`row 2: 1 6 36`
`row 3: 1 8 64`
`IMSL_QRFAC, a, pvt, Q = q, R = r, AP = ap`
`; Call IMSL_QRFAC using keywords Q, R, and AP.`
`PM, q, Title = 'Q', Format = '(4f12.6)'`

Result:

`Q`
`  -0.053149 -0.542171 0.808224 -0.223607`
`  -0.212598 -0.657436 -0.269408 0.670820`
`  -0.478345 -0.345794 -0.449013 -0.670820`
`  -0.850390 0.392754 0.269408 0.223607`
`PM, r, Title = 'R', Format = '(3f12.6)'`

Result:

`R`
`  -75.259552 -10.629880 -1.594482`
`  0.000000 -2.646819 -1.152647`
`  0.000000 0.000000 0.359211`
`  0.000000 0.000000 0.000000`
`PM, pvt, Title = 'Pvt'`

Result:

`Pvt`
`3`
`2`
`1`
`PM, q # r - ap, Title = 'Residual', Format = '(3f12.6)'`
`Residual`
`  -0.000004 -0.000001 -0.000000`
`  0.000000 -0.000000 0.000000`
`  0.000000 -0.000000 -0.000000`
`  0.000000 -0.000000 -0.000000`

## Syntax

IMSL_QRFAC, A [, Pivot [, Auxqr, Qr] [, AP=variable] [, BASIS=variable] [, /DOUBLE] [, Q=variable] [, R=variable] [, TOLERANCE=value]]

## Arguments

### A

A two-dimensional matrix containing the coefficient matrix. Element A(i,j) contains the j-th coefficient of the i-th equation.

### Pivot

A one-dimensional matrix containing the desired variable order and usage

information.

• 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.) Default: pivot (*) = 0
• On output, pivot (k) contains the index of the column of the original matrix that has been interchanged into column k.

### Auxqr (optional)

Matrix containing the scalars τk of the Householder transformations that define the decomposition.

### Qr (optional)

Matrix containing the Householder transformations that define the decomposition.

## Keywords

### AP (optional)

Named variable into which the product AP of the identity AP = QR is stored. This keyword is useful when attempting to compute the residual AP – QR.

### BASIS (optional)

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.

### DOUBLE (optional)

If present and nonzero, double precision is used.

### Q (optional)

Named variable in which the two-dimensional matrix containing the orthogonal matrix of the AP = QR factorization is stored.

### R (optional)

Named variable in which the two-dimensional matrix containing the upper-triangular matrix of the AP = QR decomposition is stored.

### TOLERANCE (optional)

Nonnegative tolerance used to determine the subset of columns of A to be included in the solution. Default: SQRT(ε), where ε is machine precision.

## Errors

### Fatal Errors

MATH_SINGULAR_TRI_MATRIX: Input triangular matrix is singular. The index of the first zero diagonal term is #.

## Version History

 6.4 Introduced