3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SGGHRD + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgghrd.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgghrd.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgghrd.f">
21 * SUBROUTINE SGGHRD( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q,
24 * .. Scalar Arguments ..
25 * CHARACTER COMPQ, COMPZ
26 * INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N
28 * .. Array Arguments ..
29 * REAL A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
39 *> SGGHRD reduces a pair of real matrices (A,B) to generalized upper
40 *> Hessenberg form using orthogonal transformations, where A is a
41 *> general matrix and B is upper triangular. The form of the
42 *> generalized eigenvalue problem is
44 *> and B is typically made upper triangular by computing its QR
45 *> factorization and moving the orthogonal matrix Q to the left side
48 *> This subroutine simultaneously reduces A to a Hessenberg matrix H:
50 *> and transforms B to another upper triangular matrix T:
52 *> in order to reduce the problem to its standard form
56 *> The orthogonal matrices Q and Z are determined as products of Givens
57 *> rotations. They may either be formed explicitly, or they may be
58 *> postmultiplied into input matrices Q1 and Z1, so that
60 *> Q1 * A * Z1**T = (Q1*Q) * H * (Z1*Z)**T
62 *> Q1 * B * Z1**T = (Q1*Q) * T * (Z1*Z)**T
64 *> If Q1 is the orthogonal matrix from the QR factorization of B in the
65 *> original equation A*x = lambda*B*x, then SGGHRD reduces the original
66 *> problem to generalized Hessenberg form.
74 *> COMPQ is CHARACTER*1
75 *> = 'N': do not compute Q;
76 *> = 'I': Q is initialized to the unit matrix, and the
77 *> orthogonal matrix Q is returned;
78 *> = 'V': Q must contain an orthogonal matrix Q1 on entry,
79 *> and the product Q1*Q is returned.
84 *> COMPZ is CHARACTER*1
85 *> = 'N': do not compute Z;
86 *> = 'I': Z is initialized to the unit matrix, and the
87 *> orthogonal matrix Z is returned;
88 *> = 'V': Z must contain an orthogonal matrix Z1 on entry,
89 *> and the product Z1*Z is returned.
95 *> The order of the matrices A and B. N >= 0.
107 *> ILO and IHI mark the rows and columns of A which are to be
108 *> reduced. It is assumed that A is already upper triangular
109 *> in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are
110 *> normally set by a previous call to SGGBAL; otherwise they
111 *> should be set to 1 and N respectively.
112 *> 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
117 *> A is REAL array, dimension (LDA, N)
118 *> On entry, the N-by-N general matrix to be reduced.
119 *> On exit, the upper triangle and the first subdiagonal of A
120 *> are overwritten with the upper Hessenberg matrix H, and the
121 *> rest is set to zero.
127 *> The leading dimension of the array A. LDA >= max(1,N).
132 *> B is REAL array, dimension (LDB, N)
133 *> On entry, the N-by-N upper triangular matrix B.
134 *> On exit, the upper triangular matrix T = Q**T B Z. The
135 *> elements below the diagonal are set to zero.
141 *> The leading dimension of the array B. LDB >= max(1,N).
146 *> Q is REAL array, dimension (LDQ, N)
147 *> On entry, if COMPQ = 'V', the orthogonal matrix Q1,
148 *> typically from the QR factorization of B.
149 *> On exit, if COMPQ='I', the orthogonal matrix Q, and if
150 *> COMPQ = 'V', the product Q1*Q.
151 *> Not referenced if COMPQ='N'.
157 *> The leading dimension of the array Q.
158 *> LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise.
163 *> Z is REAL array, dimension (LDZ, N)
164 *> On entry, if COMPZ = 'V', the orthogonal matrix Z1.
165 *> On exit, if COMPZ='I', the orthogonal matrix Z, and if
166 *> COMPZ = 'V', the product Z1*Z.
167 *> Not referenced if COMPZ='N'.
173 *> The leading dimension of the array Z.
174 *> LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise.
180 *> = 0: successful exit.
181 *> < 0: if INFO = -i, the i-th argument had an illegal value.
187 *> \author Univ. of Tennessee
188 *> \author Univ. of California Berkeley
189 *> \author Univ. of Colorado Denver
192 *> \date November 2011
194 *> \ingroup realOTHERcomputational
196 *> \par Further Details:
197 * =====================
201 *> This routine reduces A to Hessenberg and B to triangular form by
202 *> an unblocked reduction, as described in _Matrix_Computations_,
203 *> by Golub and Van Loan (Johns Hopkins Press.)
206 * =====================================================================
207 SUBROUTINE SGGHRD( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q,
208 $ LDQ, Z, LDZ, INFO )
210 * -- LAPACK computational routine (version 3.4.0) --
211 * -- LAPACK is a software package provided by Univ. of Tennessee, --
212 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
215 * .. Scalar Arguments ..
216 CHARACTER COMPQ, COMPZ
217 INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N
219 * .. Array Arguments ..
220 REAL A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
224 * =====================================================================
228 PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
230 * .. Local Scalars ..
232 INTEGER ICOMPQ, ICOMPZ, JCOL, JROW
235 * .. External Functions ..
239 * .. External Subroutines ..
240 EXTERNAL SLARTG, SLASET, SROT, XERBLA
242 * .. Intrinsic Functions ..
245 * .. Executable Statements ..
249 IF( LSAME( COMPQ, 'N' ) ) THEN
252 ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
255 ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
264 IF( LSAME( COMPZ, 'N' ) ) THEN
267 ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
270 ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
277 * Test the input parameters.
280 IF( ICOMPQ.LE.0 ) THEN
282 ELSE IF( ICOMPZ.LE.0 ) THEN
284 ELSE IF( N.LT.0 ) THEN
286 ELSE IF( ILO.LT.1 ) THEN
288 ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
290 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
292 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
294 ELSE IF( ( ILQ .AND. LDQ.LT.N ) .OR. LDQ.LT.1 ) THEN
296 ELSE IF( ( ILZ .AND. LDZ.LT.N ) .OR. LDZ.LT.1 ) THEN
300 CALL XERBLA( 'SGGHRD', -INFO )
304 * Initialize Q and Z if desired.
307 $ CALL SLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
309 $ CALL SLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
311 * Quick return if possible
316 * Zero out lower triangle of B
318 DO 20 JCOL = 1, N - 1
319 DO 10 JROW = JCOL + 1, N
320 B( JROW, JCOL ) = ZERO
326 DO 40 JCOL = ILO, IHI - 2
328 DO 30 JROW = IHI, JCOL + 2, -1
330 * Step 1: rotate rows JROW-1, JROW to kill A(JROW,JCOL)
332 TEMP = A( JROW-1, JCOL )
333 CALL SLARTG( TEMP, A( JROW, JCOL ), C, S,
334 $ A( JROW-1, JCOL ) )
335 A( JROW, JCOL ) = ZERO
336 CALL SROT( N-JCOL, A( JROW-1, JCOL+1 ), LDA,
337 $ A( JROW, JCOL+1 ), LDA, C, S )
338 CALL SROT( N+2-JROW, B( JROW-1, JROW-1 ), LDB,
339 $ B( JROW, JROW-1 ), LDB, C, S )
341 $ CALL SROT( N, Q( 1, JROW-1 ), 1, Q( 1, JROW ), 1, C, S )
343 * Step 2: rotate columns JROW, JROW-1 to kill B(JROW,JROW-1)
345 TEMP = B( JROW, JROW )
346 CALL SLARTG( TEMP, B( JROW, JROW-1 ), C, S,
348 B( JROW, JROW-1 ) = ZERO
349 CALL SROT( IHI, A( 1, JROW ), 1, A( 1, JROW-1 ), 1, C, S )
350 CALL SROT( JROW-1, B( 1, JROW ), 1, B( 1, JROW-1 ), 1, C,
353 $ CALL SROT( N, Z( 1, JROW ), 1, Z( 1, JROW-1 ), 1, C, S )