Previous Next Contents Generated Index Doc Set Home



QR Factorization with Column Pivoting of a General Matrix

The subroutines described in this section compute a QR factorization with column pivoting of a general matrix A.

Calling Sequence

CALL DGEQPF 
(M, N, DA, LDA, JPIVOT, DTAU, DWORK, INFO)
CALL SGEQPF 
(M, N, SA, LDA, JPIVOT, STAU, SWORK, INFO)
CALL ZGEQPF 
(M, N, ZA, LDA, JPIVOT, ZTAU, ZWORK, DWORK2, INFO)
CALL CGEQPF 
(M, N, CA, LDA, JPIVOT, CTAU, CWORK, SWORK2, INFO)






void dgeqpf 
(int m, int n, double *da, int lda, int *jpivot, double 
*dtau, int *info)
void sgeqpf 
(int m, int n, float *sa, int lda, int *jpivot, float 
*stau, int *info)
void zgeqpf 
(int m, int n, doublecomplex *za, int lda, int *jpivot, 
doublecomplex *ztau, int *info)
void cgeqpf 
(int m, int n, complex *ca, int lda, int *jpivot, 
complex *ctau, int *info)

Arguments

M

Number of rows of the matrix A. M > 0.

N

Number of columns of the matrix A. N > 0.

xA

On entry, the matrix A.
On exit, A and TAU contain a QR factorization of the matrix A.

LDA

Leading dimension of the array A as specified in a dimension or type statement. LDA max(1, M).

JPIVOT

On entry, if JPIVOT(i) 0 for 1 i N then the ith 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.
On exit, if JPIVOT(i) = k, then the ith column of A was the kth column of A.

xTAU

On exit, the min(M, N) scalar factors of the elementary reflectors. The elementary reflectors in xTAU together with xA contain a QR factorization of the matrix A that can be used by other LAPACK subroutines that operate on the matrix A.

xWORK

Scratch array with a dimension of 3 × N for real subroutines or N for complex subroutines.

xWORK2

Scratch array with a dimension of 2 × N for complex subroutines.

INFO

On exit:

INFO = 0

Subroutine completed normally.

INFO < 0

The ith argument, where i = |INFO|, had an illegal value.

Sample Program




      PROGRAM TEST
      IMPLICIT NONE
C
      INTEGER           LDA, LDR, LDWORK, M, N
      PARAMETER        (M = 4)
      PARAMETER        (N = 3)
      PARAMETER        (LDA = M)
      PARAMETER        (LDR = N)
      PARAMETER        (LDWORK = 3 * N)
C
      DOUBLE PRECISION  A(LDA,N), R(LDR,N), TAU(N), WORK(LDWORK)
      INTEGER           ICOL, INFO, IPIVOT(N), IROW
C
      EXTERNAL          DCOPY, DGEQPF, DORGQR
      INTRINSIC         ABS
C
C     Initialize the array A to store the matrix A shown below.
C
C         1   6   2
C     A = 1  -2  -8
C         1  -2   4
C         1   6  14
C
      DATA A / 4*1.0D0, 6.0D0, -2.0D0, -2.0D0, 6.0D0,
     $         2.0D0, -8.0D0, 4.0D0, 1.4D1 /
      DATA IPIVOT / N*0 /
C
C     Print the initial value of A.
C
      PRINT 1000
      PRINT 1010, ((A(IROW,ICOL), ICOL = 1, N), IROW = 1, M)
C
C     Compute the QR factorization of A with pivoting.
C
      CALL DGEQPF (M, N, A, LDA, IPIVOT, TAU, WORK, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1020, ABS(INFO)
        STOP 1
      END IF
      DO 100, ICOL = 1, N
        CALL DCOPY (N, A(1,ICOL), 1, R(1,ICOL), 1)
  100 CONTINUE
C
C     Compute and print the matrix Q used in the QR factorization
C     of A.
C
      CALL DORGQR (M, N, N, A, LDA, TAU, WORK, LDWORK, INFO)
      IF (INFO .NE. 0) THEN
        PRINT 1030, ABS(INFO)
        STOP 2
      END IF
      PRINT 1040
      PRINT 1010, ((A(IROW,ICOL), ICOL = 1, N), IROW = 1, M)
      PRINT 1050
      DO 110, IROW = 1, N
        PRINT 1010, (0.0D0, ICOL = 1, IROW - 1),
     $              (R(IROW,ICOL), ICOL = IROW, N)
  110 CONTINUE
C
 1000 FORMAT (1X, 'A:')
 1010 FORMAT (3(3X, F8.4))
 1020 FORMAT (1X, 'Illegal value for argument #', I1,
     $        ' in DGEQPF.')
 1030 FORMAT (1X, 'Illegal value for argument #', I1,
     $        ' in DORGQR.')
 1040 FORMAT (/1X, 'Q:')
 1050 FORMAT (/1X, 'R:')
C
      END
 

Sample Output

 
 A:
     1.0000     6.0000     2.0000
     1.0000    -2.0000    -8.0000
     1.0000    -2.0000     4.0000
     1.0000     6.0000    14.0000



 Q:
    -0.1195    -0.8173    -0.2602
     0.4781    -0.1510    -0.7061
    -0.2390     0.5419    -0.6318
    -0.8367    -0.1244    -0.1858



 R:
   -16.7332    -6.2152    -0.7171
     0.0000    -6.4321    -0.5508
     0.0000     0.0000    -1.7839






Previous Next Contents Generated Index Doc Set Home