F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08WAF (DGGEV)

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

F08WAF (DGGEV) 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.

## 2  Specification

 SUBROUTINE F08WAF ( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO)
 INTEGER N, LDA, LDB, LDVL, LDVR, LWORK, INFO REAL (KIND=nag_wp) A(LDA,*), B(LDB,*), ALPHAR(N), ALPHAI(N), BETA(N), VL(LDVL,*), VR(LDVR,*), WORK(max(1,LWORK)) CHARACTER(1) JOBVL, JOBVR
The routine may be called by its LAPACK name dggev.

## 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.

## 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:     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'}$.
2:     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'}$.
3:     N – INTEGERInput
On entry: $n$, the order of the matrices $A$ and $B$.
Constraint: ${\mathbf{N}}\ge 0$.
4:     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.
5:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F08WAF (DGGEV) is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
6:     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.
7:     LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which F08WAF (DGGEV) is called.
Constraint: ${\mathbf{LDB}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
8:     ALPHAR(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the element ${\mathbf{ALPHAR}}\left(j\right)$ contains the real part of ${\alpha }_{j}$.
9:     ALPHAI(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the element ${\mathbf{ALPHAI}}\left(j\right)$ contains the imaginary part of ${\alpha }_{j}$.
10:   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}$.
11:   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.
12:   LDVL – INTEGERInput
On entry: the first dimension of the array VL as declared in the (sub)program from which F08WAF (DGGEV) 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$.
13:   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 the corresponding eigenvalues.
If the $j$th eigenvalue is real, then ${v}_{j}={\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.
14:   LDVR – INTEGERInput
On entry: the first dimension of the array VR as declared in the (sub)program from which F08WAF (DGGEV) 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$.
15:   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.
16:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F08WAF (DGGEV) 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.
Constraint: ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,8×{\mathbf{N}}\right)$.
17:   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. See Section 4.11 of Anderson et al. (1999) for further details.
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 F08WNF (ZGGEV).

## 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 .$
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 (f08wafe.f90)

### 9.2  Program Data

Program Data (f08wafe.d)

### 9.3  Program Results

Program Results (f08wafe.r)