Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_lapack_dhsein (f08pk)

## Purpose

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

## Syntax

[select, wr, vl, vr, m, ifaill, ifailr, info] = f08pk(job, eigsrc, initv, select, h, wr, wi, vl, vr, mm, 'n', n)
[select, wr, vl, vr, m, ifaill, ifailr, info] = nag_lapack_dhsein(job, eigsrc, initv, select, h, wr, wi, vl, vr, mm, 'n', n)

## Description

nag_lapack_dhsein (f08pk) 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 $\stackrel{-}{x}$ is the eigenvector corresponding to the complex conjugate eigenvalue $\stackrel{-}{\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 nag_lapack_dormhr (f08ng).

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{job}$ – string (length ≥ 1)
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:     $\mathrm{eigsrc}$ – string (length ≥ 1)
Indicates whether the eigenvalues of $H$ (stored in wr and wi) were found using nag_lapack_dhseqr (f08pe).
${\mathbf{eigsrc}}=\text{'Q'}$
The eigenvalues of $H$ were found using nag_lapack_dhseqr (f08pe); 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{eigsrc}}=\text{'N'}$
No such assumption is made and the function performs inverse iteration using the whole matrix.
Constraint: ${\mathbf{eigsrc}}=\text{'Q'}$ or $\text{'N'}$.
3:     $\mathrm{initv}$ – string (length ≥ 1)
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:     $\mathrm{select}\left(:\right)$ – logical array
The dimension of the array select must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
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.
5:     $\mathrm{h}\left(\mathit{ldh},:\right)$ – double array
The first dimension of the array h must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The second dimension of the array h must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The $n$ by $n$ upper Hessenberg matrix $H$.
6:     $\mathrm{wr}\left(:\right)$ – double array
7:     $\mathrm{wi}\left(:\right)$ – double array
The dimension of the arrays wr and wi must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
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 nag_lapack_dhseqr (f08pe).
8:     $\mathrm{vl}\left(\mathit{ldvl},:\right)$ – double array
The first dimension, $\mathit{ldvl}$, of the array vl must satisfy
• if ${\mathbf{job}}=\text{'L'}$ or $\text{'B'}$, $\mathit{ldvl}\ge {\mathbf{n}}$;
• if ${\mathbf{job}}=\text{'R'}$, $\mathit{ldvl}\ge 1$.
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'}$.
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.
9:     $\mathrm{vr}\left(\mathit{ldvr},:\right)$ – double array
The first dimension, $\mathit{ldvr}$, of the array vr must satisfy
• if ${\mathbf{job}}=\text{'R'}$ or $\text{'B'}$, $\mathit{ldvr}\ge {\mathbf{n}}$;
• if ${\mathbf{job}}=\text{'L'}$, $\mathit{ldvr}\ge 1$.
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'}$.
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.
10:   $\mathrm{mm}$int64int32nag_int scalar
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}$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the array h and the second dimension of the array h. (An error is raised if these dimensions are not equal.)
$n$, the order of the matrix $H$.
Constraint: ${\mathbf{n}}\ge 0$.

### Output Parameters

1:     $\mathrm{select}\left(:\right)$ – logical array
The dimension of the array select will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
If a complex eigenvector was selected as specified above, then ${\mathbf{select}}\left(j\right)$ is set to true and ${\mathbf{select}}\left(j+1\right)$ to false.
2:     $\mathrm{wr}\left(:\right)$ – double array
The dimension of the arrays wr and wi will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
Some elements of wr may be modified, as close eigenvalues are perturbed slightly in searching for independent eigenvectors.
3:     $\mathrm{vl}\left(\mathit{ldvl},:\right)$ – double array
The first dimension, $\mathit{ldvl}$, of the array vl will be
• if ${\mathbf{job}}=\text{'L'}$ or $\text{'B'}$, $\mathit{ldvl}={\mathbf{n}}$;
• if ${\mathbf{job}}=\text{'R'}$, $\mathit{ldvl}=1$.
The second dimension of the array vl will be $\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'}$.
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.
4:     $\mathrm{vr}\left(\mathit{ldvr},:\right)$ – double array
The first dimension, $\mathit{ldvr}$, of the array vr will be
• if ${\mathbf{job}}=\text{'R'}$ or $\text{'B'}$, $\mathit{ldvr}={\mathbf{n}}$;
• if ${\mathbf{job}}=\text{'L'}$, $\mathit{ldvr}=1$.
The second dimension of the array vr will be $\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'}$.
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.
5:     $\mathrm{m}$int64int32nag_int scalar
$\mathit{m}$, the number of columns of vl and/or vr required to store the selected eigenvectors.
6:     $\mathrm{ifaill}\left(:\right)$int64int32nag_int array
The dimension of the array ifaill will be $\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'}$
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.
7:     $\mathrm{ifailr}\left(:\right)$int64int32nag_int array
The dimension of the array ifailr will be $\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'}$
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.
8:     $\mathrm{info}$int64int32nag_int scalar
${\mathbf{info}}=0$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

${\mathbf{info}}=-i$
If ${\mathbf{info}}=-i$, parameter $i$ had an illegal value on entry. The parameters are numbered as follows:
1: job, 2: eigsrc, 3: initv, 4: select, 5: n, 6: h, 7: ldh, 8: wr, 9: wi, 10: vl, 11: ldvl, 12: vr, 13: ldvr, 14: mm, 15: m, 16: work, 17: ifaill, 18: ifailr, 19: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.
W  ${\mathbf{info}}>0$
If ${\mathbf{info}}=i$, then $i$ eigenvectors (as indicated by the arguments ifaill and/or ifailr above) failed to converge. The corresponding columns of vl and/or vr contain no useful information.

## Accuracy

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.

The complex analogue of this function is nag_lapack_zhsein (f08px).

## Example

See Example in nag_lapack_dormhr (f08ng).
```function f08pk_example

fprintf('f08pk example results\n\n');

% Matrix A
n   = int64(4);
a = [ 0.35,  0.45, -0.14, -0.17;
0.09,  0.07, -0.54,  0.35;
-0.44, -0.33, -0.03,  0.17;
0.25, -0.32, -0.13,  0.11];

% Reduce A to upper Hessenberg Form A = QHQ^T
ilo = int64(1);
ihi = n;
[H, tau, info] = f08ne(ilo, ihi, a);

% Form Q
[Q, info] = f08nf(ilo, ihi, H, tau);

% Schur factorize H = Y*T*Y^T
job   = 'Schur form';
compz = 'No Vectors';
[~, wr, wi, ~, info] = f08pe( ...
job, compz, ilo, ihi, H, Q);

w = wr + i*wi;
disp('Eigenvalues of A');
disp(w);

% Calculate eigenvetors of H corresponding to negative real part eigenvalues
select = (wr < 0);

job = 'Right';
eigsrc = 'QR';
initv = 'No initial vectors';
vl = [];
vr = zeros(n,n);
[~, ~, ~, VR, m, ifaill, ifailr, info] = ...
f08pk( ...
job, eigsrc, initv, select, H, wr, wi, vl, vr, n);

% Eigenvectors of A = Q*VR
side = 'Left';
trans = 'No transpose';
[V, info] = f08ng( ...
side, trans, ilo, ihi, H, tau, VR);

% Combine columns of V into complex eigenvectors Z
j = 0;
for k = 1:n
if select(k)
j = j+1;
if (wi(k)==0)
% Normalize real eigenvector: largest element positive
[~,l] = max(abs(V(:,j)));
if V(l,j) < 0;
V(:,j) = -V(:,j);
end
Z(:,j) = complex(V(:,j));
else
% Normalize complex eigenvectors: largest elements are real
[~,l] = max(abs(V(:,j))+abs(V(:,j+1)));
Z(:,j)   = V(:,j) + i*V(:,j+1);
Z(:,j+1) = V(:,j) - i*V(:,j+1);
Z(:,j)   = Z(:,j)  *conj(Z(l,j))  /abs(Z(l,j));
Z(:,j+1) = Z(:,j+1)*conj(Z(l,j+1))/abs(Z(l,j+1));
j = j+1;
select(k+1) = false;
end
end
end
disp('Eigenvectors corresponding to eigenvalues with negative real part');
disp(Z);

```
```f08pk example results

Eigenvalues of A
0.7995 + 0.0000i
-0.0994 + 0.4008i
-0.0994 - 0.4008i
-0.1007 + 0.0000i

Eigenvectors corresponding to eigenvalues with negative real part
-0.2379 + 0.3134i  -0.2379 - 0.3134i   0.1493 + 0.0000i
0.3100 - 0.6430i   0.3100 + 0.6430i   0.3956 + 0.0000i
0.1196 - 0.3795i   0.1196 + 0.3795i   0.7075 + 0.0000i
0.8319 + 0.0000i   0.8319 + 0.0000i   0.8603 + 0.0000i

```