3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZGGBAL + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zggbal.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zggbal.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zggbal.f">
21 * SUBROUTINE ZGGBAL( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE,
22 * RSCALE, WORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER IHI, ILO, INFO, LDA, LDB, N
28 * .. Array Arguments ..
29 * DOUBLE PRECISION LSCALE( * ), RSCALE( * ), WORK( * )
30 * COMPLEX*16 A( LDA, * ), B( LDB, * )
39 *> ZGGBAL balances a pair of general complex matrices (A,B). This
40 *> involves, first, permuting A and B by similarity transformations to
41 *> isolate eigenvalues in the first 1 to ILO$-$1 and last IHI+1 to N
42 *> elements on the diagonal; and second, applying a diagonal similarity
43 *> transformation to rows and columns ILO to IHI to make the rows
44 *> and columns as close in norm as possible. Both steps are optional.
46 *> Balancing may reduce the 1-norm of the matrices, and improve the
47 *> accuracy of the computed eigenvalues and/or eigenvectors in the
48 *> generalized eigenvalue problem A*x = lambda*B*x.
57 *> Specifies the operations to be performed on A and B:
58 *> = 'N': none: simply set ILO = 1, IHI = N, LSCALE(I) = 1.0
59 *> and RSCALE(I) = 1.0 for i=1,...,N;
60 *> = 'P': permute only;
62 *> = 'B': both permute and scale.
68 *> The order of the matrices A and B. N >= 0.
73 *> A is COMPLEX*16 array, dimension (LDA,N)
74 *> On entry, the input matrix A.
75 *> On exit, A is overwritten by the balanced matrix.
76 *> If JOB = 'N', A is not referenced.
82 *> The leading dimension of the array A. LDA >= max(1,N).
87 *> B is COMPLEX*16 array, dimension (LDB,N)
88 *> On entry, the input matrix B.
89 *> On exit, B is overwritten by the balanced matrix.
90 *> If JOB = 'N', B is not referenced.
96 *> The leading dimension of the array B. LDB >= max(1,N).
107 *> ILO and IHI are set to integers such that on exit
108 *> A(i,j) = 0 and B(i,j) = 0 if i > j and
109 *> j = 1,...,ILO-1 or i = IHI+1,...,N.
110 *> If JOB = 'N' or 'S', ILO = 1 and IHI = N.
113 *> \param[out] LSCALE
115 *> LSCALE is DOUBLE PRECISION array, dimension (N)
116 *> Details of the permutations and scaling factors applied
117 *> to the left side of A and B. If P(j) is the index of the
118 *> row interchanged with row j, and D(j) is the scaling factor
119 *> applied to row j, then
120 *> LSCALE(j) = P(j) for J = 1,...,ILO-1
121 *> = D(j) for J = ILO,...,IHI
122 *> = P(j) for J = IHI+1,...,N.
123 *> The order in which the interchanges are made is N to IHI+1,
127 *> \param[out] RSCALE
129 *> RSCALE is DOUBLE PRECISION array, dimension (N)
130 *> Details of the permutations and scaling factors applied
131 *> to the right side of A and B. If P(j) is the index of the
132 *> column interchanged with column j, and D(j) is the scaling
133 *> factor applied to column j, then
134 *> RSCALE(j) = P(j) for J = 1,...,ILO-1
135 *> = D(j) for J = ILO,...,IHI
136 *> = P(j) for J = IHI+1,...,N.
137 *> The order in which the interchanges are made is N to IHI+1,
143 *> WORK is DOUBLE PRECISION array, dimension (lwork)
144 *> lwork must be at least max(1,6*N) when JOB = 'S' or 'B', and
145 *> at least 1 when JOB = 'N' or 'P'.
151 *> = 0: successful exit
152 *> < 0: if INFO = -i, the i-th argument had an illegal value.
158 *> \author Univ. of Tennessee
159 *> \author Univ. of California Berkeley
160 *> \author Univ. of Colorado Denver
165 *> \ingroup complex16GBcomputational
167 *> \par Further Details:
168 * =====================
172 *> See R.C. WARD, Balancing the generalized eigenvalue problem,
173 *> SIAM J. Sci. Stat. Comp. 2 (1981), 141-152.
176 * =====================================================================
177 SUBROUTINE ZGGBAL( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE,
178 $ RSCALE, WORK, INFO )
180 * -- LAPACK computational routine (version 3.6.1) --
181 * -- LAPACK is a software package provided by Univ. of Tennessee, --
182 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
185 * .. Scalar Arguments ..
187 INTEGER IHI, ILO, INFO, LDA, LDB, N
189 * .. Array Arguments ..
190 DOUBLE PRECISION LSCALE( * ), RSCALE( * ), WORK( * )
191 COMPLEX*16 A( LDA, * ), B( LDB, * )
194 * =====================================================================
197 DOUBLE PRECISION ZERO, HALF, ONE
198 PARAMETER ( ZERO = 0.0D+0, HALF = 0.5D+0, ONE = 1.0D+0 )
199 DOUBLE PRECISION THREE, SCLFAC
200 PARAMETER ( THREE = 3.0D+0, SCLFAC = 1.0D+1 )
202 PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ) )
204 * .. Local Scalars ..
205 INTEGER I, ICAB, IFLOW, IP1, IR, IRAB, IT, J, JC, JP1,
206 $ K, KOUNT, L, LCAB, LM1, LRAB, LSFMAX, LSFMIN,
208 DOUBLE PRECISION ALPHA, BASL, BETA, CAB, CMAX, COEF, COEF2,
209 $ COEF5, COR, EW, EWC, GAMMA, PGAMMA, RAB, SFMAX,
210 $ SFMIN, SUM, T, TA, TB, TC
213 * .. External Functions ..
216 DOUBLE PRECISION DDOT, DLAMCH
217 EXTERNAL LSAME, IZAMAX, DDOT, DLAMCH
219 * .. External Subroutines ..
220 EXTERNAL DAXPY, DSCAL, XERBLA, ZDSCAL, ZSWAP
222 * .. Intrinsic Functions ..
223 INTRINSIC ABS, DBLE, DIMAG, INT, LOG10, MAX, MIN, SIGN
225 * .. Statement Functions ..
226 DOUBLE PRECISION CABS1
228 * .. Statement Function definitions ..
229 CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
231 * .. Executable Statements ..
233 * Test the input parameters
236 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
237 $ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
239 ELSE IF( N.LT.0 ) THEN
241 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
243 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
247 CALL XERBLA( 'ZGGBAL', -INFO )
251 * Quick return if possible
267 IF( LSAME( JOB, 'N' ) ) THEN
279 IF( LSAME( JOB, 'S' ) )
284 * Permute the matrices A and B to isolate the eigenvalues.
286 * Find row with one nonzero in columns 1 through L
302 IF( A( I, J ).NE.CZERO .OR. B( I, J ).NE.CZERO )
310 IF( A( I, J ).NE.CZERO .OR. B( I, J ).NE.CZERO )
322 * Find column with one nonzero in rows K through N
331 IF( A( I, J ).NE.CZERO .OR. B( I, J ).NE.CZERO )
338 IF( A( I, J ).NE.CZERO .OR. B( I, J ).NE.CZERO )
349 * Permute rows M and I
355 CALL ZSWAP( N-K+1, A( I, K ), LDA, A( M, K ), LDA )
356 CALL ZSWAP( N-K+1, B( I, K ), LDB, B( M, K ), LDB )
358 * Permute columns M and J
364 CALL ZSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
365 CALL ZSWAP( L, B( 1, J ), 1, B( 1, M ), 1 )
368 GO TO ( 20, 90 )IFLOW
374 IF( LSAME( JOB, 'P' ) ) THEN
385 * Balance the submatrix in rows ILO to IHI.
400 * Compute right side vector in resulting linear equations
402 BASL = LOG10( SCLFAC )
405 IF( A( I, J ).EQ.CZERO ) THEN
409 TA = LOG10( CABS1( A( I, J ) ) ) / BASL
412 IF( B( I, J ).EQ.CZERO ) THEN
416 TB = LOG10( CABS1( B( I, J ) ) ) / BASL
419 WORK( I+4*N ) = WORK( I+4*N ) - TA - TB
420 WORK( J+5*N ) = WORK( J+5*N ) - TA - TB
424 COEF = ONE / DBLE( 2*NR )
431 * Start generalized conjugate gradient iteration
435 GAMMA = DDOT( NR, WORK( ILO+4*N ), 1, WORK( ILO+4*N ), 1 ) +
436 $ DDOT( NR, WORK( ILO+5*N ), 1, WORK( ILO+5*N ), 1 )
441 EW = EW + WORK( I+4*N )
442 EWC = EWC + WORK( I+5*N )
445 GAMMA = COEF*GAMMA - COEF2*( EW**2+EWC**2 ) - COEF5*( EW-EWC )**2
449 $ BETA = GAMMA / PGAMMA
450 T = COEF5*( EWC-THREE*EW )
451 TC = COEF5*( EW-THREE*EWC )
453 CALL DSCAL( NR, BETA, WORK( ILO ), 1 )
454 CALL DSCAL( NR, BETA, WORK( ILO+N ), 1 )
456 CALL DAXPY( NR, COEF, WORK( ILO+4*N ), 1, WORK( ILO+N ), 1 )
457 CALL DAXPY( NR, COEF, WORK( ILO+5*N ), 1, WORK( ILO ), 1 )
460 WORK( I ) = WORK( I ) + TC
461 WORK( I+N ) = WORK( I+N ) + T
464 * Apply matrix to vector
470 IF( A( I, J ).EQ.CZERO )
473 SUM = SUM + WORK( J )
475 IF( B( I, J ).EQ.CZERO )
478 SUM = SUM + WORK( J )
480 WORK( I+2*N ) = DBLE( KOUNT )*WORK( I+N ) + SUM
487 IF( A( I, J ).EQ.CZERO )
490 SUM = SUM + WORK( I+N )
492 IF( B( I, J ).EQ.CZERO )
495 SUM = SUM + WORK( I+N )
497 WORK( J+3*N ) = DBLE( KOUNT )*WORK( J ) + SUM
500 SUM = DDOT( NR, WORK( ILO+N ), 1, WORK( ILO+2*N ), 1 ) +
501 $ DDOT( NR, WORK( ILO ), 1, WORK( ILO+3*N ), 1 )
504 * Determine correction to current iteration
508 COR = ALPHA*WORK( I+N )
509 IF( ABS( COR ).GT.CMAX )
511 LSCALE( I ) = LSCALE( I ) + COR
512 COR = ALPHA*WORK( I )
513 IF( ABS( COR ).GT.CMAX )
515 RSCALE( I ) = RSCALE( I ) + COR
520 CALL DAXPY( NR, -ALPHA, WORK( ILO+2*N ), 1, WORK( ILO+4*N ), 1 )
521 CALL DAXPY( NR, -ALPHA, WORK( ILO+3*N ), 1, WORK( ILO+5*N ), 1 )
528 * End generalized conjugate gradient iteration
531 SFMIN = DLAMCH( 'S' )
533 LSFMIN = INT( LOG10( SFMIN ) / BASL+ONE )
534 LSFMAX = INT( LOG10( SFMAX ) / BASL )
536 IRAB = IZAMAX( N-ILO+1, A( I, ILO ), LDA )
537 RAB = ABS( A( I, IRAB+ILO-1 ) )
538 IRAB = IZAMAX( N-ILO+1, B( I, ILO ), LDB )
539 RAB = MAX( RAB, ABS( B( I, IRAB+ILO-1 ) ) )
540 LRAB = INT( LOG10( RAB+SFMIN ) / BASL+ONE )
541 IR = INT(LSCALE( I ) + SIGN( HALF, LSCALE( I ) ))
542 IR = MIN( MAX( IR, LSFMIN ), LSFMAX, LSFMAX-LRAB )
543 LSCALE( I ) = SCLFAC**IR
544 ICAB = IZAMAX( IHI, A( 1, I ), 1 )
545 CAB = ABS( A( ICAB, I ) )
546 ICAB = IZAMAX( IHI, B( 1, I ), 1 )
547 CAB = MAX( CAB, ABS( B( ICAB, I ) ) )
548 LCAB = INT( LOG10( CAB+SFMIN ) / BASL+ONE )
549 JC = INT(RSCALE( I ) + SIGN( HALF, RSCALE( I ) ))
550 JC = MIN( MAX( JC, LSFMIN ), LSFMAX, LSFMAX-LCAB )
551 RSCALE( I ) = SCLFAC**JC
554 * Row scaling of matrices A and B
557 CALL ZDSCAL( N-ILO+1, LSCALE( I ), A( I, ILO ), LDA )
558 CALL ZDSCAL( N-ILO+1, LSCALE( I ), B( I, ILO ), LDB )
561 * Column scaling of matrices A and B
564 CALL ZDSCAL( IHI, RSCALE( J ), A( 1, J ), 1 )
565 CALL ZDSCAL( IHI, RSCALE( J ), B( 1, J ), 1 )