f08 Chapter Contents
f08 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_zhgeqz (f08xsc)

## 1  Purpose

nag_zhgeqz (f08xsc) 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.

## 2  Specification

 #include #include
 void nag_zhgeqz (Nag_OrderType order, Nag_JobType job, Nag_ComputeQType compq, Nag_ComputeZType compz, Integer n, Integer ilo, Integer ihi, Complex a[], Integer pda, Complex b[], Integer pdb, Complex alpha[], Complex beta[], Complex q[], Integer pdq, Complex z[], Integer pdz, NagError *fail)

## 3  Description

nag_zhgeqz (f08xsc) 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 function nag_zgghrd (f08wsc) should be called before invoking nag_zhgeqz (f08xsc).
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 function 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}}=\mathrm{Nag_Schur}$ 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}}=\mathrm{Nag_EigVals}$, 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}}=\mathrm{Nag_Schur}$ and ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$ or $\mathrm{Nag_InitQ}$, and ${\mathbf{compz}}=\mathrm{Nag_AccumulateZ}$ or $\mathrm{Nag_InitZ}$, 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}}=\mathrm{Nag_Schur}$ and if left (right) generalized eigenvectors are to be computed then compq (compz) must be set to ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$ or $\mathrm{Nag_InitQ}$ rather than ${\mathbf{compq}}=\mathrm{Nag_NotQ}$.
If ${\mathbf{compq}}=\mathrm{Nag_InitQ}$, then eigenvectors are accumulated on the identity matrix and on exit the array q contains the left eigenvector matrix $Q$. However, if ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$ 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.

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

## 5  Arguments

1:     orderNag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or Nag_ColMajor.
2:     jobNag_JobTypeInput
On entry: specifies the operations to be performed on $\left(A,B\right)$.
${\mathbf{job}}=\mathrm{Nag_EigVals}$
The matrix pair $\left(A,B\right)$ on exit might not be in the generalized Schur form.
${\mathbf{job}}=\mathrm{Nag_Schur}$
The matrix pair $\left(A,B\right)$ on exit will be in the generalized Schur form.
Constraint: ${\mathbf{job}}=\mathrm{Nag_EigVals}$ or $\mathrm{Nag_Schur}$.
3:     compqNag_ComputeQTypeInput
On entry: specifies the operations to be performed on $Q$:
${\mathbf{compq}}=\mathrm{Nag_NotQ}$
The array q is unchanged.
${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$
The left transformation $Q$ is accumulated on the array q.
${\mathbf{compq}}=\mathrm{Nag_InitQ}$
The array q is initialized to the identity matrix before the left transformation $Q$ is accumulated in q.
Constraint: ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, $\mathrm{Nag_AccumulateQ}$ or $\mathrm{Nag_InitQ}$.
4:     compzNag_ComputeZTypeInput
On entry: specifies the operations to be performed on $Z$.
${\mathbf{compz}}=\mathrm{Nag_NotZ}$
The array z is unchanged.
${\mathbf{compz}}=\mathrm{Nag_AccumulateZ}$
The right transformation $Z$ is accumulated on the array z.
${\mathbf{compz}}=\mathrm{Nag_InitZ}$
The array z is initialized to the identity matrix before the right transformation $Z$ is accumulated in z.
Constraint: ${\mathbf{compz}}=\mathrm{Nag_NotZ}$, $\mathrm{Nag_AccumulateZ}$ or $\mathrm{Nag_InitZ}$.
5:     nIntegerInput
On entry: $n$, the order of the matrices $A$, $B$, $Q$ and $Z$.
Constraint: ${\mathbf{n}}\ge 0$.
6:     iloIntegerInput
7:     ihiIntegerInput
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 nag_zggbal (f08wvc) 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$.
8:     a[$\mathit{dim}$]ComplexInput/Output
Note: the dimension, dim, of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pda}}×{\mathbf{n}}\right)$.
The $\left(i,j\right)$th element of the matrix $A$ is stored in
• ${\mathbf{a}}\left[\left(j-1\right)×{\mathbf{pda}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{a}}\left[\left(i-1\right)×{\mathbf{pda}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
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}}=\mathrm{Nag_Schur}$, the matrix pair $\left(A,B\right)$ will be simultaneously reduced to generalized Schur form.
If ${\mathbf{job}}=\mathrm{Nag_EigVals}$, 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.
9:     pdaIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array a.
Constraint: ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
10:   b[$\mathit{dim}$]ComplexInput/Output
Note: the dimension, dim, of the array b must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdb}}×{\mathbf{n}}\right)$.
The $\left(i,j\right)$th element of the matrix $B$ is stored in
• ${\mathbf{b}}\left[\left(j-1\right)×{\mathbf{pdb}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{b}}\left[\left(i-1\right)×{\mathbf{pdb}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the $n$ by $n$ upper triangular matrix $B$. The elements below the diagonal must be zero.
On exit: if ${\mathbf{job}}=\mathrm{Nag_Schur}$, the matrix pair $\left(A,B\right)$ will be simultaneously reduced to generalized Schur form.
If ${\mathbf{job}}=\mathrm{Nag_EigVals}$, 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.
11:   pdbIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array b.
Constraint: ${\mathbf{pdb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
12:   alpha[n]ComplexOutput
On exit: ${\alpha }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
13:   beta[n]ComplexOutput
On exit: ${\beta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
14:   q[$\mathit{dim}$]ComplexInput/Output
Note: the dimension, dim, of the array q must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdq}}×{\mathbf{n}}\right)$ when ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$ or $\mathrm{Nag_InitQ}$;
• $1$ when ${\mathbf{compq}}=\mathrm{Nag_NotQ}$.
The $\left(i,j\right)$th element of the matrix $Q$ is stored in
• ${\mathbf{q}}\left[\left(j-1\right)×{\mathbf{pdq}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{q}}\left[\left(i-1\right)×{\mathbf{pdq}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: if ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$, the matrix ${Q}_{0}$. The matrix ${Q}_{0}$ is usually the matrix $Q$ returned by nag_zgghrd (f08wsc).
If ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, q is not referenced.
On exit: if ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$, q contains the matrix product $Q{Q}_{0}$.
If ${\mathbf{compq}}=\mathrm{Nag_InitQ}$, q contains the transformation matrix $Q$.
15:   pdqIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array q.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$ or $\mathrm{Nag_InitQ}$, ${\mathbf{pdq}}\ge {\mathbf{n}}$;
• if ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, ${\mathbf{pdq}}\ge 1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$,
• if ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$ or $\mathrm{Nag_InitQ}$, ${\mathbf{pdq}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, ${\mathbf{pdq}}\ge 1$.
16:   z[$\mathit{dim}$]ComplexInput/Output
Note: the dimension, dim, of the array z must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdz}}×{\mathbf{n}}\right)$ when ${\mathbf{compz}}=\mathrm{Nag_AccumulateZ}$ or $\mathrm{Nag_InitZ}$;
• $1$ when ${\mathbf{compz}}=\mathrm{Nag_NotZ}$.
The $\left(i,j\right)$th element of the matrix $Z$ is stored in
• ${\mathbf{z}}\left[\left(j-1\right)×{\mathbf{pdz}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{z}}\left[\left(i-1\right)×{\mathbf{pdz}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: if ${\mathbf{compz}}=\mathrm{Nag_AccumulateZ}$, the matrix ${Z}_{0}$. The matrix ${Z}_{0}$ is usually the matrix $Z$ returned by nag_zgghrd (f08wsc).
If ${\mathbf{compz}}=\mathrm{Nag_NotZ}$, z is not referenced.
On exit: if ${\mathbf{compz}}=\mathrm{Nag_AccumulateZ}$, z contains the matrix product $Z{Z}_{0}$.
If ${\mathbf{compz}}=\mathrm{Nag_InitZ}$, z contains the transformation matrix $Z$.
17:   pdzIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array z.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{compz}}=\mathrm{Nag_AccumulateZ}$ or $\mathrm{Nag_InitZ}$, ${\mathbf{pdz}}\ge {\mathbf{n}}$;
• if ${\mathbf{compz}}=\mathrm{Nag_NotZ}$, ${\mathbf{pdz}}\ge 1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$,
• if ${\mathbf{compz}}=\mathrm{Nag_AccumulateZ}$ or $\mathrm{Nag_InitZ}$, ${\mathbf{pdz}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{compz}}=\mathrm{Nag_NotZ}$, ${\mathbf{pdz}}\ge 1$.
18:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_ENUM_INT_2
On entry, ${\mathbf{compq}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdq}}=〈\mathit{\text{value}}〉$, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$ or $\mathrm{Nag_InitQ}$, ${\mathbf{pdq}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
if ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, ${\mathbf{pdq}}\ge 1$.
On entry, ${\mathbf{compq}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdq}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{compq}}=\mathrm{Nag_AccumulateQ}$ or $\mathrm{Nag_InitQ}$, ${\mathbf{pdq}}\ge {\mathbf{n}}$;
if ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, ${\mathbf{pdq}}\ge 1$.
On entry, ${\mathbf{compz}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdz}}=〈\mathit{\text{value}}〉$, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{compz}}=\mathrm{Nag_AccumulateZ}$ or $\mathrm{Nag_InitZ}$, ${\mathbf{pdz}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
if ${\mathbf{compz}}=\mathrm{Nag_NotZ}$, ${\mathbf{pdz}}\ge 1$.
On entry, ${\mathbf{compz}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdz}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{compz}}=\mathrm{Nag_AccumulateZ}$ or $\mathrm{Nag_InitZ}$, ${\mathbf{pdz}}\ge {\mathbf{n}}$;
if ${\mathbf{compz}}=\mathrm{Nag_NotZ}$, ${\mathbf{pdz}}\ge 1$.
NE_INT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{pda}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pda}}>0$.
On entry, ${\mathbf{pdb}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdb}}>0$.
On entry, ${\mathbf{pdq}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdq}}>0$.
On entry, ${\mathbf{pdz}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdz}}>0$.
NE_INT_2
On entry, ${\mathbf{pda}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{pdb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
NE_INT_3
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$, ${\mathbf{ilo}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ihi}}=〈\mathit{\text{value}}〉$.
Constraint: 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$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
An unexpected Library error has occurred.
NE_ITERATION_QZ
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}}〉$.
NE_SCHUR
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}}〉$.

## 7  Accuracy

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.

nag_zhgeqz (f08xsc) is the fifth step in the solution of the complex generalized eigenvalue problem and is called after nag_zgghrd (f08wsc).
The number of floating point operations taken by this function is proportional to ${n}^{3}$.
The real analogue of this function is nag_dhgeqz (f08xec).

## 9  Example

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 functions: nag_zggbal (f08wvc) to balance the matrix, nag_zgeqrf (f08asc) to perform the $QR$ factorization of $B$, nag_zunmqr (f08auc) to apply $Q$ to $A$, nag_zgghrd (f08wsc) to reduce the matrix pair to the generalized Hessenberg form and nag_zhgeqz (f08xsc) to compute the eigenvalues using the $QZ$ algorithm.

### 9.1  Program Text

Program Text (f08xsce.c)

### 9.2  Program Data

Program Data (f08xsce.d)

### 9.3  Program Results

Program Results (f08xsce.r)