Purpose
To compute (optionally) a rank-revealing QR factorization of a real general M-by-N matrix A, which may be rank-deficient, and estimate its effective rank using incremental condition estimation. The routine uses a QR factorization with column pivoting: A * P = Q * R, where R = [ R11 R12 ], [ 0 R22 ] with R11 defined as the largest leading submatrix whose estimated condition number is less than 1/RCOND. The order of R11, RANK, is the effective rank of A. MB03OD does not perform any scaling of the matrix A.Specification
SUBROUTINE MB03OD( JOBQR, M, N, A, LDA, JPVT, RCOND, SVLMAX, TAU, $ RANK, SVAL, DWORK, LDWORK, INFO ) C .. Scalar Arguments .. CHARACTER JOBQR INTEGER INFO, LDA, LDWORK, M, N, RANK DOUBLE PRECISION RCOND, SVLMAX C .. Array Arguments .. INTEGER JPVT( * ) DOUBLE PRECISION A( LDA, * ), SVAL( 3 ), TAU( * ), DWORK( * )Arguments
Mode Parameters
JOBQR CHARACTER*1 = 'Q': Perform a QR factorization with column pivoting; = 'N': Do not perform the QR factorization (but assume that it has been done outside).Input/Output Parameters
M (input) INTEGER The number of rows of the matrix A. M >= 0. N (input) INTEGER The number of columns of the matrix A. N >= 0. A (input/output) DOUBLE PRECISION array, dimension ( LDA, N ) On entry with JOBQR = 'Q', the leading M by N part of this array must contain the given matrix A. On exit with JOBQR = 'Q', the leading min(M,N) by N upper triangular part of A contains the triangular factor R, and the elements below the diagonal, with the array TAU, represent the orthogonal matrix Q as a product of min(M,N) elementary reflectors. On entry and on exit with JOBQR = 'N', the leading min(M,N) by N upper triangular part of A contains the triangular factor R, as determined by the QR factorization with pivoting. The elements below the diagonal of A are not referenced. LDA INTEGER The leading dimension of the array A. LDA >= max(1,M). JPVT (input/output) INTEGER array, dimension ( N ) On entry with JOBQR = 'Q', if JPVT(i) <> 0, the i-th column of A is an initial column, otherwise it is a free column. Before the QR factorization of A, all initial columns are permuted to the leading positions; only the remaining free columns are moved as a result of column pivoting during the factorization. For rank determination it is preferable that all columns be free. On exit with JOBQR = 'Q', if JPVT(i) = k, then the i-th column of A*P was the k-th column of A. Array JPVT is not referenced when JOBQR = 'N'. RCOND (input) DOUBLE PRECISION RCOND is used to determine the effective rank of A, which is defined as the order of the largest leading triangular submatrix R11 in the QR factorization with pivoting of A, whose estimated condition number is less than 1/RCOND. RCOND >= 0. NOTE that when SVLMAX > 0, the estimated rank could be less than that defined above (see SVLMAX). SVLMAX (input) DOUBLE PRECISION If A is a submatrix of another matrix B, and the rank decision should be related to that matrix, then SVLMAX should be an estimate of the largest singular value of B (for instance, the Frobenius norm of B). If this is not the case, the input value SVLMAX = 0 should work. SVLMAX >= 0. TAU (output) DOUBLE PRECISION array, dimension ( MIN( M, N ) ) On exit with JOBQR = 'Q', the leading min(M,N) elements of TAU contain the scalar factors of the elementary reflectors. Array TAU is not referenced when JOBQR = 'N'. RANK (output) INTEGER The effective (estimated) rank of A, i.e. the order of the submatrix R11. SVAL (output) DOUBLE PRECISION array, dimension ( 3 ) The estimates of some of the singular values of the triangular factor R: SVAL(1): largest singular value of R(1:RANK,1:RANK); SVAL(2): smallest singular value of R(1:RANK,1:RANK); SVAL(3): smallest singular value of R(1:RANK+1,1:RANK+1), if RANK < MIN( M, N ), or of R(1:RANK,1:RANK), otherwise. If the triangular factorization is a rank-revealing one (which will be the case if the leading columns were well- conditioned), then SVAL(1) will also be an estimate for the largest singular value of A, and SVAL(2) and SVAL(3) will be estimates for the RANK-th and (RANK+1)-st singular values of A, respectively. By examining these values, one can confirm that the rank is well defined with respect to the chosen value of RCOND. The ratio SVAL(1)/SVAL(2) is an estimate of the condition number of R(1:RANK,1:RANK).Workspace
DWORK DOUBLE PRECISION array, dimension ( LDWORK ) On exit, if INFO = 0, DWORK(1) returns the optimal value of LDWORK. LDWORK INTEGER The length of the array DWORK. LDWORK >= 3*N + 1, if JOBQR = 'Q'; LDWORK >= max( 1, 2*min( M, N ) ), if JOBQR = 'N'. For good performance when JOBQR = 'Q', LDWORK should be larger. Specifically, LDWORK >= 2*N + ( N + 1 )*NB, where NB is the optimal block size for the LAPACK Library routine DGEQP3. If LDWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of the DWORK array, returns this value as the first entry of the DWORK array, and no error message related to LDWORK is issued by XERBLA.Error Indicator
INFO INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value.Method
The routine computes or uses a QR factorization with column pivoting of A, A * P = Q * R, with R defined above, and then finds the largest leading submatrix whose estimated condition number is less than 1/RCOND, taking the possible positive value of SVLMAX into account. This is performed using the LAPACK incremental condition estimation scheme and a slightly modified rank decision test.Further Comments
NoneExample
Program Text
* MB03OD EXAMPLE PROGRAM TEXT * Copyright (c) 2002-2017 NICONET e.V. * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 ) INTEGER NIN, NOUT PARAMETER ( NIN = 5, NOUT = 6 ) INTEGER NMAX, MMAX PARAMETER ( NMAX = 10, MMAX = 10 ) INTEGER LDA PARAMETER ( LDA = NMAX ) INTEGER LDTAU PARAMETER ( LDTAU = MIN(MMAX,NMAX) ) INTEGER LDWORK PARAMETER ( LDWORK = 3*NMAX + 1 ) * .. Local Scalars .. CHARACTER*1 JOBQR INTEGER I, INFO, J, M, N, RANK DOUBLE PRECISION RCOND, SVAL(3), SVLMAX * .. * .. Local Arrays .. DOUBLE PRECISION A(LDA,NMAX), DWORK(LDWORK), TAU(LDTAU) INTEGER JPVT(NMAX) * .. External Subroutines .. EXTERNAL MB03OD * .. Intrinsic Functions .. INTRINSIC MIN * .. Executable Statements .. * WRITE ( NOUT, FMT = 99999 ) * Skip the heading in the data file and read the data. READ ( NIN, FMT = '()' ) READ ( NIN, FMT = * ) M, N, JOBQR, RCOND, SVLMAX IF ( N.LT.0 .OR. N.GT.NMAX ) THEN WRITE ( NOUT, FMT = 99972 ) N ELSE IF ( M.LT.0 .OR. M.GT.MMAX ) THEN WRITE ( NOUT, FMT = 99971 ) M ELSE READ ( NIN, FMT = * ) ( ( A(I,J), J = 1,N ), I = 1,M ) * QR with column pivoting. DO 10 I = 1, N JPVT(I) = 0 10 CONTINUE CALL MB03OD( JOBQR, M, N, A, LDA, JPVT, RCOND, SVLMAX, TAU, $ RANK, SVAL, DWORK, LDWORK, INFO ) * IF ( INFO.NE.0 ) THEN WRITE ( NOUT, FMT = 99998 ) INFO ELSE WRITE ( NOUT, FMT = 99995 ) RANK WRITE ( NOUT, FMT = 99994 ) ( JPVT(I), I = 1,N ) WRITE ( NOUT, FMT = 99993 ) ( SVAL(I), I = 1,3 ) END IF END IF END IF * STOP * 99999 FORMAT (' MB03OD EXAMPLE PROGRAM RESULTS',/1X) 99998 FORMAT (' INFO on exit from MB03OD = ',I2) 99995 FORMAT (' The rank is ',I5) 99994 FORMAT (' Column permutations are ',/(20(I3,2X))) 99993 FORMAT (' SVAL vector is ',/(20(1X,F10.4))) 99972 FORMAT (/' N is out of range.',/' N = ',I5) 99971 FORMAT (/' M is out of range.',/' M = ',I5) ENDProgram Data
MB03OD EXAMPLE PROGRAM DATA 6 5 Q 5.D-16 0.0 1. 2. 6. 3. 5. -2. -1. -1. 0. -2. 5. 5. 1. 5. 1. -2. -1. -1. 0. -2. 4. 8. 4. 20. 4. -2. -1. -1. 0. -2.Program Results
MB03OD EXAMPLE PROGRAM RESULTS The rank is 4 Column permutations are 4 3 1 5 2 SVAL vector is 22.7257 1.4330 0.0000