# NAG Library Function Document

## 1Purpose

nag_zhsein (f08pxc) computes selected left and/or right eigenvectors of a complex upper Hessenberg matrix corresponding to specified eigenvalues, by inverse iteration.

## 2Specification

 #include #include
 void nag_zhsein (Nag_OrderType order, Nag_SideType side, Nag_EigValsSourceType eig_source, Nag_InitVeenumtype initv, const Nag_Boolean select[], Integer n, const Complex h[], Integer pdh, Complex w[], Complex vl[], Integer pdvl, Complex vr[], Integer pdvr, Integer mm, Integer *m, Integer ifaill[], Integer ifailr[], NagError *fail)

## 3Description

nag_zhsein (f08pxc) computes left and/or right eigenvectors of a complex upper Hessenberg matrix $H$, corresponding to selected eigenvalues.
The right eigenvector $x$, and the left eigenvector $y$, corresponding to an eigenvalue $\lambda$, are defined by:
The eigenvectors are computed by inverse iteration. They are scaled so that $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\left|\mathrm{Re}\left({x}_{i}\right)\right|+\left|\mathrm{Im}{x}_{i}\right|\right)=1$.
If $H$ has been formed by reduction of a complex general matrix $A$ to upper Hessenberg form, then the eigenvectors of $H$ may be transformed to eigenvectors of $A$ by a call to nag_zunmhr (f08nuc).

## 4References

Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 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{side}$Nag_SideTypeInput
On entry: indicates whether left and/or right eigenvectors are to be computed.
${\mathbf{side}}=\mathrm{Nag_RightSide}$
Only right eigenvectors are computed.
${\mathbf{side}}=\mathrm{Nag_LeftSide}$
Only left eigenvectors are computed.
${\mathbf{side}}=\mathrm{Nag_BothSides}$
Both left and right eigenvectors are computed.
Constraint: ${\mathbf{side}}=\mathrm{Nag_RightSide}$, $\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$.
3:    $\mathbf{eig_source}$Nag_EigValsSourceTypeInput
On entry: indicates whether the eigenvalues of $H$ (stored in w) were found using nag_zhseqr (f08psc).
${\mathbf{eig_source}}=\mathrm{Nag_HSEQRSource}$
The eigenvalues of $H$ were found using nag_zhseqr (f08psc); thus if $H$ has any zero subdiagonal elements (and so is block triangular), then the $j$th eigenvalue can be assumed to be an eigenvalue of the block containing the $j$th row/column. This property allows the function to perform inverse iteration on just one diagonal block.
${\mathbf{eig_source}}=\mathrm{Nag_NotKnown}$
No such assumption is made and the function performs inverse iteration using the whole matrix.
Constraint: ${\mathbf{eig_source}}=\mathrm{Nag_HSEQRSource}$ or $\mathrm{Nag_NotKnown}$.
4:    $\mathbf{initv}$Nag_InitVeenumtypeInput
On entry: indicates whether you are supplying initial estimates for the selected eigenvectors.
${\mathbf{initv}}=\mathrm{Nag_NoVec}$
No initial estimates are supplied.
${\mathbf{initv}}=\mathrm{Nag_UserVec}$
Initial estimates are supplied in vl and/or vr.
Constraint: ${\mathbf{initv}}=\mathrm{Nag_NoVec}$ or $\mathrm{Nag_UserVec}$.
5:    $\mathbf{select}\left[\mathit{dim}\right]$const Nag_BooleanInput
Note: the dimension, dim, of the array select must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: specifies which eigenvectors are to be computed. To select the eigenvector corresponding to the eigenvalue ${\mathbf{w}}\left[j-1\right]$, ${\mathbf{select}}\left[j-1\right]$ must be set to Nag_TRUE.
6:    $\mathbf{n}$IntegerInput
On entry: $n$, the order of the matrix $H$.
Constraint: ${\mathbf{n}}\ge 0$.
7:    $\mathbf{h}\left[\mathit{dim}\right]$const ComplexInput
Note: the dimension, dim, of the array h must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdh}}×{\mathbf{n}}\right)$.
The $\left(i,j\right)$th element of the matrix $H$ is stored in
• ${\mathbf{h}}\left[\left(j-1\right)×{\mathbf{pdh}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{h}}\left[\left(i-1\right)×{\mathbf{pdh}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the $n$ by $n$ upper Hessenberg matrix $H$. If a NaN is detected in h, the function will return with ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_BAD_PARAM.
Constraint: No element of h is equal to NaN.
8:    $\mathbf{pdh}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array h.
Constraint: ${\mathbf{pdh}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
9:    $\mathbf{w}\left[\mathit{dim}\right]$ComplexInput/Output
Note: the dimension, dim, of the array w must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the eigenvalues of the matrix $H$. If ${\mathbf{eig_source}}=\mathrm{Nag_HSEQRSource}$, the array must be exactly as returned by nag_zhseqr (f08psc).
On exit: the real parts of some elements of w may be modified, as close eigenvalues are perturbed slightly in searching for independent eigenvectors.
10:  $\mathbf{vl}\left[\mathit{dim}\right]$ComplexInput/Output
Note: the dimension, dim, of the array vl must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdvl}}×{\mathbf{mm}}\right)$ when ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$ and ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×{\mathbf{pdvl}}\right)$ when ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$ and ${\mathbf{order}}=\mathrm{Nag_RowMajor}$;
• $1$ when ${\mathbf{side}}=\mathrm{Nag_RightSide}$.
The $\left(i,j\right)$th element of the matrix is stored in
• ${\mathbf{vl}}\left[\left(j-1\right)×{\mathbf{pdvl}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{vl}}\left[\left(i-1\right)×{\mathbf{pdvl}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: if ${\mathbf{initv}}=\mathrm{Nag_UserVec}$ and ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, vl must contain starting vectors for inverse iteration for the left eigenvectors. Each starting vector must be stored in the same row or column as will be used to store the corresponding eigenvector (see below).
If ${\mathbf{initv}}=\mathrm{Nag_NoVec}$, vl need not be set.
On exit: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, vl contains the computed left eigenvectors (as specified by select). The eigenvectors are stored consecutively in the rows or columns of the array (depending on the value of order), in the same order as their eigenvalues.
If ${\mathbf{side}}=\mathrm{Nag_RightSide}$, vl is not referenced.
11:  $\mathbf{pdvl}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array vl.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge {\mathbf{n}}$;
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{pdvl}}\ge 1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$,
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$;
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{pdvl}}\ge 1$.
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{pdvl}}\ge 1$.
12:  $\mathbf{vr}\left[\mathit{dim}\right]$ComplexInput/Output
Note: the dimension, dim, of the array vr must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdvr}}×{\mathbf{mm}}\right)$ when ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$ and ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×{\mathbf{pdvr}}\right)$ when ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$ and ${\mathbf{order}}=\mathrm{Nag_RowMajor}$;
• $1$ when ${\mathbf{side}}=\mathrm{Nag_LeftSide}$.
The $\left(i,j\right)$th element of the matrix is stored in
• ${\mathbf{vr}}\left[\left(j-1\right)×{\mathbf{pdvr}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{vr}}\left[\left(i-1\right)×{\mathbf{pdvr}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: if ${\mathbf{initv}}=\mathrm{Nag_UserVec}$ and ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, vr must contain starting vectors for inverse iteration for the right eigenvectors. Each starting vector must be stored in the same row or column as will be used to store the corresponding eigenvector (see below).
If ${\mathbf{initv}}=\mathrm{Nag_NoVec}$, vr need not be set.
On exit: if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, vr contains the computed right eigenvectors (as specified by select). The eigenvectors are stored consecutively in the rows or columns of the array (depending on the value of order), in the same order as their eigenvalues.
If ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, vr is not referenced.
13:  $\mathbf{pdvr}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array vr.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge {\mathbf{n}}$;
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{pdvr}}\ge 1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$,
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$;
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{pdvr}}\ge 1$.
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{pdvr}}\ge 1$.
14:  $\mathbf{mm}$IntegerInput
On entry: the number of columns in the arrays vl and/or vr if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$ or the number of rows in the arrays if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. This must be an upper bound on the actual number of rows or columns required, that is, the number of elements of select, in the first n, that are set to Nag_TRUE.
Constraint: ${\mathbf{mm}}\ge \mathit{required_rowcol}$.
15:  $\mathbf{m}$Integer *Output
On exit: $\mathit{required_rowcol}$, the number of selected eigenvectors.
16:  $\mathbf{ifaill}\left[\mathit{dim}\right]$IntegerOutput
Note: the dimension, dim, of the array ifaill must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ when ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$;
• $1$ when ${\mathbf{side}}=\mathrm{Nag_RightSide}$.
On exit: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, then ${\mathbf{ifaill}}\left[i-1\right]=0$ if the selected left eigenvector converged and ${\mathbf{ifaill}}\left[i-1\right]=j\ge 0$ if the eigenvector stored in the $i$th row or column of vl (corresponding to the $j$th eigenvalue) failed to converge.
If ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ifaill is not referenced.
17:  $\mathbf{ifailr}\left[\mathit{dim}\right]$IntegerOutput
Note: the dimension, dim, of the array ifailr must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ when ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$;
• $1$ when ${\mathbf{side}}=\mathrm{Nag_LeftSide}$.
On exit: if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, then ${\mathbf{ifailr}}\left[i-1\right]=0$ if the selected right eigenvector converged and ${\mathbf{ifailr}}\left[i-1\right]=j\ge 0$ if the eigenvector stored in the $i$th column of vr (corresponding to the $j$th eigenvalue) failed to converge.
If ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ifailr is not referenced.
18:  $\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.
Constraint: No element of h is equal to NaN.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_CONVERGENCE
$〈\mathit{\text{value}}〉$ eigenvectors (as indicated by arguments ifaill and/or ifailr) failed to converge. The corresponding columns of vl and/or vr contain no useful information.
NE_ENUM_INT_2
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvl}}=〈\mathit{\text{value}}〉$, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{pdvl}}\ge 1$.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvl}}=〈\mathit{\text{value}}〉$, ${\mathbf{mm}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$;
if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{pdvl}}\ge 1$.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvl}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge {\mathbf{n}}$;
if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{pdvl}}\ge 1$.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvr}}=〈\mathit{\text{value}}〉$, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{pdvr}}\ge 1$.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvr}}=〈\mathit{\text{value}}〉$, ${\mathbf{mm}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$;
if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{pdvr}}\ge 1$.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvr}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge {\mathbf{n}}$;
if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{pdvr}}\ge 1$.
NE_INT
On entry, ${\mathbf{mm}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mm}}\ge \mathit{required_rowcol}$, where $\mathit{required_rowcol}$ is the number of selected eigenvectors.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{pdh}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdh}}>0$.
On entry, ${\mathbf{pdvl}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdvl}}>0$.
On entry, ${\mathbf{pdvr}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdvr}}>0$.
NE_INT_2
On entry, ${\mathbf{pdh}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdh}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
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

Each computed right eigenvector ${x}_{i}$ is the exact eigenvector of a nearby matrix $A+{E}_{i}$, such that $‖{E}_{i}‖=\mathit{O}\left(\epsilon \right)‖A‖$. Hence the residual is small:
 $Axi - λixi = Oε A .$
However, eigenvectors corresponding to close or coincident eigenvalues may not accurately span the relevant subspaces.
Similar remarks apply to computed left eigenvectors.

## 8Parallelism and Performance

nag_zhsein (f08pxc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_zhsein (f08pxc) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.