# NAG Library Function Document

## 1Purpose

nag_zgghrd (f08wsc) reduces a pair of complex matrices $\left(A,B\right)$, where $B$ is upper triangular, to the generalized upper Hessenberg form using unitary transformations.

## 2Specification

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

## 3Description

nag_zgghrd (f08wsc) is usually the third step in the solution of the complex generalized eigenvalue problem
 $Ax=λBx.$
The (optional) first step balances the two matrices using nag_zggbal (f08wvc). In the second step, matrix $B$ is reduced to upper triangular form using the $QR$ factorization function nag_zgeqrf (f08asc) and this unitary transformation $Q$ is applied to matrix $A$ by calling nag_zunmqr (f08auc).
nag_zgghrd (f08wsc) reduces a pair of complex matrices $\left(A,B\right)$, where $B$ is triangular, to the generalized upper Hessenberg form using unitary transformations. This two-sided transformation is of the form
 $QHAZ=H QHBZ=T$
where $H$ is an upper Hessenberg matrix, $T$ is an upper triangular matrix and $Q$ and $Z$ are unitary matrices determined as products of Givens rotations. They may either be formed explicitly, or they may be postmultiplied into input matrices ${Q}_{1}$ and ${Z}_{1}$, so that
 $Q1AZ1H=Q1QHZ1ZH, Q1BZ1H=Q1QTZ1ZH.$

## 4References

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

## 5Arguments

1:    $\mathbf{order}$Nag_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.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2:    $\mathbf{compq}$Nag_ComputeQTypeInput
On entry: specifies the form of the computed unitary matrix $Q$.
${\mathbf{compq}}=\mathrm{Nag_NotQ}$
Do not compute $Q$.
${\mathbf{compq}}=\mathrm{Nag_InitQ}$
The unitary matrix $Q$ is returned.
${\mathbf{compq}}=\mathrm{Nag_UpdateSchur}$
q must contain a unitary matrix ${Q}_{1}$, and the product ${Q}_{1}Q$ is returned.
Constraint: ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, $\mathrm{Nag_InitQ}$ or $\mathrm{Nag_UpdateSchur}$.
3:    $\mathbf{compz}$Nag_ComputeZTypeInput
On entry: specifies the form of the computed unitary matrix $Z$.
${\mathbf{compz}}=\mathrm{Nag_NotZ}$
Do not compute $Z$.
${\mathbf{compz}}=\mathrm{Nag_UpdateZ}$
z must contain a unitary matrix ${Z}_{1}$, and the product ${Z}_{1}Z$ is returned.
${\mathbf{compz}}=\mathrm{Nag_InitZ}$
The unitary matrix $Z$ is returned.
Constraint: ${\mathbf{compz}}=\mathrm{Nag_NotZ}$, $\mathrm{Nag_UpdateZ}$ or $\mathrm{Nag_InitZ}$.
4:    $\mathbf{n}$IntegerInput
On entry: $n$, the order of the matrices $A$ and $B$.
Constraint: ${\mathbf{n}}\ge 0$.
5:    $\mathbf{ilo}$IntegerInput
6:    $\mathbf{ihi}$IntegerInput
On entry: ${i}_{\mathrm{lo}}$ and ${i}_{\mathrm{hi}}$ as determined by a previous call to nag_zggbal (f08wvc). Otherwise, they should be set to $1$ and $n$, respectively.
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[\mathit{dim}\right]$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 matrix $A$ of the matrix pair $\left(A,B\right)$. Usually, this is the matrix $A$ returned by nag_zunmqr (f08auc).
On exit: a is overwritten by the upper Hessenberg matrix $H$.
8:    $\mathbf{pda}$IntegerInput
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)$.
9:    $\mathbf{b}\left[\mathit{dim}\right]$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 upper triangular matrix $B$ of the matrix pair $\left(A,B\right)$. Usually, this is the matrix $B$ returned by the $QR$ factorization function nag_zgeqrf (f08asc).
On exit: b is overwritten by the upper triangular matrix $T$.
10:  $\mathbf{pdb}$IntegerInput
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)$.
11:  $\mathbf{q}\left[\mathit{dim}\right]$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_InitQ}$ or $\mathrm{Nag_UpdateSchur}$;
• $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_UpdateSchur}$, q must contain a unitary matrix ${Q}_{1}$.
If ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, q is not referenced.
On exit: if ${\mathbf{compq}}=\mathrm{Nag_InitQ}$, q contains the unitary matrix $Q$.
Iif ${\mathbf{compq}}=\mathrm{Nag_UpdateSchur}$, q is overwritten by ${Q}_{1}Q$.
12:  $\mathbf{pdq}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array q.
Constraints:
• if ${\mathbf{compq}}=\mathrm{Nag_InitQ}$ or $\mathrm{Nag_UpdateSchur}$, ${\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$.
13:  $\mathbf{z}\left[\mathit{dim}\right]$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_UpdateZ}$ 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_UpdateZ}$, z must contain a unitary matrix ${Z}_{1}$.
If ${\mathbf{compz}}=\mathrm{Nag_NotZ}$, z is not referenced.
On exit: if ${\mathbf{compz}}=\mathrm{Nag_InitZ}$, z contains the unitary matrix $Z$.
If ${\mathbf{compz}}=\mathrm{Nag_UpdateZ}$, z is overwritten by ${Z}_{1}Z$.
14:  $\mathbf{pdz}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array z.
Constraints:
• if ${\mathbf{compz}}=\mathrm{Nag_UpdateZ}$ 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$.
15:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
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}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{compq}}=\mathrm{Nag_InitQ}$ or $\mathrm{Nag_UpdateSchur}$, ${\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{compz}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdz}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{compz}}=\mathrm{Nag_UpdateZ}$ 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$.
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: ${\mathbf{ilo}}\ge 1$ and
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.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

The reduction to the generalized Hessenberg form is implemented using unitary transformations which are backward stable.

## 8Parallelism and Performance

nag_zgghrd (f08wsc) is not threaded in any implementation.

This function is usually followed by nag_zhgeqz (f08xsc) which implements the $QZ$ algorithm for computing generalized eigenvalues of a reduced pair of matrices.