1*> \brief \b DLQT02
2*
3*  =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6*            http://www.netlib.org/lapack/explore-html/
7*
8*  Definition:
9*  ===========
10*
11*       SUBROUTINE DLQT02( M, N, K, A, AF, Q, L, LDA, TAU, WORK, LWORK,
12*                          RWORK, RESULT )
13*
14*       .. Scalar Arguments ..
15*       INTEGER            K, LDA, LWORK, M, N
16*       ..
17*       .. Array Arguments ..
18*       DOUBLE PRECISION   A( LDA, * ), AF( LDA, * ), L( LDA, * ),
19*      $                   Q( LDA, * ), RESULT( * ), RWORK( * ), TAU( * ),
20*      $                   WORK( LWORK )
21*       ..
22*
23*
24*> \par Purpose:
25*  =============
26*>
27*> \verbatim
28*>
29*> DLQT02 tests DORGLQ, which generates an m-by-n matrix Q with
30*> orthonornmal rows that is defined as the product of k elementary
31*> reflectors.
32*>
33*> Given the LQ factorization of an m-by-n matrix A, DLQT02 generates
34*> the orthogonal matrix Q defined by the factorization of the first k
35*> rows of A; it compares L(1:k,1:m) with A(1:k,1:n)*Q(1:m,1:n)', and
36*> checks that the rows of Q are orthonormal.
37*> \endverbatim
38*
39*  Arguments:
40*  ==========
41*
42*> \param[in] M
43*> \verbatim
44*>          M is INTEGER
45*>          The number of rows of the matrix Q to be generated.  M >= 0.
46*> \endverbatim
47*>
48*> \param[in] N
49*> \verbatim
50*>          N is INTEGER
51*>          The number of columns of the matrix Q to be generated.
52*>          N >= M >= 0.
53*> \endverbatim
54*>
55*> \param[in] K
56*> \verbatim
57*>          K is INTEGER
58*>          The number of elementary reflectors whose product defines the
59*>          matrix Q. M >= K >= 0.
60*> \endverbatim
61*>
62*> \param[in] A
63*> \verbatim
64*>          A is DOUBLE PRECISION array, dimension (LDA,N)
65*>          The m-by-n matrix A which was factorized by DLQT01.
66*> \endverbatim
67*>
68*> \param[in] AF
69*> \verbatim
70*>          AF is DOUBLE PRECISION array, dimension (LDA,N)
71*>          Details of the LQ factorization of A, as returned by DGELQF.
72*>          See DGELQF for further details.
73*> \endverbatim
74*>
75*> \param[out] Q
76*> \verbatim
77*>          Q is DOUBLE PRECISION array, dimension (LDA,N)
78*> \endverbatim
79*>
80*> \param[out] L
81*> \verbatim
82*>          L is DOUBLE PRECISION array, dimension (LDA,M)
83*> \endverbatim
84*>
85*> \param[in] LDA
86*> \verbatim
87*>          LDA is INTEGER
88*>          The leading dimension of the arrays A, AF, Q and L. LDA >= N.
89*> \endverbatim
90*>
91*> \param[in] TAU
92*> \verbatim
93*>          TAU is DOUBLE PRECISION array, dimension (M)
94*>          The scalar factors of the elementary reflectors corresponding
95*>          to the LQ factorization in AF.
96*> \endverbatim
97*>
98*> \param[out] WORK
99*> \verbatim
100*>          WORK is DOUBLE PRECISION array, dimension (LWORK)
101*> \endverbatim
102*>
103*> \param[in] LWORK
104*> \verbatim
105*>          LWORK is INTEGER
106*>          The dimension of the array WORK.
107*> \endverbatim
108*>
109*> \param[out] RWORK
110*> \verbatim
111*>          RWORK is DOUBLE PRECISION array, dimension (M)
112*> \endverbatim
113*>
114*> \param[out] RESULT
115*> \verbatim
116*>          RESULT is DOUBLE PRECISION array, dimension (2)
117*>          The test ratios:
118*>          RESULT(1) = norm( L - A*Q' ) / ( N * norm(A) * EPS )
119*>          RESULT(2) = norm( I - Q*Q' ) / ( N * EPS )
120*> \endverbatim
121*
122*  Authors:
123*  ========
124*
125*> \author Univ. of Tennessee
126*> \author Univ. of California Berkeley
127*> \author Univ. of Colorado Denver
128*> \author NAG Ltd.
129*
130*> \ingroup double_lin
131*
132*  =====================================================================
133      SUBROUTINE DLQT02( M, N, K, A, AF, Q, L, LDA, TAU, WORK, LWORK,
134     $                   RWORK, RESULT )
135*
136*  -- LAPACK test routine --
137*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
138*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
139*
140*     .. Scalar Arguments ..
141      INTEGER            K, LDA, LWORK, M, N
142*     ..
143*     .. Array Arguments ..
144      DOUBLE PRECISION   A( LDA, * ), AF( LDA, * ), L( LDA, * ),
145     $                   Q( LDA, * ), RESULT( * ), RWORK( * ), TAU( * ),
146     $                   WORK( LWORK )
147*     ..
148*
149*  =====================================================================
150*
151*     .. Parameters ..
152      DOUBLE PRECISION   ZERO, ONE
153      PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
154      DOUBLE PRECISION   ROGUE
155      PARAMETER          ( ROGUE = -1.0D+10 )
156*     ..
157*     .. Local Scalars ..
158      INTEGER            INFO
159      DOUBLE PRECISION   ANORM, EPS, RESID
160*     ..
161*     .. External Functions ..
162      DOUBLE PRECISION   DLAMCH, DLANGE, DLANSY
163      EXTERNAL           DLAMCH, DLANGE, DLANSY
164*     ..
165*     .. External Subroutines ..
166      EXTERNAL           DGEMM, DLACPY, DLASET, DORGLQ, DSYRK
167*     ..
168*     .. Intrinsic Functions ..
169      INTRINSIC          DBLE, MAX
170*     ..
171*     .. Scalars in Common ..
172      CHARACTER*32       SRNAMT
173*     ..
174*     .. Common blocks ..
175      COMMON             / SRNAMC / SRNAMT
176*     ..
177*     .. Executable Statements ..
178*
179      EPS = DLAMCH( 'Epsilon' )
180*
181*     Copy the first k rows of the factorization to the array Q
182*
183      CALL DLASET( 'Full', M, N, ROGUE, ROGUE, Q, LDA )
184      CALL DLACPY( 'Upper', K, N-1, AF( 1, 2 ), LDA, Q( 1, 2 ), LDA )
185*
186*     Generate the first n columns of the matrix Q
187*
188      SRNAMT = 'DORGLQ'
189      CALL DORGLQ( M, N, K, Q, LDA, TAU, WORK, LWORK, INFO )
190*
191*     Copy L(1:k,1:m)
192*
193      CALL DLASET( 'Full', K, M, ZERO, ZERO, L, LDA )
194      CALL DLACPY( 'Lower', K, M, AF, LDA, L, LDA )
195*
196*     Compute L(1:k,1:m) - A(1:k,1:n) * Q(1:m,1:n)'
197*
198      CALL DGEMM( 'No transpose', 'Transpose', K, M, N, -ONE, A, LDA, Q,
199     $            LDA, ONE, L, LDA )
200*
201*     Compute norm( L - A*Q' ) / ( N * norm(A) * EPS ) .
202*
203      ANORM = DLANGE( '1', K, N, A, LDA, RWORK )
204      RESID = DLANGE( '1', K, M, L, LDA, RWORK )
205      IF( ANORM.GT.ZERO ) THEN
206         RESULT( 1 ) = ( ( RESID / DBLE( MAX( 1, N ) ) ) / ANORM ) / EPS
207      ELSE
208         RESULT( 1 ) = ZERO
209      END IF
210*
211*     Compute I - Q*Q'
212*
213      CALL DLASET( 'Full', M, M, ZERO, ONE, L, LDA )
214      CALL DSYRK( 'Upper', 'No transpose', M, N, -ONE, Q, LDA, ONE, L,
215     $            LDA )
216*
217*     Compute norm( I - Q*Q' ) / ( N * EPS ) .
218*
219      RESID = DLANSY( '1', 'Upper', M, L, LDA, RWORK )
220*
221      RESULT( 2 ) = ( RESID / DBLE( MAX( 1, N ) ) ) / EPS
222*
223      RETURN
224*
225*     End of DLQT02
226*
227      END
228