Previous Next Contents Generated Index Doc Set Home



Generation of Q Defined in QR Factorization

The subroutines described in this section generate a matrix Q with orthonormal columns that was defined in a QR factorization computed by xGEQRF.

Calling Sequence

CALL DORGQR 
(M, N, K, DA, LDA, DTAU, DWORK, LDWORK, INFO)
CALL SORGQR 
(M, N, K, SA, LDA, STAU, SWORK, LDWORK, INFO)






void dorgqr 
(int m, int n, int k, double *da, int lda, double *dtau, 
int *info)
void sorgqr 
(int m, int n, int k, float *sa, int lda, float *stau, 
int *info)

Arguments

M

Number of rows of the matrix Q. M 0.

N

Number of columns of the matrix Q. M N 0.

K

Number of elementary reflectors whose product defines the matrix Q. N K 0.

xA

On entry, A and TAU contain the QR factorization of the matrix A as computed by xGEQRF.
On exit, the M×N matrix Q.

LDA

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

xTAU

TAU(i) contains the scalar factor of the elementary reflector H(i) for 1 i K, as computed by xGEQRF.

xWORK

Scratch array with a dimension of LDWORK.

LDWORK

Leading dimension of the array WORK as specified in a dimension or type statement. LDWORK max(1, N).

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 = N)
C
      DOUBLE PRECISION  A(LDA,N), R(LDR,N), TAU(N), WORK(LDWORK)
      INTEGER           ICOL, INFO, IROW
C
      EXTERNAL          DCOPY, DGEQRF, 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 /
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.
C
      CALL DGEQRF (M, N, A, LDA, TAU, WORK, LDWORK, 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 DGEQRF.')
 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.5000     0.5000     0.5000
    -0.5000    -0.5000     0.5000
    -0.5000    -0.5000    -0.5000
    -0.5000     0.5000    -0.5000



 R:
    -2.0000    -4.0000    -6.0000
     0.0000     8.0000    10.0000
     0.0000     0.0000   -12.0000






Previous Next Contents Generated Index Doc Set Home