# NAG FL Interfacef08xsf (zhgeqz)

## 1Purpose

f08xsf implements the $QZ$ method for finding generalized eigenvalues of the complex matrix pair $\left(A,B\right)$ of order $n$, which is in the generalized upper Hessenberg form.

## 2Specification

Fortran Interface
 Subroutine f08xsf ( job, n, ilo, ihi, a, lda, b, ldb, beta, q, ldq, z, ldz, work, info)
 Integer, Intent (In) :: n, ilo, ihi, lda, ldb, ldq, ldz, lwork Integer, Intent (Out) :: info Real (Kind=nag_wp), Intent (Out) :: rwork(n) Complex (Kind=nag_wp), Intent (Inout) :: a(lda,*), b(ldb,*), q(ldq,*), z(ldz,*) Complex (Kind=nag_wp), Intent (Out) :: alpha(n), beta(n), work(max(1,lwork)) Character (1), Intent (In) :: job, compq, compz
#include <nag.h>
 void f08xsf_ (const char *job, const char *compq, const char *compz, const Integer *n, const Integer *ilo, const Integer *ihi, Complex a[], const Integer *lda, Complex b[], const Integer *ldb, Complex alpha[], Complex beta[], Complex q[], const Integer *ldq, Complex z[], const Integer *ldz, Complex work[], const Integer *lwork, double rwork[], Integer *info, const Charlen length_job, const Charlen length_compq, const Charlen length_compz)
The routine may be called by the names f08xsf, nagf_lapackeig_zhgeqz or its LAPACK name zhgeqz.

## 3Description

f08xsf implements a single-shift version of the $QZ$ method for finding the generalized eigenvalues of the complex matrix pair $\left(A,B\right)$ which is in the generalized upper Hessenberg form. If the matrix pair $\left(A,B\right)$ is not in the generalized upper Hessenberg form, then the routine f08wsf should be called before invoking f08xsf.
This problem is mathematically equivalent to solving the matrix equation
 $detA-λB=0.$
Note that, to avoid underflow, overflow and other arithmetic problems, the generalized eigenvalues ${\lambda }_{j}$ are never computed explicitly by this routine but defined as ratios between two computed values, ${\alpha }_{j}$ and ${\beta }_{j}$:
 $λj=αj/βj.$
The arguments ${\alpha }_{j}$, in general, are finite complex values and ${\beta }_{j}$ are finite real non-negative values.
If desired, the matrix pair $\left(A,B\right)$ may be reduced to generalized Schur form. That is, the transformed matrices $A$ and $B$ are upper triangular and the diagonal values of $A$ and $B$ provide $\alpha$ and $\beta$.
The argument job specifies two options. If ${\mathbf{job}}=\text{'S'}$ then the matrix pair $\left(A,B\right)$ is simultaneously reduced to Schur form by applying one unitary transformation (usually called $Q$) on the left and another (usually called $Z$) on the right. That is,
 $A←QHAZ B←QHBZ$
If ${\mathbf{job}}=\text{'E'}$, then at each iteration the same transformations are computed but they are only applied to those parts of $A$ and $B$ which are needed to compute $\alpha$ and $\beta$. This option could be used if generalized eigenvalues are required but not generalized eigenvectors.
If ${\mathbf{job}}=\text{'S'}$ and ${\mathbf{compq}}=\text{'V'}$ or $\text{'I'}$, and ${\mathbf{compz}}=\text{'V'}$ or $\text{'I'}$, then the unitary transformations used to reduce the pair $\left(A,B\right)$ are accumulated into the input arrays q and z. If generalized eigenvectors are required then job must be set to ${\mathbf{job}}=\text{'S'}$ and if left (right) generalized eigenvectors are to be computed then compq (compz) must be set to ${\mathbf{compq}}=\text{'V'}$ or $\text{'I'}$ rather than ${\mathbf{compq}}=\text{'N'}$.
If ${\mathbf{compq}}=\text{'I'}$, then eigenvectors are accumulated on the identity matrix and on exit the array q contains the left eigenvector matrix $Q$. However, if ${\mathbf{compq}}=\text{'V'}$ then the transformations are accumulated in the user-supplied matrix ${Q}_{0}$ in array q on entry and thus on exit q contains the matrix product $Q{Q}_{0}$. A similar convention is used for compz.

## 4References

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
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Moler C B and Stewart G W (1973) An algorithm for generalized matrix eigenproblems SIAM J. Numer. Anal. 10 241–256
Stewart G W and Sun J-G (1990) Matrix Perturbation Theory Academic Press, London

## 5Arguments

1: $\mathbf{job}$Character(1) Input
On entry: specifies the operations to be performed on $\left(A,B\right)$.
${\mathbf{job}}=\text{'E'}$
The matrix pair $\left(A,B\right)$ on exit might not be in the generalized Schur form.
${\mathbf{job}}=\text{'S'}$
The matrix pair $\left(A,B\right)$ on exit will be in the generalized Schur form.
Constraint: ${\mathbf{job}}=\text{'E'}$ or $\text{'S'}$.
2: $\mathbf{compq}$Character(1) Input
On entry: specifies the operations to be performed on $Q$:
${\mathbf{compq}}=\text{'N'}$
The array q is unchanged.
${\mathbf{compq}}=\text{'V'}$
The left transformation $Q$ is accumulated on the array q.
${\mathbf{compq}}=\text{'I'}$
The array q is initialized to the identity matrix before the left transformation $Q$ is accumulated in q.
Constraint: ${\mathbf{compq}}=\text{'N'}$, $\text{'V'}$ or $\text{'I'}$.
3: $\mathbf{compz}$Character(1) Input
On entry: specifies the operations to be performed on $Z$.
${\mathbf{compz}}=\text{'N'}$
The array z is unchanged.
${\mathbf{compz}}=\text{'V'}$
The right transformation $Z$ is accumulated on the array z.
${\mathbf{compz}}=\text{'I'}$
The array z is initialized to the identity matrix before the right transformation $Z$ is accumulated in z.
Constraint: ${\mathbf{compz}}=\text{'N'}$, $\text{'V'}$ or $\text{'I'}$.
4: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrices $A$, $B$, $Q$ and $Z$.
Constraint: ${\mathbf{n}}\ge 0$.
5: $\mathbf{ilo}$Integer Input
6: $\mathbf{ihi}$Integer Input
On entry: the indices ${i}_{\mathrm{lo}}$ and ${i}_{\mathrm{hi}}$, respectively which define the upper triangular parts of $A$. The submatrices $A\left(1:{i}_{\mathrm{lo}}-1,1:{i}_{\mathrm{lo}}-1\right)$ and $A\left({i}_{\mathrm{hi}}+1:n,{i}_{\mathrm{hi}}+1:n\right)$ are then upper triangular. These arguments are provided by f08wvf if the matrix pair was previously balanced; otherwise, ${\mathbf{ilo}}=1$ and ${\mathbf{ihi}}={\mathbf{n}}$.
Constraints:
• if ${\mathbf{n}}>0$, $1\le {\mathbf{ilo}}\le {\mathbf{ihi}}\le {\mathbf{n}}$;
• if ${\mathbf{n}}=0$, ${\mathbf{ilo}}=1$ and ${\mathbf{ihi}}=0$.
7: $\mathbf{a}\left({\mathbf{lda}},*\right)$Complex (Kind=nag_wp) array Input/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 $n$ by $n$ upper Hessenberg matrix $A$. The elements below the first subdiagonal must be set to zero.
On exit: if ${\mathbf{job}}=\text{'S'}$, the matrix pair $\left(A,B\right)$ will be simultaneously reduced to generalized Schur form.
If ${\mathbf{job}}=\text{'E'}$, the $1$ by $1$ and $2$ by $2$ diagonal blocks of the matrix pair $\left(A,B\right)$ will give generalized eigenvalues but the remaining elements will be irrelevant.
8: $\mathbf{lda}$Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which f08xsf is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
9: $\mathbf{b}\left({\mathbf{ldb}},*\right)$Complex (Kind=nag_wp) array Input/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 $n$ by $n$ upper triangular matrix $B$. The elements below the diagonal must be zero.
On exit: if ${\mathbf{job}}=\text{'S'}$, the matrix pair $\left(A,B\right)$ will be simultaneously reduced to generalized Schur form.
If ${\mathbf{job}}=\text{'E'}$, the $1$ by $1$ and $2$ by $2$ diagonal blocks of the matrix pair $\left(A,B\right)$ will give generalized eigenvalues but the remaining elements will be irrelevant.
10: $\mathbf{ldb}$Integer Input
On entry: the first dimension of the array b as declared in the (sub)program from which f08xsf is called.
Constraint: ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
11: $\mathbf{alpha}\left({\mathbf{n}}\right)$Complex (Kind=nag_wp) array Output
On exit: ${\alpha }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
12: $\mathbf{beta}\left({\mathbf{n}}\right)$Complex (Kind=nag_wp) array Output
On exit: ${\beta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
13: $\mathbf{q}\left({\mathbf{ldq}},*\right)$Complex (Kind=nag_wp) array Input/Output
Note: the second dimension of the array q must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{compq}}=\text{'V'}$ or $\text{'I'}$ and at least $1$ if ${\mathbf{compq}}=\text{'N'}$.
On entry: if ${\mathbf{compq}}=\text{'V'}$, the matrix ${Q}_{0}$. The matrix ${Q}_{0}$ is usually the matrix $Q$ returned by f08wsf.
If ${\mathbf{compq}}=\text{'N'}$, q is not referenced.
On exit: if ${\mathbf{compq}}=\text{'V'}$, q contains the matrix product $Q{Q}_{0}$.
If ${\mathbf{compq}}=\text{'I'}$, q contains the transformation matrix $Q$.
14: $\mathbf{ldq}$Integer Input
On entry: the first dimension of the array q as declared in the (sub)program from which f08xsf is called.
Constraints:
• if ${\mathbf{compq}}=\text{'V'}$ or $\text{'I'}$, ${\mathbf{ldq}}\ge {\mathbf{n}}$;
• if ${\mathbf{compq}}=\text{'N'}$, ${\mathbf{ldq}}\ge 1$.
15: $\mathbf{z}\left({\mathbf{ldz}},*\right)$Complex (Kind=nag_wp) array Input/Output
Note: the second dimension of the array z must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{compz}}=\text{'V'}$ or $\text{'I'}$ and at least $1$ if ${\mathbf{compz}}=\text{'N'}$.
On entry: if ${\mathbf{compz}}=\text{'V'}$, the matrix ${Z}_{0}$. The matrix ${Z}_{0}$ is usually the matrix $Z$ returned by f08wsf.
If ${\mathbf{compz}}=\text{'N'}$, z is not referenced.
On exit: if ${\mathbf{compz}}=\text{'V'}$, z contains the matrix product $Z{Z}_{0}$.
If ${\mathbf{compz}}=\text{'I'}$, z contains the transformation matrix $Z$.
16: $\mathbf{ldz}$Integer Input
On entry: the first dimension of the array z as declared in the (sub)program from which f08xsf is called.
Constraints:
• if ${\mathbf{compz}}=\text{'V'}$ or $\text{'I'}$, ${\mathbf{ldz}}\ge {\mathbf{n}}$;
• if ${\mathbf{compz}}=\text{'N'}$, ${\mathbf{ldz}}\ge 1$.
17: $\mathbf{work}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{lwork}}\right)\right)$Complex (Kind=nag_wp) array Workspace
On exit: if ${\mathbf{info}}={\mathbf{0}}$, the real part of ${\mathbf{work}}\left(1\right)$ contains the minimum value of lwork required for optimal performance.
18: $\mathbf{lwork}$Integer Input
On entry: the dimension of the array work as declared in the (sub)program from which f08xsf is called.
If ${\mathbf{lwork}}=-1$, a workspace query is assumed; the routine only calculates the minimum 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.
Constraint: ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ or ${\mathbf{lwork}}=-1$.
19: $\mathbf{rwork}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Workspace
20: $\mathbf{info}$Integer Output
On exit: ${\mathbf{info}}=0$ unless the routine detects an error (see Section 6).

## 6Error Indicators and Warnings

${\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,\dots ,{\mathbf{n}}$
The $QZ$ iteration did not converge and the matrix pair $\left(A,B\right)$ is not in the generalized Schur form. The computed ${\alpha }_{i}$ and ${\beta }_{i}$ should be correct for $i=〈\mathit{\text{value}}〉,\dots ,〈\mathit{\text{value}}〉$.
${\mathbf{info}}>{\mathbf{n}}$ and ${\mathbf{info}}\le 2×{\mathbf{n}}$
The computation of shifts failed and the matrix pair $\left(A,B\right)$ is not in the generalized Schur form. The computed ${\alpha }_{i}$ and ${\beta }_{i}$ should be correct for $i=〈\mathit{\text{value}}〉,\dots ,〈\mathit{\text{value}}〉$.
${\mathbf{info}}>2×{\mathbf{n}}$
An unexpected Library error has occurred.

## 7Accuracy

Please consult Section 4.11 of the LAPACK Users' Guide (see Anderson et al. (1999)) and Chapter 6 of Stewart and Sun (1990), for more information.

## 8Parallelism and Performance

f08xsf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

f08xsf is the fifth step in the solution of the complex generalized eigenvalue problem and is called after f08wsf.
The number of floating-point operations taken by this routine is proportional to ${n}^{3}$.
The real analogue of this routine is f08xef.

## 10Example

This example computes the $\alpha$ and $\beta$ arguments, which defines the generalized eigenvalues, of the matrix pair $\left(A,B\right)$ given by
 $A = 1.0+3.0i 1.0+4.0i 1.0+5.0i 1.0+6.0i 2.0+2.0i 4.0+3.0i 8.0+4.0i 16.0+5.0i 3.0+1.0i 9.0+2.0i 27.0+3.0i 81.0+4.0i 4.0+0.0i 16.0+1.0i 64.0+2.0i 256.0+3.0i$
and
 $B = 1.0+0.0i 2.0+1.0i 3.0+2.0i 4.0+3.0i 1.0+1.0i 4.0+2.0i 9.0+3.0i 16.0+4.0i 1.0+2.0i 8.0+3.0i 27.0+4.0i 64.0+5.0i 1.0+3.0i 16.0+4.0i 81.0+5.0i 256.0+6.0i .$
This requires calls to five routines: f08wvf to balance the matrix, f08asf to perform the $QR$ factorization of $B$, f08auf to apply $Q$ to $A$, f08wsf to reduce the matrix pair to the generalized Hessenberg form and f08xsf to compute the eigenvalues using the $QZ$ algorithm.

### 10.1Program Text

Program Text (f08xsfe.f90)

### 10.2Program Data

Program Data (f08xsfe.d)

### 10.3Program Results

Program Results (f08xsfe.r)