F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08WBF (DGGEVX)

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

F08WBF (DGGEVX) computes for a pair of $n$ by $n$ real nonsymmetric matrices $\left(A,B\right)$ the generalized eigenvalues and, optionally, the left and/or right generalized eigenvectors using the $QZ$ algorithm.
Optionally it also computes a balancing transformation to improve the conditioning of the eigenvalues and eigenvectors, reciprocal condition numbers for the eigenvalues, and reciprocal condition numbers for the right eigenvectors.

## 2  Specification

 SUBROUTINE F08WBF ( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, B, LDB, ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, ILO, IHI, LSCALE, RSCALE, ABNRM, BBNRM, RCONDE, RCONDV, WORK, LWORK, IWORK, BWORK, INFO)
 INTEGER N, LDA, LDB, LDVL, LDVR, ILO, IHI, LWORK, IWORK(*), INFO REAL (KIND=nag_wp) A(LDA,*), B(LDB,*), ALPHAR(N), ALPHAI(N), BETA(N), VL(LDVL,*), VR(LDVR,*), LSCALE(N), RSCALE(N), ABNRM, BBNRM, RCONDE(*), RCONDV(*), WORK(max(1,LWORK)) LOGICAL BWORK(*) CHARACTER(1) BALANC, JOBVL, JOBVR, SENSE
The routine may be called by its LAPACK name dggevx.

## 3  Description

A generalized eigenvalue for a pair of matrices $\left(A,B\right)$ is a scalar $\lambda$ or a ratio $\alpha /\beta =\lambda$, such that $A-\lambda B$ is singular. It is usually represented as the pair $\left(\alpha ,\beta \right)$, as there is a reasonable interpretation for $\beta =0$, and even for both being zero.
The right eigenvector ${v}_{j}$ corresponding to the eigenvalue ${\lambda }_{j}$ of $\left(A,B\right)$ satisfies
 $A vj = λj B vj .$
The left eigenvector ${u}_{j}$ corresponding to the eigenvalue ${\lambda }_{j}$ of $\left(A,B\right)$ satisfies
 $ujH A = λj ujH B ,$
where ${u}_{j}^{\mathrm{H}}$ is the conjugate-transpose of ${u}_{j}$.
All the eigenvalues and, if required, all the eigenvectors of the generalized eigenproblem $Ax=\lambda Bx$, where $A$ and $B$ are real, square matrices, are determined using the $QZ$ algorithm. The $QZ$ algorithm consists of four stages:
1. $A$ is reduced to upper Hessenberg form and at the same time $B$ is reduced to upper triangular form.
2. $A$ is further reduced to quasi-triangular form while the triangular form of $B$ is maintained. This is the real generalized Schur form of the pair $\left(A,B\right)$.
3. The quasi-triangular form of $A$ is reduced to triangular form and the eigenvalues extracted. This routine does not actually produce the eigenvalues ${\lambda }_{j}$, but instead returns ${\alpha }_{j}$ and ${\beta }_{j}$ such that
 $λj=αj/βj, j=1,2,…,n.$
The division by ${\beta }_{j}$ becomes your responsibility, since ${\beta }_{j}$ may be zero, indicating an infinite eigenvalue. Pairs of complex eigenvalues occur with ${\alpha }_{j}/{\beta }_{j}$ and ${\alpha }_{j+1}/{\beta }_{j+1}$ complex conjugates, even though ${\alpha }_{j}$ and ${\alpha }_{j+1}$ are not conjugate.
4. If the eigenvectors are required they are obtained from the triangular matrices and then transformed back into the original coordinate system.
For details of the balancing option, see Section 3 in F08WHF (DGGBAL).

## 4  References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia http://www.netlib.org/lapack/lug
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Wilkinson J H (1979) Kronecker's canonical form and the $QZ$ algorithm Linear Algebra Appl. 28 285–303

## 5  Parameters

1:     BALANC – CHARACTER(1)Input
On entry: specifies the balance option to be performed.
${\mathbf{BALANC}}=\text{'N'}$
Do not diagonally scale or permute.
${\mathbf{BALANC}}=\text{'P'}$
Permute only.
${\mathbf{BALANC}}=\text{'S'}$
Scale only.
${\mathbf{BALANC}}=\text{'B'}$
Both permute and scale.
Computed reciprocal condition numbers will be for the matrices after permuting and/or balancing. Permuting does not change condition numbers (in exact arithmetic), but balancing does. In the absence of other information, ${\mathbf{BALANC}}=\text{'B'}$ is recommended.
Constraint: ${\mathbf{BALANC}}=\text{'N'}$, $\text{'P'}$, $\text{'S'}$ or $\text{'B'}$.
2:     JOBVL – CHARACTER(1)Input
On entry: if ${\mathbf{JOBVL}}=\text{'N'}$, do not compute the left generalized eigenvectors.
If ${\mathbf{JOBVL}}=\text{'V'}$, compute the left generalized eigenvectors.
Constraint: ${\mathbf{JOBVL}}=\text{'N'}$ or $\text{'V'}$.
3:     JOBVR – CHARACTER(1)Input
On entry: if ${\mathbf{JOBVR}}=\text{'N'}$, do not compute the right generalized eigenvectors.
If ${\mathbf{JOBVR}}=\text{'V'}$, compute the right generalized eigenvectors.
Constraint: ${\mathbf{JOBVR}}=\text{'N'}$ or $\text{'V'}$.
4:     SENSE – CHARACTER(1)Input
On entry: determines which reciprocal condition numbers are computed.
${\mathbf{SENSE}}=\text{'N'}$
None are computed.
${\mathbf{SENSE}}=\text{'E'}$
Computed for eigenvalues only.
${\mathbf{SENSE}}=\text{'V'}$
Computed for eigenvectors only.
${\mathbf{SENSE}}=\text{'B'}$
Computed for eigenvalues and eigenvectors.
Constraint: ${\mathbf{SENSE}}=\text{'N'}$, $\text{'E'}$, $\text{'V'}$ or $\text{'B'}$.
5:     N – INTEGERInput
On entry: $n$, the order of the matrices $A$ and $B$.
Constraint: ${\mathbf{N}}\ge 0$.
6:     A(LDA,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array A must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
On entry: the matrix $A$ in the pair $\left(A,B\right)$.
On exit: A has been overwritten. If ${\mathbf{JOBVL}}=\text{'V'}$ or ${\mathbf{JOBVR}}=\text{'V'}$ or both, then $A$ contains the first part of the real Schur form of the ‘balanced’ versions of the input $A$ and $B$.
7:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F08WBF (DGGEVX) is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
8:     B(LDB,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array B must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
On entry: the matrix $B$ in the pair $\left(A,B\right)$.
On exit: B has been overwritten.
9:     LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which F08WBF (DGGEVX) is called.
Constraint: ${\mathbf{LDB}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
10:   ALPHAR(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the element ${\mathbf{ALPHAR}}\left(j\right)$ contains the real part of ${\alpha }_{j}$.
11:   ALPHAI(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the element ${\mathbf{ALPHAI}}\left(j\right)$ contains the imaginary part of ${\alpha }_{j}$.
12:   BETA(N) – REAL (KIND=nag_wp) arrayOutput
On exit: $\left({\mathbf{ALPHAR}}\left(\mathit{j}\right)+{\mathbf{ALPHAI}}\left(\mathit{j}\right)×i\right)/{\mathbf{BETA}}\left(\mathit{j}\right)$, for $\mathit{j}=1,2,\dots ,{\mathbf{N}}$, will be the generalized eigenvalues.
If ${\mathbf{ALPHAI}}\left(j\right)$ is zero, then the $j$th eigenvalue is real; if positive, then the $j$th and $\left(j+1\right)$st eigenvalues are a complex conjugate pair, with ${\mathbf{ALPHAI}}\left(j+1\right)$ negative.
Note:  the quotients ${\mathbf{ALPHAR}}\left(j\right)/{\mathbf{BETA}}\left(j\right)$ and ${\mathbf{ALPHAI}}\left(j\right)/{\mathbf{BETA}}\left(j\right)$ may easily overflow or underflow, and ${\mathbf{BETA}}\left(j\right)$ may even be zero. Thus, you should avoid naively computing the ratio ${\alpha }_{j}/{\beta }_{j}$. However, $\mathrm{max}\left|{\alpha }_{j}\right|$ will always be less than and usually comparable with ${‖{\mathbf{A}}‖}_{2}$ in magnitude, and $\mathrm{max}\left|{\beta }_{j}\right|$ will always be less than and usually comparable with ${‖{\mathbf{B}}‖}_{2}$.
13:   VL(LDVL,$*$) – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array VL must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$ if ${\mathbf{JOBVL}}=\text{'V'}$, and at least $1$ otherwise.
On exit: if ${\mathbf{JOBVL}}=\text{'V'}$, the left eigenvectors ${u}_{j}$ are stored one after another in the columns of VL, in the same order as the corresponding eigenvalues.
If the $j$th eigenvalue is real, then ${u}_{j}={\mathbf{VL}}\left(:,j\right)$, the $j$th column of ${\mathbf{VL}}$.
If the $j$th and $\left(j+1\right)$th eigenvalues form a complex conjugate pair, then ${u}_{j}={\mathbf{VL}}\left(:,j\right)+i×{\mathbf{VL}}\left(:,j+1\right)$ and $u\left(j+1\right)={\mathbf{VL}}\left(:,j\right)-i×{\mathbf{VL}}\left(:,j+1\right)$. Each eigenvector will be scaled so the largest component has $\left|\text{real part}\right|+\left|\text{imag. part}\right|=1$.
If ${\mathbf{JOBVL}}=\text{'N'}$, VL is not referenced.
14:   LDVL – INTEGERInput
On entry: the first dimension of the array VL as declared in the (sub)program from which F08WBF (DGGEVX) is called.
Constraints:
• if ${\mathbf{JOBVL}}=\text{'V'}$, ${\mathbf{LDVL}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• otherwise ${\mathbf{LDVL}}\ge 1$.
15:   VR(LDVR,$*$) – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array VR must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$ if ${\mathbf{JOBVR}}=\text{'V'}$, and at least $1$ otherwise.
On exit: if ${\mathbf{JOBVR}}=\text{'V'}$, the right eigenvectors ${v}_{j}$ are stored one after another in the columns of VR, in the same order as their eigenvalues.
If the $j$th eigenvalue is real, then $v\left(j\right)={\mathbf{VR}}\left(:,j\right)$, the $j$th column of $\mathrm{VR}$.
If the $j$th and $\left(j+1\right)$th eigenvalues form a complex conjugate pair, then ${v}_{j}={\mathbf{VR}}\left(:,j\right)+i×{\mathbf{VR}}\left(:,j+1\right)$ and ${v}_{j+1}={\mathbf{VR}}\left(:,j\right)-i×{\mathbf{VR}}\left(:,j+1\right)$.
Each eigenvector will be scaled so the largest component has $\left|\text{real part}\right|+\left|\text{imag. part}\right|=1$.
If ${\mathbf{JOBVR}}=\text{'N'}$, VR is not referenced.
16:   LDVR – INTEGERInput
On entry: the first dimension of the array VR as declared in the (sub)program from which F08WBF (DGGEVX) is called.
Constraints:
• if ${\mathbf{JOBVR}}=\text{'V'}$, ${\mathbf{LDVR}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• otherwise ${\mathbf{LDVR}}\ge 1$.
17:   ILO – INTEGEROutput
18:   IHI – INTEGEROutput
On exit: ILO and IHI are integer values such that ${\mathbf{A}}\left(i,j\right)=0$ and ${\mathbf{B}}\left(i,j\right)=0$ if $i>j$ and $j=1,2,\dots ,{\mathbf{ILO}}-1$ or $i={\mathbf{IHI}}+1,\dots ,{\mathbf{N}}$.
If ${\mathbf{BALANC}}=\text{'N'}$ or $\text{'S'}$, ${\mathbf{ILO}}=1$ and ${\mathbf{IHI}}={\mathbf{N}}$.
19:   LSCALE(N) – REAL (KIND=nag_wp) arrayOutput
On exit: details of the permutations and scaling factors applied to the left side of $A$ and $B$.
If ${\mathit{pl}}_{j}$ is the index of the row interchanged with row $j$, and ${\mathit{dl}}_{j}$ is the scaling factor applied to row $j$, then:
• ${\mathbf{LSCALE}}\left(\mathit{j}\right)={\mathit{pl}}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{ILO}}-1$;
• ${\mathbf{LSCALE}}={\mathit{dl}}_{\mathit{j}}$, for $\mathit{j}={\mathbf{ILO}},\dots ,{\mathbf{IHI}}$;
• ${\mathbf{LSCALE}}={\mathit{pl}}_{\mathit{j}}$, for $\mathit{j}={\mathbf{IHI}}+1,\dots ,{\mathbf{N}}$.
The order in which the interchanges are made is N to ${\mathbf{IHI}}+1$, then $1$ to ${\mathbf{ILO}}-1$.
20:   RSCALE(N) – REAL (KIND=nag_wp) arrayOutput
On exit: details of the permutations and scaling factors applied to the right side of $A$ and $B$.
If ${\mathit{pr}}_{j}$ is the index of the column interchanged with column $j$, and ${\mathit{dr}}_{j}$ is the scaling factor applied to column $j$, then:
• ${\mathbf{RSCALE}}\left(\mathit{j}\right)={\mathit{pr}}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{ILO}}-1$;
• if ${\mathbf{RSCALE}}={\mathit{dr}}_{\mathit{j}}$, for $\mathit{j}={\mathbf{ILO}},\dots ,{\mathbf{IHI}}$;
• if ${\mathbf{RSCALE}}={\mathit{pr}}_{\mathit{j}}$, for $\mathit{j}={\mathbf{IHI}}+1,\dots ,{\mathbf{N}}$.
The order in which the interchanges are made is N to ${\mathbf{IHI}}+1$, then $1$ to ${\mathbf{ILO}}-1$.
21:   ABNRM – REAL (KIND=nag_wp)Output
On exit: the $1$-norm of the balanced matrix $A$.
22:   BBNRM – REAL (KIND=nag_wp)Output
On exit: the $1$-norm of the balanced matrix $B$.
23:   RCONDE($*$) – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array RCONDE must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
On exit: if ${\mathbf{SENSE}}=\text{'E'}$ or $\text{'B'}$, the reciprocal condition numbers of the eigenvalues, stored in consecutive elements of the array. For a complex conjugate pair of eigenvalues two consecutive elements of RCONDE are set to the same value. Thus ${\mathbf{RCONDE}}\left(j\right)$, ${\mathbf{RCONDV}}\left(j\right)$, and the $j$th columns of VL and VR all correspond to the $j$th eigenpair.
If ${\mathbf{SENSE}}=\text{'V'}$, RCONDE is not referenced.
24:   RCONDV($*$) – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array RCONDV must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
On exit: if ${\mathbf{SENSE}}=\text{'V'}$ or $\text{'B'}$, the estimated reciprocal condition numbers of the eigenvectors, stored in consecutive elements of the array. For a complex eigenvector two consecutive elements of RCONDV are set to the same value.
If ${\mathbf{SENSE}}=\text{'E'}$, RCONDV is not referenced.
25:   WORK($\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{LWORK}}\right)$) – REAL (KIND=nag_wp) arrayWorkspace
On exit: if ${\mathbf{INFO}}={\mathbf{0}}$, ${\mathbf{WORK}}\left(1\right)$ contains the minimum value of LWORK required for optimal performance.
26:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F08WBF (DGGEVX) is called.
If ${\mathbf{LWORK}}=-1$, a workspace query is assumed; the routine only calculates the optimal size of the WORK array, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued.
Suggested value: for optimal performance, LWORK must generally be larger than the minimum; increase workspace by, say, $\mathit{nb}×{\mathbf{N}}$, where $\mathit{nb}$ is the optimal block size.
Constraints:
• if ${\mathbf{SENSE}}=\text{'N'}$,
• if ${\mathbf{BALANC}}=\text{'N'}$ or $\text{'P'}$ and ${\mathbf{JOBVL}}=\text{'N'}$ and ${\mathbf{JOBVR}}=\text{'N'}$, ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,2×{\mathbf{N}}\right)$;
• otherwise ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,6×{\mathbf{N}}\right)$;
• if ${\mathbf{SENSE}}=\text{'E'}$, ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,10×{\mathbf{N}}\right)$;
• if ${\mathbf{SENSE}}=\text{'B'}$ or ${\mathbf{SENSE}}=\text{'V'}$, ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(10×{\mathbf{N}},2×{\mathbf{N}}×\left({\mathbf{N}}+4\right)+16\right)$.
27:   IWORK($*$) – INTEGER arrayWorkspace
Note: the dimension of the array IWORK must be at least ${\mathbf{N}}+6$.
If ${\mathbf{SENSE}}=\text{'E'}$, IWORK is not referenced.
28:   BWORK($*$) – LOGICAL arrayWorkspace
Note: the dimension of the array BWORK must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
If ${\mathbf{SENSE}}=\text{'N'}$, BWORK is not referenced.
29:   INFO – INTEGEROutput
On exit: ${\mathbf{INFO}}=0$ unless the routine detects an error (see Section 6).

## 6  Error Indicators and Warnings

Errors or warnings detected by the routine:
${\mathbf{INFO}}<0$
If ${\mathbf{INFO}}=-i$, argument $i$ had an illegal value. An explanatory message is output, and execution of the program is terminated.
The $QZ$ iteration failed. No eigenvectors have been calculated, but ${\mathbf{ALPHAR}}\left(j\right)$, ${\mathbf{ALPHAI}}\left(j\right)$, and ${\mathbf{BETA}}\left(j\right)$ should be correct for $j={\mathbf{INFO}}+1,\dots ,{\mathbf{N}}$.
${\mathbf{INFO}}={\mathbf{N}}+1$
Unexpected error returned from F08XEF (DHGEQZ).
${\mathbf{INFO}}={\mathbf{N}}+2$
Error returned from F08YKF (DTGEVC).

## 7  Accuracy

The computed eigenvalues and eigenvectors are exact for a nearby matrices $\left(A+E\right)$ and $\left(B+F\right)$, where
 $E,F F = Oε A,B F ,$
and $\epsilon$ is the machine precision.
An approximate error bound on the chordal distance between the $i$th computed generalized eigenvalue $w$ and the corresponding exact eigenvalue $\lambda$ is
 $ε × ABNRM,BBNRM2 / RCONDEi .$
An approximate error bound for the angle between the $i$th computed eigenvector ${\mathbf{VL}}\left(i\right)$ or ${\mathbf{VR}}\left(i\right)$ is given by
 $ε × ABNRM,BBNRM2 / RCONDVi .$
For further explanation of the reciprocal condition numbers RCONDE and RCONDV, see Section 4.11 of Anderson et al. (1999).
Note:  interpretation of results obtained with the $QZ$ algorithm often requires a clear understanding of the effects of small changes in the original data. These effects are reviewed in Wilkinson (1979), in relation to the significance of small values of ${\alpha }_{j}$ and ${\beta }_{j}$. It should be noted that if ${\alpha }_{j}$ and ${\beta }_{j}$ are both small for any $j$, it may be that no reliance can be placed on any of the computed eigenvalues ${\lambda }_{i}={\alpha }_{i}/{\beta }_{i}$. You are recommended to study Wilkinson (1979) and, if in difficulty, to seek expert advice on determining the sensitivity of the eigenvalues to perturbations in the data.

The total number of floating point operations is proportional to ${n}^{3}$.
The complex analogue of this routine is F08WPF (ZGGEVX).

## 9  Example

This example finds all the eigenvalues and right eigenvectors of the matrix pair $\left(A,B\right)$, where
 $A = 3.9 12.5 -34.5 -0.5 4.3 21.5 -47.5 7.5 4.3 21.5 -43.5 3.5 4.4 26.0 -46.0 6.0 and B= 1.0 2.0 -3.0 1.0 1.0 3.0 -5.0 4.0 1.0 3.0 -4.0 3.0 1.0 3.0 -4.0 4.0 ,$
together with estimates of the condition number and forward error bounds for each eigenvalue and eigenvector. The option to balance the matrix pair is used.
Note that the block size (NB) of $64$ assumed in this example is not realistic for such a small problem, but should be suitable for large problems.

### 9.1  Program Text

Program Text (f08wbfe.f90)

### 9.2  Program Data

Program Data (f08wbfe.d)

### 9.3  Program Results

Program Results (f08wbfe.r)