f08wp computes for a pair of $n$ by $n$ complex 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.

# Syntax

C#
```public static void f08wp(
string balanc,
string jobvl,
string jobvr,
string sense,
int n,
Complex[,] a,
Complex[,] b,
Complex[] alpha,
Complex[] beta,
Complex[,] vl,
Complex[,] vr,
out int ilo,
out int ihi,
double[] lscale,
double[] rscale,
out double abnrm,
out double bbnrm,
double[] rconde,
double[] rcondv,
out int info
)```
Visual Basic
```Public Shared Sub f08wp ( _
balanc As String, _
jobvl As String, _
jobvr As String, _
sense As String, _
n As Integer, _
a As Complex(,), _
b As Complex(,), _
alpha As Complex(), _
beta As Complex(), _
vl As Complex(,), _
vr As Complex(,), _
<OutAttribute> ByRef ilo As Integer, _
<OutAttribute> ByRef ihi As Integer, _
lscale As Double(), _
rscale As Double(), _
<OutAttribute> ByRef abnrm As Double, _
<OutAttribute> ByRef bbnrm As Double, _
rconde As Double(), _
rcondv As Double(), _
<OutAttribute> ByRef info As Integer _
)```
Visual C++
```public:
static void f08wp(
String^ balanc,
String^ jobvl,
String^ jobvr,
String^ sense,
int n,
array<Complex,2>^ a,
array<Complex,2>^ b,
array<Complex>^ alpha,
array<Complex>^ beta,
array<Complex,2>^ vl,
array<Complex,2>^ vr,
[OutAttribute] int% ilo,
[OutAttribute] int% ihi,
array<double>^ lscale,
array<double>^ rscale,
[OutAttribute] double% abnrm,
[OutAttribute] double% bbnrm,
array<double>^ rconde,
array<double>^ rcondv,
[OutAttribute] int% info
)```
F#
```static member f08wp :
balanc : string *
jobvl : string *
jobvr : string *
sense : string *
n : int *
a : Complex[,] *
b : Complex[,] *
alpha : Complex[] *
beta : Complex[] *
vl : Complex[,] *
vr : Complex[,] *
ilo : int byref *
ihi : int byref *
lscale : float[] *
rscale : float[] *
abnrm : float byref *
bbnrm : float byref *
rconde : float[] *
rcondv : float[] *
info : int byref -> unit
```

#### Parameters

balanc
Type: System..::..String
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"}$.
jobvl
Type: System..::..String
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"}$.
jobvr
Type: System..::..String
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"}$.
sense
Type: System..::..String
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"}$.
n
Type: System..::..Int32
On entry: $n$, the order of the matrices $A$ and $B$.
Constraint: ${\mathbf{n}}\ge 0$.
a
Type: array<NagLibrary..::..Complex,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
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 Schur form of the ‘balanced’ versions of the input $A$ and $B$.
b
Type: array<NagLibrary..::..Complex,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
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.
alpha
Type: array<NagLibrary..::..Complex>[]()[][]
An array of size [n]
On exit: see the description of beta.
beta
Type: array<NagLibrary..::..Complex>[]()[][]
An array of size [n]
On exit: ${\mathbf{alpha}}\left[\mathit{j}-1\right]/{\mathbf{beta}}\left[\mathit{j}-1\right]$, for $\mathit{j}=1,2,\dots ,{\mathbf{n}}$, will be the generalized eigenvalues.
Note:  the quotients ${\mathbf{alpha}}\left[j-1\right]/{\mathbf{beta}}\left[j-1\right]$ may easily overflow or underflow, and ${\mathbf{beta}}\left[j-1\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}$.
vl
Type: array<NagLibrary..::..Complex,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint:
• if ${\mathbf{jobvl}}=\text{"V"}$, $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise $\mathrm{dim1}\ge 1$.
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 generalized eigenvectors ${u}_{j}$ are stored one after another in the columns of vl, in the same order as the corresponding eigenvalues. Each eigenvector will be scaled so the largest component will have $\left|\text{real part}\right|+\left|\text{imag. part}\right|=1$.
If ${\mathbf{jobvl}}=\text{"N"}$, vl is not referenced.
vr
Type: array<NagLibrary..::..Complex,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint:
• if ${\mathbf{jobvr}}=\text{"V"}$, $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise $\mathrm{dim1}\ge 1$.
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 generalized eigenvectors ${v}_{j}$ are stored one after another in the columns of vr, in the same order as the corresponding eigenvalues. Each eigenvector will be scaled so the largest component will have $\left|\text{real part}\right|+\left|\text{imag. part}\right|=1$.
If ${\mathbf{jobvr}}=\text{"N"}$, vr is not referenced.
ilo
Type: System..::..Int32%
On exit: ilo and ihi are integer values such that ${\mathbf{a}}\left[i-1,j-1\right]=0$ and ${\mathbf{b}}\left[i-1,j-1\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}}$.
ihi
Type: System..::..Int32%
On exit: ilo and ihi are integer values such that ${\mathbf{a}}\left[i-1,j-1\right]=0$ and ${\mathbf{b}}\left[i-1,j-1\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}}$.
lscale
Type: array<System..::..Double>[]()[][]
An array of size [n]
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}-1\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$.
rscale
Type: array<System..::..Double>[]()[][]
An array of size [n]
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}-1\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$.
abnrm
Type: System..::..Double%
On exit: the $1$-norm of the balanced matrix $A$.
bbnrm
Type: System..::..Double%
On exit: the $1$-norm of the balanced matrix $B$.
rconde
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
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.
If ${\mathbf{sense}}=\text{"N"}$ or $\text{"V"}$, rconde is not referenced.
rcondv
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
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 selected eigenvectors, stored in consecutive elements of the array.
If ${\mathbf{sense}}=\text{"N"}$ or $\text{"E"}$, rcondv is not referenced.
info
Type: System..::..Int32%
On exit: ${\mathbf{info}}=0$ unless the method detects an error (see [Error Indicators and Warnings]).

# 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 generalized eigenvector ${v}_{j}$ corresponding to the generalized eigenvalue ${\lambda }_{j}$ of $\left(A,B\right)$ satisfies
 $Avj=λjBvj.$
The left generalized eigenvector ${u}_{j}$ corresponding to the generalized eigenvalue ${\lambda }_{j}$ of $\left(A,B\right)$ satisfies
 $ujHA=λjujHB,$
where ${u}_{j}^{\mathrm{H}}$ is the conjugate-transpose of ${u}_{j}$.
All the eigenvalues and, if required, all the eigenvectors of the complex generalized eigenproblem $Ax=\lambda Bx$, where $A$ and $B$ are complex, square matrices, are determined using the $QZ$ algorithm. The complex $QZ$ algorithm consists of three stages:
1. $A$ is reduced to upper Hessenberg form (with real, non-negative subdiagonal elements) and at the same time $B$ is reduced to upper triangular form.
2. $A$ is further reduced to triangular form while the triangular form of $B$ is maintained and the diagonal elements of $B$ are made real and non-negative. This is the generalized Schur form of the pair $\left(A,B\right)$.
This method 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.
3. 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 [Description] in f08wv.

# 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

# Error Indicators and Warnings

Some error messages may refer to parameters that are dropped from this interface (LDA, LDB, LDVL, LDVR) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\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.
${\mathbf{info}}=1 \text{to} {\mathbf{n}}$
The $QZ$ iteration failed. No eigenvectors have been calculated, but ${\mathbf{alpha}}\left[j-1\right]$ and ${\mathbf{beta}}\left[j-1\right]$ should be correct for $j={\mathbf{info}}+1,\dots ,{\mathbf{n}}$.
${\mathbf{info}}={\mathbf{n}}+1$
Unexpected error returned from f08xs.
${\mathbf{info}}={\mathbf{n}}+2$
Error returned from f08yx.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

The computed eigenvalues and eigenvectors are exact for a nearby matrices $\left(A+E\right)$ and $\left(B+F\right)$, where
 $E,FF=OεA,BF,$
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/rconde[i-1].$
An approximate error bound for the angle between the $i$th computed eigenvector ${u}_{j}$ or ${v}_{j}$ is given by
 $ε×abnrm,bbnrm2/rcondv[i-1].$
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.

# Parallelism and Performance

None.

The total number of floating-point operations is proportional to ${n}^{3}$.
The real analogue of this method is f08wb.

# Example

This example finds all the eigenvalues and right eigenvectors of the matrix pair $\left(A,B\right)$, where
 $A= -21.10-22.50i 53.50-50.50i -34.50+127.50i 7.50+00.50i -0.46-07.78i -3.50-37.50i -15.50+058.50i -10.50-01.50i 4.30-05.50i 39.70-17.10i -68.50+012.50i -7.50-03.50i 5.50+04.40i 14.40+43.30i -32.50-046.00i -19.00-32.50i$
and
 $B= 1.00-5.00i 1.60+1.20i -3.00+0.00i 0.00-1.00i 0.80-0.60i 3.00-5.00i -4.00+3.00i -2.40-3.20i 1.00+0.00i 2.40+1.80i -4.00-5.00i 0.00-3.00i 0.00+1.00i -1.80+2.40i 0.00-4.00i 4.00-5.00i ,$
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.

Example program (C#): f08wpe.cs

Example program data: f08wpe.d

Example program results: f08wpe.r