**Purpose**

To compute the eigenvalues of a complex N-by-N skew-Hamiltonian/ Hamiltonian pencil aS - bH, with ( A D ) ( B F ) S = ( H ) and H = ( H ). (1) ( E A ) ( G -B ) This routine computes the eigenvalues using an embedding to a real skew-Hamiltonian/skew-Hamiltonian pencil aB_S - bB_T, defined as ( Re(A) -Im(A) | Re(D) -Im(D) ) ( | ) ( Im(A) Re(A) | Im(D) Re(D) ) ( | ) B_S = (-----------------+-----------------) , and ( | T T ) ( Re(E) -Im(E) | Re(A ) Im(A ) ) ( | T T ) ( Im(E) Re(E) | -Im(A ) Re(A ) ) (2) ( -Im(B) -Re(B) | -Im(F) -Re(F) ) ( | ) ( Re(B) -Im(B) | Re(F) -Im(F) ) ( | ) B_T = (-----------------+-----------------) , T = i*H. ( | T T ) ( -Im(G) -Re(G) | -Im(B ) Re(B ) ) ( | T T ) ( Re(G) -Im(G) | -Re(B ) -Im(B ) ) Optionally, if JOB = 'T', the pencil aB_S - bB_H (B_H = -i*B_T) is transformed by a unitary matrix Q to the structured Schur form ( BA BD ) ( BB BF ) B_Sout = ( H ) and B_Hout = ( H ), (3) ( 0 BA ) ( 0 -BB ) where BA and BB are upper triangular, BD is skew-Hermitian, and BF is Hermitian. The embedding doubles the multiplicities of the eigenvalues of the pencil aS - bH. Optionally, if COMPQ = 'C', the unitary matrix Q is computed.

SUBROUTINE MB04BZ( JOB, COMPQ, N, A, LDA, DE, LDDE, B, LDB, FG, $ LDFG, Q, LDQ, ALPHAR, ALPHAI, BETA, IWORK, $ DWORK, LDWORK, ZWORK, LZWORK, BWORK, INFO ) C .. Scalar Arguments .. CHARACTER COMPQ, JOB INTEGER INFO, LDA, LDB, LDDE, LDFG, LDQ, LDWORK, $ LZWORK, N C .. Array Arguments .. LOGICAL BWORK( * ) INTEGER IWORK( * ) DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ), DWORK( * ) COMPLEX*16 A( LDA, * ), B( LDB, * ), DE( LDDE, * ), $ FG( LDFG, * ), Q( LDQ, * ), ZWORK( * )

**Mode Parameters**

JOB CHARACTER*1 Specifies the computation to be performed, as follows: = 'E': compute the eigenvalues only; S and H will not necessarily be transformed as in (3). = 'T': put S and H into the forms in (3) and return the eigenvalues in ALPHAR, ALPHAI and BETA. COMPQ CHARACTER*1 Specifies whether to compute the unitary transformation matrix Q, as follows: = 'N': Q is not computed; = 'C': compute the unitary transformation matrix Q.

N (input) INTEGER The order of the pencil aS - bH. N >= 0, even. A (input/output) COMPLEX*16 array, dimension (LDA, K) where K = N/2, if JOB = 'E', and K = N, if JOB = 'T'. On entry, the leading N/2-by-N/2 part of this array must contain the matrix A. On exit, if JOB = 'T', the leading N-by-N part of this array contains the upper triangular matrix BA in (3) (see also METHOD). The strictly lower triangular part is not zeroed, but it is preserved. If JOB = 'E', this array is unchanged on exit. LDA INTEGER The leading dimension of the array A. LDA >= MAX(1, K). DE (input/output) COMPLEX*16 array, dimension (LDDE, MIN(K+1,N)) On entry, the leading N/2-by-N/2 lower triangular part of this array must contain the lower triangular part of the skew-Hermitian matrix E, and the N/2-by-N/2 upper triangular part of the submatrix in the columns 2 to N/2+1 of this array must contain the upper triangular part of the skew-Hermitian matrix D. On exit, if JOB = 'T', the leading N-by-N part of this array contains the skew-Hermitian matrix BD in (3) (see also METHOD). The strictly lower triangular part of the input matrix is preserved. If JOB = 'E', this array is unchanged on exit. LDDE INTEGER The leading dimension of the array DE. LDDE >= MAX(1, K). B (input/output) COMPLEX*16 array, dimension (LDB, K) On entry, the leading N/2-by-N/2 part of this array must contain the matrix B. On exit, if JOB = 'T', the leading N-by-N part of this array contains the upper triangular matrix BB in (3) (see also METHOD). The strictly lower triangular part is not zeroed; the elements below the first subdiagonal of the input matrix are preserved. If JOB = 'E', this array is unchanged on exit. LDB INTEGER The leading dimension of the array B. LDB >= MAX(1, K). FG (input/output) COMPLEX*16 array, dimension (LDFG, MIN(K+1,N)) On entry, the leading N/2-by-N/2 lower triangular part of this array must contain the lower triangular part of the Hermitian matrix G, and the N/2-by-N/2 upper triangular part of the submatrix in the columns 2 to N/2+1 of this array must contain the upper triangular part of the Hermitian matrix F. On exit, if JOB = 'T', the leading N-by-N part of this array contains the Hermitian matrix BF in (3) (see also METHOD). The strictly lower triangular part of the input matrix is preserved. The diagonal elements might have tiny imaginary parts. If JOB = 'E', this array is unchanged on exit. LDFG INTEGER The leading dimension of the array FG. LDFG >= MAX(1, K). Q (output) COMPLEX*16 array, dimension (LDQ, 2*N) On exit, if COMPQ = 'C', the leading 2*N-by-2*N part of this array contains the unitary transformation matrix Q that reduced the matrices B_S and B_H to the form in (3). However, if JOB = 'E', the reduction was possibly not completed: the matrix B_H may have 2-by-2 diagonal blocks, and the array Q returns the orthogonal matrix that performed the partial reduction. If COMPQ = 'N', this array is not referenced. LDQ INTEGER The leading dimension of the array Q. LDQ >= 1, if COMPQ = 'N'; LDQ >= MAX(1, 2*N), if COMPQ = 'C'. ALPHAR (output) DOUBLE PRECISION array, dimension (N) The real parts of each scalar alpha defining an eigenvalue of the pencil aS - bH. ALPHAI (output) DOUBLE PRECISION array, dimension (N) The imaginary parts of each scalar alpha defining an eigenvalue of the pencil aS - bH. If ALPHAI(j) is zero, then the j-th eigenvalue is real. BETA (output) DOUBLE PRECISION array, dimension (N) The scalars beta that define the eigenvalues of the pencil aS - bH. Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and beta = BETA(j) represent the j-th eigenvalue of the pencil aS - bH, in the form lambda = alpha/beta. Since lambda may overflow, the ratios should not, in general, be computed.

IWORK INTEGER array, dimension (2*N+3) On exit, IWORK(1) contains the number, q, of unreliable, possibly inaccurate (pairs of) eigenvalues, and the absolute values in IWORK(2), ..., IWORK(q+1) are their indices, as well as of the corresponding 1-by-1 and 2-by-2 diagonal blocks of the arrays B and A on exit, if JOB = 'T'. Specifically, a positive value is an index of a real or purely imaginary eigenvalue, corresponding to a 1-by-1 block, while the absolute value of a negative entry in IWORK is an index to the first eigenvalue in a pair of consecutively stored eigenvalues, corresponding to a 2-by-2 block. Moreover, IWORK(q+2),..., IWORK(2*q+1) contain pointers to the starting elements in DWORK where each block pair is stored. Specifically, if IWORK(i+1) > 0 then DWORK(r) and DWORK(r+1) store corresponding diagonal elements of T11 and S11, respectively, and if IWORK(i+1) < 0, then DWORK(r:r+3) and DWORK(r+4:r+7) store the elements of the block in T11 and S11, respectively (see Section METHOD), where r = IWORK(q+1+i). Moreover, IWORK(2*q+2) contains the number s of the 1-by-1 blocks, and IWORK(2*q+3) contains the number t of the 2-by-2 blocks, corresponding to unreliable eigenvalues. DWORK DOUBLE PRECISION array, dimension (LDWORK) On exit, if INFO = 0 or INFO = 3, DWORK(1) returns the optimal LDWORK, and DWORK(2) and DWORK(3) contain the Frobenius norms of the matrices B_S and B_T. These norms are used in the tests to decide that some eigenvalues are considered as numerically unreliable. Moreover, DWORK(4), ..., DWORK(3+2*s) contain the s pairs of values of the 1-by-1 diagonal elements of T11 and S11 corresponding to unreliable eigenvalues. (Such an eigenvalue is obtained from -i*sqrt(T11(i,i)/S11(i,i)).) Similarly, DWORK(4+2*s), ..., DWORK(3+2*s+8*t) contain the t groups of pairs of 2-by-2 diagonal submatrices of T11 and S11 corresponding to pairs of unreliable eigenvalues. (Such an eigenvalue pair is obtained from -i*sqrt( ev ), where ev are the eigenvalues of (T11(i:i+1,i:i+1),S11(i:i+1,i:i+1)).) On exit, if INFO = -19, DWORK(1) returns the minimum value of LDWORK. LDWORK INTEGER The dimension of the array DWORK. If COMPQ = 'N', LDWORK >= MAX( 3, 4*N*N + 3*N ), if JOB = 'E'; LDWORK >= MAX( 3, 5*N*N + 3*N ), if JOB = 'T'; LDWORK >= MAX( 3, 11*N*N + 2*N ), if COMPQ = 'C'. For good performance LDWORK should be generally larger. If LDWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of the DWORK array, returns this value as the first entry of the DWORK array, and no error message related to LDWORK is issued by XERBLA. ZWORK COMPLEX*16 array, dimension (LZWORK) On exit, if INFO = 0, ZWORK(1) returns the optimal LZWORK. On exit, if INFO = -21, ZWORK(1) returns the minimum value of LZWORK. LZWORK INTEGER The dimension of the array ZWORK. LZWORK >= 1, if JOB = 'E'; otherwise, LZWORK >= 6*N + 4, if COMPQ = 'N'; LZWORK >= 8*N + 4, if COMPQ = 'C'. If LZWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of the ZWORK array, returns this value as the first entry of the ZWORK array, and no error message related to LZWORK is issued by XERBLA. BWORK LOGICAL array, dimension (LBWORK) LBWORK >= 0, if JOB = 'E'; LBWORK >= N, if JOB = 'T'.

INFO INTEGER = 0: succesful exit; < 0: if INFO = -i, the i-th argument had an illegal value; = 1: QZ iteration failed in the SLICOT Library routine MB04FD (QZ iteration did not converge or computation of the shifts failed); = 2: QZ iteration failed in the LAPACK routine ZHGEQZ when trying to triangularize the 2-by-2 blocks; = 3: warning: the pencil is numerically singular.

First, T = i*H is set. Then, the embeddings, B_S and B_T, of the matrices S and T, are determined and, subsequently, the SLICOT Library routine MB04FD is applied to compute the structured Schur form, i.e., the factorizations ~ T T ( S11 S12 ) B_S = J Q J B_S Q = ( T ) and ( 0 S11 ) ~ T T ( T11 T12 ) B_T = J Q J B_T Q = ( T ), ( 0 T11 ) where Q is real orthogonal, S11 is upper triangular, and T11 is upper quasi-triangular. If JOB = 'T', then the matrices above are ~ further transformed so that the 2-by-2 blocks in i*B_T are split into 1-by-1 blocks. If COMPQ = 'C', the transformations are accumulated in the unitary matrix Q. See also page 22 in [1] for more details.

[1] Benner, P., Byers, R., Mehrmann, V. and Xu, H. Numerical Computation of Deflating Subspaces of Embedded Hamiltonian Pencils. Tech. Rep. SFB393/99-15, Technical University Chemnitz, Germany, June 1999.

3 The algorithm is numerically backward stable and needs O(N ) complex floating point operations.

The returned eigenvalues are those of the pencil (-i*T11,S11), where i is the purely imaginary unit. If JOB = 'E', the returned matrix T11 is quasi-triangular. Note that the off-diagonal elements of the 2-by-2 blocks of S11 are zero by construction. If JOB = 'T', the returned eigenvalues correspond to the diagonal elements of BB and BA. This routine does not perform any scaling of the matrices. Scaling might sometimes be useful, and it should be done externally.

**Program Text**

* MB04BZ EXAMPLE PROGRAM TEXT * Copyright (c) 2002-2017 NICONET e.V. * * .. Parameters .. INTEGER NIN, NOUT PARAMETER ( NIN = 5, NOUT = 6 ) INTEGER NMAX PARAMETER ( NMAX = 50 ) INTEGER LDA, LDB, LDDE, LDFG, LDQ, LDWORK, LZWORK PARAMETER ( LDA = NMAX, LDB = NMAX, LDDE = NMAX, $ LDFG = NMAX, LDQ = 2*NMAX, $ LDWORK = 11*NMAX*NMAX + 2*NMAX, $ LZWORK = 8*NMAX + 4 ) * * .. Local Scalars .. CHARACTER COMPQ, JOB INTEGER I, INFO, J, M, N * * .. Local Arrays .. COMPLEX*16 A( LDA, NMAX ), B( LDB, NMAX ), $ DE( LDDE, NMAX ), FG( LDFG, NMAX ), $ Q( LDQ, 2*NMAX ), ZWORK( LZWORK ) DOUBLE PRECISION ALPHAI( NMAX ), ALPHAR( NMAX ), $ BETA( NMAX ), DWORK( LDWORK ) INTEGER IWORK( 2*NMAX+3 ) LOGICAL BWORK( NMAX ) * * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * * .. External Subroutines .. EXTERNAL MB04BZ * * .. Intrinsic Functions .. INTRINSIC MOD * * .. Executable Statements .. * WRITE( NOUT, FMT = 99999 ) * Skip the heading in the data file and read in the data. READ( NIN, FMT = * ) READ( NIN, FMT = * ) JOB, COMPQ, N IF( N.LT.0 .OR. N.GT.NMAX .OR. MOD( N, 2 ).NE.0 ) THEN WRITE( NOUT, FMT = 99998 ) N ELSE M = N/2 READ( NIN, FMT = * ) ( ( A( I, J ), J = 1, M ), I = 1, M ) READ( NIN, FMT = * ) ( ( DE( I, J ), J = 1, M+1 ), I = 1, M ) READ( NIN, FMT = * ) ( ( B( I, J ), J = 1, M ), I = 1, M ) READ( NIN, FMT = * ) ( ( FG( I, J ), J = 1, M+1 ), I = 1, M ) * Compute the eigenvalues of a complex skew-Hamiltonian/ * Hamiltonian pencil. CALL MB04BZ( JOB, COMPQ, N, A, LDA, DE, LDDE, B, LDB, FG, LDFG, $ Q, LDQ, ALPHAR, ALPHAI, BETA, IWORK, DWORK, $ LDWORK, ZWORK, LZWORK, BWORK, INFO ) * IF( INFO.NE.0 ) THEN WRITE( NOUT, FMT = 99997 ) INFO ELSE IF( LSAME( JOB, 'T' ) ) THEN WRITE( NOUT, FMT = 99996 ) DO 10 I = 1, N WRITE( NOUT, FMT = 99995 ) ( A( I, J ), J = 1, N ) 10 CONTINUE WRITE( NOUT, FMT = 99994 ) DO 20 I = 1, N WRITE( NOUT, FMT = 99995 ) ( DE( I, J ), J = 1, N ) 20 CONTINUE WRITE( NOUT, FMT = 99993 ) DO 30 I = 1, N WRITE( NOUT, FMT = 99995 ) ( B( I, J ), J = 1, N ) 30 CONTINUE WRITE( NOUT, FMT = 99992 ) DO 40 I = 1, N WRITE( NOUT, FMT = 99995 ) ( FG( I, J ), J = 1, N ) 40 CONTINUE END IF IF( LSAME( COMPQ, 'C' ) ) THEN WRITE( NOUT, FMT = 99991 ) DO 50 I = 1, 2*N WRITE( NOUT, FMT = 99995 ) ( Q( I, J ), J = 1, 2*N ) 50 CONTINUE END IF WRITE( NOUT, FMT = 99990 ) WRITE( NOUT, FMT = 99989 ) ( ALPHAR( I ), I = 1, N ) WRITE( NOUT, FMT = 99988 ) WRITE( NOUT, FMT = 99989 ) ( ALPHAI( I ), I = 1, N ) WRITE( NOUT, FMT = 99987 ) WRITE( NOUT, FMT = 99989 ) ( BETA( I ), I = 1, N ) END IF END IF STOP * 99999 FORMAT ( 'MB04BZ EXAMPLE PROGRAM RESULTS', 1X ) 99998 FORMAT ( 'N is out of range.', /, 'N = ', I5 ) 99997 FORMAT ( 'INFO on exit from MB04BZ = ', I2 ) 99996 FORMAT (/'The matrix A on exit is ' ) 99995 FORMAT (20( 1X, F9.4, SP, F9.4, S, 'i ') ) 99994 FORMAT (/'The matrix D on exit is ' ) 99993 FORMAT (/'The matrix B on exit is ' ) 99992 FORMAT (/'The matrix F on exit is ' ) 99991 FORMAT (/'The matrix Q is ' ) 99990 FORMAT (/'The vector ALPHAR is ' ) 99989 FORMAT ( 50( 1X, F8.4 ) ) 99988 FORMAT (/'The vector ALPHAI is ' ) 99987 FORMAT (/'The vector BETA is ' ) END

MB04BZ EXAMPLE PROGRAM DATA T C 4 (0.0604,0.6568) (0.5268,0.2919) (0.3992,0.6279) (0.4167,0.4316) (0,0.4896) (0,0.9516) (0.3724,0.0526) (0.9840,0.3394) (0,0.9203) (0,0.7378) (0.2691,0.4177) (0.5478,0.3014) (0.4228,0.9830) (0.9427,0.7010) 0.6663 0.6981 (0.1781,0.8818) (0.5391,0.1711) 0.6665 0.1280

MB04BZ EXAMPLE PROGRAM RESULTS The matrix A on exit is 0.7430 +0.0000i 0.0389 -0.4330i -0.1155 -0.1366i -0.6586 -0.3210i 0.3992 +0.6279i 0.7548 +0.0000i 0.6099 -0.2308i 0.2140 +0.1260i 0.0000 +0.0000i 0.0000 +0.0000i 1.4085 +0.0000i 0.0848 +0.4972i 0.0000 +0.0000i 0.0000 +0.0000i 0.0000 +0.0000i 1.4725 +0.0000i The matrix D on exit is 0.0000 -0.6858i 0.1839 -0.0474i -0.4428 -0.1290i 0.4759 +0.0380i 0.9840 +0.3394i 0.0000 +0.6858i -0.6339 +0.1358i 0.4204 -0.2140i 0.0000 +0.0000i 0.0000 +0.0000i 0.0000 -0.2110i -0.0159 -0.0338i 0.0000 +0.0000i 0.0000 +0.0000i 0.0000 +0.0000i 0.0000 +0.2110i The matrix B on exit is -1.5832 +0.5069i -0.0097 +0.0866i 0.1032 -0.1431i -0.0426 +0.7942i 0.0000 +0.0000i 1.6085 +0.5150i -0.1342 -0.8180i 0.5143 +0.0178i 0.0000 +0.0000i 0.0000 +0.0000i -0.0842 -0.1642i 0.0246 -0.0264i 0.0000 +0.0000i 0.0000 +0.0000i 0.0000 +0.0000i 0.0880 -0.1716i The matrix F on exit is 0.3382 0.0000i 0.0234 +0.0907i -0.1619 +0.9033i -0.8227 +0.0204i 0.5391 +0.1711i -0.3382 +0.0000i -0.6525 +0.2455i -0.3532 -0.6409i 0.0000 +0.0000i 0.0000 +0.0000i 0.0120 0.0000i 0.0019 -0.0009i 0.0000 +0.0000i 0.0000 +0.0000i 0.0000 +0.0000i -0.0120 +0.0000i The matrix Q is 0.1422 +0.5446i -0.3877 -0.1273i -0.4363 +0.1705i 0.0348 -0.5440i 0.0000 +0.0000i 0.0000 +0.0000i 0.0000 +0.0000i 0.0000 +0.0000i 0.1594 -0.2382i 0.1967 -0.2467i -0.1376 -0.0961i -0.1070 -0.2058i -0.1273 +0.0585i -0.0852 +0.1020i 0.6125 -0.1059i -0.0172 +0.5589i -0.3659 -0.0211i -0.0291 +0.4967i -0.0729 +0.4236i 0.3169 -0.0008i 0.2947 -0.1080i 0.1614 -0.2342i 0.2867 -0.0578i -0.0170 +0.2603i 0.1846 +0.4089i -0.2815 -0.2018i 0.3220 -0.1600i -0.0526 +0.3937i 0.2747 -0.0655i 0.1045 -0.2159i 0.2085 -0.3104i -0.3052 +0.1463i -0.0201 -0.2898i 0.2131 -0.0081i -0.2165 -0.1055i -0.1324 -0.3133i 0.1660 -0.1635i 0.2250 -0.1390i -0.1590 -0.4634i -0.5310 -0.2239i 0.1342 -0.1295i 0.1128 -0.1990i -0.0712 -0.1686i -0.1490 -0.1336i 0.6198 +0.0113i 0.0281 -0.4762i -0.0462 +0.3244i 0.3464 +0.0086i 0.2305 -0.1358i 0.1292 -0.3311i -0.0106 +0.4992i 0.3906 +0.0997i 0.1429 +0.3376i -0.4310 -0.0866i -0.0894 -0.1336i -0.1601 -0.1055i -0.2601 +0.0835i -0.0940 +0.3652i -0.0213 -0.3116i -0.2502 -0.0995i 0.1361 +0.4589i -0.5898 -0.0730i 0.0294 -0.1192i -0.1253 +0.0085i The vector ALPHAR is -1.5832 1.5832 -0.0842 0.0842 The vector ALPHAI is 0.5069 0.5069 -0.1642 -0.1642 The vector BETA is 0.7430 0.7430 1.4085 1.4085