# NAG FL Interfacef08pkf (dhsein)

## 1Purpose

f08pkf computes selected left and/or right eigenvectors of a real upper Hessenberg matrix corresponding to specified eigenvalues, by inverse iteration.

## 2Specification

Fortran Interface
 Subroutine f08pkf ( job, n, h, ldh, wr, wi, vl, ldvl, vr, ldvr, mm, m, work, info)
 Integer, Intent (In) :: n, ldh, ldvl, ldvr, mm Integer, Intent (Inout) :: ifaill(*), ifailr(*) Integer, Intent (Out) :: m, info Real (Kind=nag_wp), Intent (In) :: h(ldh,*), wi(*) Real (Kind=nag_wp), Intent (Inout) :: wr(*), vl(ldvl,*), vr(ldvr,*) Real (Kind=nag_wp), Intent (Out) :: work((n+2)*n) Logical, Intent (Inout) :: select(*) Character (1), Intent (In) :: job, eigsrc, initv
#include <nag.h>
 void f08pkf_ (const char *job, const char *eigsrc, const char *initv, logical sel[], const Integer *n, const double h[], const Integer *ldh, double wr[], const double wi[], double vl[], const Integer *ldvl, double vr[], const Integer *ldvr, const Integer *mm, Integer *m, double work[], Integer ifaill[], Integer ifailr[], Integer *info, const Charlen length_job, const Charlen length_eigsrc, const Charlen length_initv)
The routine may be called by the names f08pkf, nagf_lapackeig_dhsein or its LAPACK name dhsein.

## 3Description

f08pkf computes left and/or right eigenvectors of a real 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:
Note that even though $H$ is real, $\lambda$, $x$ and $y$ may be complex. If $x$ is an eigenvector corresponding to a complex eigenvalue $\lambda$, then the complex conjugate vector $\overline{x}$ is the eigenvector corresponding to the complex conjugate eigenvalue $\overline{\lambda }$.
The eigenvectors are computed by inverse iteration. They are scaled so that, for a real eigenvector $x$, $\mathrm{max}\left|{x}_{i}\right|=1$, and for a complex eigenvector, $\mathrm{max}\phantom{\rule{0.25em}{0ex}}\left|\mathrm{Re}\left({x}_{i}\right)\right|+\left|\mathrm{Im}{x}_{i}\right|=1$.
If $H$ has been formed by reduction of a real general matrix $A$ to upper Hessenberg form, then the eigenvectors of $H$ may be transformed to eigenvectors of $A$ by a call to f08ngf.

## 4References

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

## 5Arguments

1: $\mathbf{job}$Character(1) Input
On entry: indicates whether left and/or right eigenvectors are to be computed.
${\mathbf{job}}=\text{'R'}$
Only right eigenvectors are computed.
${\mathbf{job}}=\text{'L'}$
Only left eigenvectors are computed.
${\mathbf{job}}=\text{'B'}$
Both left and right eigenvectors are computed.
Constraint: ${\mathbf{job}}=\text{'R'}$, $\text{'L'}$ or $\text{'B'}$.
2: $\mathbf{eigsrc}$Character(1) Input
On entry: indicates whether the eigenvalues of $H$ (stored in wr and wi) were found using f08pef.
${\mathbf{eigsrc}}=\text{'Q'}$
The eigenvalues of $H$ were found using f08pef; 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 routine to perform inverse iteration on just one diagonal block.
${\mathbf{eigsrc}}=\text{'N'}$
No such assumption is made and the routine performs inverse iteration using the whole matrix.
Constraint: ${\mathbf{eigsrc}}=\text{'Q'}$ or $\text{'N'}$.
3: $\mathbf{initv}$Character(1) Input
On entry: indicates whether you are supplying initial estimates for the selected eigenvectors.
${\mathbf{initv}}=\text{'N'}$
No initial estimates are supplied.
${\mathbf{initv}}=\text{'U'}$
Initial estimates are supplied in vl and/or vr.
Constraint: ${\mathbf{initv}}=\text{'N'}$ or $\text{'U'}$.
4: $\mathbf{select}\left(*\right)$Logical array Input/Output
Note: the dimension 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 obtain the real eigenvector corresponding to the real eigenvalue ${\mathbf{wr}}\left(j\right)$, ${\mathbf{select}}\left(j\right)$ must be set .TRUE.. To select the complex eigenvector corresponding to the complex eigenvalue $\left({\mathbf{wr}}\left(j\right),{\mathbf{wi}}\left(j\right)\right)$ with complex conjugate (${\mathbf{wr}}\left(j+1\right),{\mathbf{wi}}\left(j+1\right)$), ${\mathbf{select}}\left(j\right)$ and/or ${\mathbf{select}}\left(j+1\right)$ must be set .TRUE.; the eigenvector corresponding to the first eigenvalue in the pair is computed.
On exit: if a complex eigenvector was selected as specified above, ${\mathbf{select}}\left(j\right)$ is set to .TRUE. and ${\mathbf{select}}\left(j+1\right)$ to .FALSE..
5: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrix $H$.
Constraint: ${\mathbf{n}}\ge 0$.
6: $\mathbf{h}\left({\mathbf{ldh}},*\right)$Real (Kind=nag_wp) array Input
Note: the second dimension of the array h 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 $H$. If a NaN is detected in h, the routine will return with ${\mathbf{info}}=-{\mathbf{6}}$.
Constraint: No element of h is equal to NaN.
7: $\mathbf{ldh}$Integer Input
On entry: the first dimension of the array h as declared in the (sub)program from which f08pkf is called.
Constraint: ${\mathbf{ldh}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
8: $\mathbf{wr}\left(*\right)$Real (Kind=nag_wp) array Input/Output
9: $\mathbf{wi}\left(*\right)$Real (Kind=nag_wp) array Input
Note: the dimension of the arrays wr and wi must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the real and imaginary parts, respectively, of the eigenvalues of the matrix $H$. Complex conjugate pairs of values must be stored in consecutive elements of the arrays. If ${\mathbf{eigsrc}}=\text{'Q'}$, the arrays must be exactly as returned by f08pef.
On exit: some elements of wr may be modified, as close eigenvalues are perturbed slightly in searching for independent eigenvectors.
10: $\mathbf{vl}\left({\mathbf{ldvl}},*\right)$Real (Kind=nag_wp) array Input/Output
Note: the second dimension of the array vl must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if ${\mathbf{job}}=\text{'L'}$ or $\text{'B'}$ and at least $1$ if ${\mathbf{job}}=\text{'R'}$.
On entry: if ${\mathbf{initv}}=\text{'U'}$ and ${\mathbf{job}}=\text{'L'}$ or $\text{'B'}$, vl must contain starting vectors for inverse iteration for the left eigenvectors. Each starting vector must be stored in the same column or columns as will be used to store the corresponding eigenvector (see below).
If ${\mathbf{initv}}=\text{'N'}$, vl need not be set.
On exit: if ${\mathbf{job}}=\text{'L'}$ or $\text{'B'}$, vl contains the computed left eigenvectors (as specified by select). The eigenvectors are stored consecutively in the columns of the array, in the same order as their eigenvalues. Corresponding to each selected real eigenvalue is a real eigenvector, occupying one column. Corresponding to each selected complex eigenvalue is a complex eigenvector, occupying two columns: the first column holds the real part and the second column holds the imaginary part.
If ${\mathbf{job}}=\text{'R'}$, vl is not referenced.
11: $\mathbf{ldvl}$Integer Input
On entry: the first dimension of the array vl as declared in the (sub)program from which f08pkf is called.
Constraints:
• if ${\mathbf{job}}=\text{'L'}$ or $\text{'B'}$, ${\mathbf{ldvl}}\ge {\mathbf{n}}$;
• if ${\mathbf{job}}=\text{'R'}$, ${\mathbf{ldvl}}\ge 1$.
12: $\mathbf{vr}\left({\mathbf{ldvr}},*\right)$Real (Kind=nag_wp) array Input/Output
Note: the second dimension of the array vr must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if ${\mathbf{job}}=\text{'R'}$ or $\text{'B'}$ and at least $1$ if ${\mathbf{job}}=\text{'L'}$.
On entry: if ${\mathbf{initv}}=\text{'U'}$ and ${\mathbf{job}}=\text{'R'}$ or $\text{'B'}$, vr must contain starting vectors for inverse iteration for the right eigenvectors. Each starting vector must be stored in the same column or columns as will be used to store the corresponding eigenvector (see below).
If ${\mathbf{initv}}=\text{'N'}$, vr need not be set.
On exit: if ${\mathbf{job}}=\text{'R'}$ or $\text{'B'}$, vr contains the computed right eigenvectors (as specified by select). The eigenvectors are stored consecutively in the columns of the array, in the same order as their eigenvalues. Corresponding to each selected real eigenvalue is a real eigenvector, occupying one column. Corresponding to each selected complex eigenvalue is a complex eigenvector, occupying two columns: the first column holds the real part and the second column holds the imaginary part.
If ${\mathbf{job}}=\text{'L'}$, vr is not referenced.
13: $\mathbf{ldvr}$Integer Input
On entry: the first dimension of the array vr as declared in the (sub)program from which f08pkf is called.
Constraints:
• if ${\mathbf{job}}=\text{'R'}$ or $\text{'B'}$, ${\mathbf{ldvr}}\ge {\mathbf{n}}$;
• if ${\mathbf{job}}=\text{'L'}$, ${\mathbf{ldvr}}\ge 1$.
14: $\mathbf{mm}$Integer Input
On entry: the number of columns in the arrays vl and/or vr. The actual number of columns required, $\mathit{m}$, is obtained by counting $1$ for each selected real eigenvector and $2$ for each selected complex eigenvector (see select); $0\le \mathit{m}\le n$.
Constraint: ${\mathbf{mm}}\ge \mathit{m}$.
15: $\mathbf{m}$Integer Output
On exit: $\mathit{m}$, the number of columns of vl and/or vr required to store the selected eigenvectors.
16: $\mathbf{work}\left(\left({\mathbf{n}}+2\right)×{\mathbf{n}}\right)$Real (Kind=nag_wp) array Workspace
17: $\mathbf{ifaill}\left(*\right)$Integer array Output
Note: the dimension of the array ifaill must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if ${\mathbf{job}}=\text{'L'}$ or $\text{'B'}$ and at least $1$ if ${\mathbf{job}}=\text{'R'}$.
On exit: if ${\mathbf{job}}=\text{'L'}$ or $\text{'B'}$, then ${\mathbf{ifaill}}\left(i\right)=0$ if the selected left eigenvector converged and ${\mathbf{ifaill}}\left(i\right)=j>0$ if the eigenvector stored in the $i$th column of vl (corresponding to the $j$th eigenvalue as held in $\left({\mathbf{wr}}\left(j\right),{\mathbf{wi}}\left(j\right)\right)$ failed to converge. If the $i$th and $\left(i+1\right)$th columns of vl contain a selected complex eigenvector, then ${\mathbf{ifaill}}\left(i\right)$ and ${\mathbf{ifaill}}\left(i+1\right)$ are set to the same value.
If ${\mathbf{job}}=\text{'R'}$, ifaill is not referenced.
18: $\mathbf{ifailr}\left(*\right)$Integer array Output
Note: the dimension of the array ifailr must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if ${\mathbf{job}}=\text{'R'}$ or $\text{'B'}$ and at least $1$ if ${\mathbf{job}}=\text{'L'}$.
On exit: if ${\mathbf{job}}=\text{'R'}$ or $\text{'B'}$, then ${\mathbf{ifailr}}\left(i\right)=0$ if the selected right eigenvector converged and ${\mathbf{ifailr}}\left(i\right)=j>0$ if the eigenvector stored in the $i$th row or column of vr (corresponding to the $j$th eigenvalue as held in $\left({\mathbf{wr}}\left(j\right),{\mathbf{wi}}\left(j\right)\right)$) failed to converge. If the $i$th and $\left(i+1\right)$th rows or columns of vr contain a selected complex eigenvector, then ${\mathbf{ifailr}}\left(i\right)$ and ${\mathbf{ifailr}}\left(i+1\right)$ are set to the same value.
If ${\mathbf{job}}=\text{'L'}$, ifailr is not referenced.
19: $\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}}>0$
$〈\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.

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

f08pkf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f08pkf 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.