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_zhsein (f08px)

## Purpose

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

## Syntax

[w, vl, vr, m, ifaill, ifailr, info] = f08px(job, eigsrc, initv, select, h, w, vl, vr, mm, 'n', n)
[w, vl, vr, m, ifaill, ifailr, info] = nag_lapack_zhsein(job, eigsrc, initv, select, h, w, vl, vr, mm, 'n', n)

## Description

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

## References

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

## Parameters

### Compulsory Input Parameters

1:     job – string (length ≥ 1)
Indicates whether left and/or right eigenvectors are to be computed.
job = 'R'${\mathbf{job}}=\text{'R'}$
Only right eigenvectors are computed.
job = 'L'${\mathbf{job}}=\text{'L'}$
Only left eigenvectors are computed.
job = 'B'${\mathbf{job}}=\text{'B'}$
Both left and right eigenvectors are computed.
Constraint: job = 'R'${\mathbf{job}}=\text{'R'}$, 'L'$\text{'L'}$ or 'B'$\text{'B'}$.
2:     eigsrc – string (length ≥ 1)
Indicates whether the eigenvalues of H$H$ (stored in w) were found using nag_lapack_zhseqr (f08ps).
eigsrc = 'Q'${\mathbf{eigsrc}}=\text{'Q'}$
The eigenvalues of H$H$ were found using nag_lapack_zhseqr (f08ps); thus if H$H$ has any zero subdiagonal elements (and so is block triangular), then the j$j$th eigenvalue can be assumed to be an eigenvalue of the block containing the j$j$th row/column. This property allows the function to perform inverse iteration on just one diagonal block.
eigsrc = 'N'${\mathbf{eigsrc}}=\text{'N'}$
No such assumption is made and the function performs inverse iteration using the whole matrix.
Constraint: eigsrc = 'Q'${\mathbf{eigsrc}}=\text{'Q'}$ or 'N'$\text{'N'}$.
3:     initv – string (length ≥ 1)
Indicates whether you are supplying initial estimates for the selected eigenvectors.
initv = 'N'${\mathbf{initv}}=\text{'N'}$
No initial estimates are supplied.
initv = 'U'${\mathbf{initv}}=\text{'U'}$
Initial estimates are supplied in vl and/or vr.
Constraint: initv = 'N'${\mathbf{initv}}=\text{'N'}$ or 'U'$\text{'U'}$.
4:     select( : $:$) – logical array
Note: the dimension of the array select must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
Specifies which eigenvectors are to be computed. To select the eigenvector corresponding to the eigenvalue w(j)${\mathbf{w}}\left(j\right)$, select(j)${\mathbf{select}}\left(j\right)$ must be set to true.
5:     h(ldh, : $:$) – complex array
The first dimension of the array h must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The n$n$ by n$n$ upper Hessenberg matrix H$H$.
6:     w( : $:$) – complex array
Note: the dimension of the array w must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The eigenvalues of the matrix H$H$. If eigsrc = 'Q'${\mathbf{eigsrc}}=\text{'Q'}$, the array must be exactly as returned by nag_lapack_zhseqr (f08ps).
7:     vl(ldvl, : $:$) – complex array
The first dimension, ldvl, of the array vl must satisfy
• if job = 'L'${\mathbf{job}}=\text{'L'}$ or 'B'$\text{'B'}$, ldvl max (1,n) $\mathit{ldvl}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if job = 'R'${\mathbf{job}}=\text{'R'}$, ldvl1$\mathit{ldvl}\ge 1$.
The second dimension of the array must be at least max (1,mm)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if job = 'L'${\mathbf{job}}=\text{'L'}$ or 'B'$\text{'B'}$ and at least 1$1$ if job = 'R'${\mathbf{job}}=\text{'R'}$
If initv = 'U'${\mathbf{initv}}=\text{'U'}$ and job = 'L'${\mathbf{job}}=\text{'L'}$ or 'B'$\text{'B'}$, vl must contain starting vectors for inverse iteration for the left eigenvectors. Each starting vector must be stored in the same column as will be used to store the corresponding eigenvector (see below).
If initv = 'N'${\mathbf{initv}}=\text{'N'}$, vl need not be set.
8:     vr(ldvr, : $:$) – complex array
The first dimension, ldvr, of the array vr must satisfy
• if job = 'R'${\mathbf{job}}=\text{'R'}$ or 'B'$\text{'B'}$, ldvr max (1,n) $\mathit{ldvr}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if job = 'L'${\mathbf{job}}=\text{'L'}$, ldvr1$\mathit{ldvr}\ge 1$.
The second dimension of the array must be at least max (1,mm)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if job = 'R'${\mathbf{job}}=\text{'R'}$ or 'B'$\text{'B'}$ and at least 1$1$ if job = 'L'${\mathbf{job}}=\text{'L'}$
If initv = 'U'${\mathbf{initv}}=\text{'U'}$ and job = 'R'${\mathbf{job}}=\text{'R'}$ or 'B'$\text{'B'}$, vr must contain starting vectors for inverse iteration for the right eigenvectors. Each starting vector must be stored in the same column as will be used to store the corresponding eigenvector (see below).
If initv = 'N'${\mathbf{initv}}=\text{'N'}$, vr need not be set.
9:     mm – int64int32nag_int scalar
The number of columns in the arrays vl and/or vr . The actual number of columns required, m$\mathit{m}$, is obtained by counting 1$1$ for each selected real eigenvector and 2$2$ for each selected complex eigenvector (see select); 0mn$0\le \mathit{m}\le n$.
Constraint: mmm${\mathbf{mm}}\ge \mathit{m}$.

### Optional Input Parameters

1:     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$n$, the order of the matrix H$H$.
Constraint: n0${\mathbf{n}}\ge 0$.

### Input Parameters Omitted from the MATLAB Interface

ldh ldvl ldvr work rwork

### Output Parameters

1:     w( : $:$) – complex array
Note: the dimension of the array w must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The real parts of some elements of w may be modified, as close eigenvalues are perturbed slightly in searching for independent eigenvectors.
2:     vl(ldvl, : $:$) – complex array
The first dimension, ldvl, of the array vl will be
• if job = 'L'${\mathbf{job}}=\text{'L'}$ or 'B'$\text{'B'}$, ldvl max (1,n) $\mathit{ldvl}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if job = 'R'${\mathbf{job}}=\text{'R'}$, ldvl1$\mathit{ldvl}\ge 1$.
The second dimension of the array will be max (1,mm)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if job = 'L'${\mathbf{job}}=\text{'L'}$ or 'B'$\text{'B'}$ and at least 1$1$ if job = 'R'${\mathbf{job}}=\text{'R'}$
If job = 'L'${\mathbf{job}}=\text{'L'}$ or 'B'$\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.
If job = 'R'${\mathbf{job}}=\text{'R'}$, vl is not referenced.
3:     vr(ldvr, : $:$) – complex array
The first dimension, ldvr, of the array vr will be
• if job = 'R'${\mathbf{job}}=\text{'R'}$ or 'B'$\text{'B'}$, ldvr max (1,n) $\mathit{ldvr}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if job = 'L'${\mathbf{job}}=\text{'L'}$, ldvr1$\mathit{ldvr}\ge 1$.
The second dimension of the array will be max (1,mm)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if job = 'R'${\mathbf{job}}=\text{'R'}$ or 'B'$\text{'B'}$ and at least 1$1$ if job = 'L'${\mathbf{job}}=\text{'L'}$
If job = 'R'${\mathbf{job}}=\text{'R'}$ or 'B'$\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.
If job = 'L'${\mathbf{job}}=\text{'L'}$, vr is not referenced.
4:     m – int64int32nag_int scalar
m$\mathit{m}$, the number of selected eigenvectors.
5:     ifaill( : $:$) – int64int32nag_int array
Note: the dimension of the array ifaill must be at least max (1,mm)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if job = 'L'${\mathbf{job}}=\text{'L'}$ or 'B'$\text{'B'}$ and at least 1$1$ if job = 'R'${\mathbf{job}}=\text{'R'}$.
If job = 'L'${\mathbf{job}}=\text{'L'}$ or 'B'$\text{'B'}$, then ifaill(i) = 0${\mathbf{ifaill}}\left(i\right)=0$ if the selected left eigenvector converged and ifaill(i) = j > 0${\mathbf{ifaill}}\left(i\right)=j>0$ if the eigenvector stored in the i$i$th row or column of vl (corresponding to the j$j$th eigenvalue) failed to converge.
If job = 'R'${\mathbf{job}}=\text{'R'}$, ifaill is not referenced.
6:     ifailr( : $:$) – int64int32nag_int array
Note: the dimension of the array ifailr must be at least max (1,mm)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if job = 'R'${\mathbf{job}}=\text{'R'}$ or 'B'$\text{'B'}$ and at least 1$1$ if job = 'L'${\mathbf{job}}=\text{'L'}$.
If job = 'R'${\mathbf{job}}=\text{'R'}$ or 'B'$\text{'B'}$, then ifailr(i) = 0${\mathbf{ifailr}}\left(i\right)=0$ if the selected right eigenvector converged and ifailr(i) = j > 0${\mathbf{ifailr}}\left(i\right)=j>0$ if the eigenvector stored in the i$i$th column of vr (corresponding to the j$j$th eigenvalue) failed to converge.
If job = 'L'${\mathbf{job}}=\text{'L'}$, ifailr is not referenced.
7:     info – int64int32nag_int scalar
info = 0${\mathbf{info}}=0$ unless the function detects an error (see Section [Error Indicators and Warnings]).

## Error Indicators and Warnings

info = i${\mathbf{info}}=-i$
If info = i${\mathbf{info}}=-i$, parameter i$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: w, 9: vl, 10: ldvl, 11: vr, 12: ldvr, 13: mm, 14: m, 15: work, 16: rwork, 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.
INFO > 0${\mathbf{INFO}}>0$
If info = i${\mathbf{info}}=i$, then i$i$ eigenvectors (as indicated by the parameters 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 xi${x}_{i}$ is the exact eigenvector of a nearby matrix A + Ei$A+{E}_{i}$, such that Ei = O(ε)A$‖{E}_{i}‖=\mathit{O}\left(\epsilon \right)‖A‖$. Hence the residual is small:
 ‖Axi − λixi‖ = O(ε) ‖A‖ . $‖ 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 real analogue of this function is nag_lapack_dhsein (f08pk).

## Example

```function nag_lapack_zhsein_example
job = 'Right';
eigsrc = 'QR';
initv = 'No initial vectors';
select = [true;
true;
false;
false];
h = [ -3.97 - 5.04i,  -1.131805187339771 - 2.56930489882744i, ...
-4.602742437533554 - 0.142631904083292i,  -1.424912289366528 + 1.732983703342187i;
-5.479653273702635 + 0i,  1.858472820765587 - 1.55018070644029i, ...
4.414465526917012 - 0.7638237115550983i,  -0.4805261336990153 - 1.197599997332747i;
0.6932222118146283 - 0.4828752762602551i, ...
6.267276818064224 + 0i,  -0.4503809403345012 - 0.02898183259817966i,  ...
-1.346684450078734 + 1.65792489538873i;
-0.2112946907920694 + 0.0864412259893682i, ...
0.1242146188766495 - 0.2289276049796828i,  -3.499985837393258 + 0i,  ...
2.561908119568915 - 3.370837460961531i];
w = [ -6.000425342949246 - 6.999843371570391i;
-5.000033457596968 + 2.006027162316515i;
7.998194516208248 - 0.9963650913929011i;
3.002264284337973 - 3.999818699353226i];
vl = complex([ 0]);
vr = complex([ 0,  0,  0,  0;
0,  0,  0,  0;
0,  0,  0,  0;
0,  0,  0,  0]);
mm = int64(4);
[wOut, vlOut, vrOut, m, ifaill, ifailr, info] = ...
nag_lapack_zhsein(job, eigsrc, initv, select, h, w, vl, vr, mm)
```
```

wOut =

-6.0004 - 6.9998i
-5.0000 + 2.0060i
7.9982 - 0.9964i
3.0023 - 3.9998i

vlOut =

0.0000 + 0.0000i

vrOut =

0.3815 - 0.6185i  -0.2691 - 0.5053i   0.0000 + 0.0000i   0.0000 + 0.0000i
-0.1142 - 0.3555i   0.5760 - 0.2995i   0.0000 + 0.0000i   0.0000 + 0.0000i
0.2385 + 0.0716i  -0.9708 + 0.0292i   0.0000 + 0.0000i   0.0000 + 0.0000i
0.0932 - 0.0102i  -0.3048 - 0.2032i   0.0000 + 0.0000i   0.0000 + 0.0000i

m =

2

ifaill =

0

ifailr =

0
0
0
0

info =

0

```
```function f08px_example
job = 'Right';
eigsrc = 'QR';
initv = 'No initial vectors';
select = [true;
true;
false;
false];
h = [ -3.97 - 5.04i,  -1.131805187339771 - 2.56930489882744i, ...
-4.602742437533554 - 0.142631904083292i,  -1.424912289366528 + 1.732983703342187i;
-5.479653273702635 + 0i,  1.858472820765587 - 1.55018070644029i, ...
4.414465526917012 - 0.7638237115550983i,  -0.4805261336990153 - 1.197599997332747i;
0.6932222118146283 - 0.4828752762602551i, ...
6.267276818064224 + 0i,  -0.4503809403345012 - 0.02898183259817966i,  ...
-1.346684450078734 + 1.65792489538873i;
-0.2112946907920694 + 0.0864412259893682i, ...
0.1242146188766495 - 0.2289276049796828i,  -3.499985837393258 + 0i,  ...
2.561908119568915 - 3.370837460961531i];
w = [ -6.000425342949246 - 6.999843371570391i;
-5.000033457596968 + 2.006027162316515i;
7.998194516208248 - 0.9963650913929011i;
3.002264284337973 - 3.999818699353226i];
vl = complex([ 0]);
vr = complex([ 0,  0,  0,  0;
0,  0,  0,  0;
0,  0,  0,  0;
0,  0,  0,  0]);
mm = int64(4);
[wOut, vlOut, vrOut, m, ifaill, ifailr, info] = ...
f08px(job, eigsrc, initv, select, h, w, vl, vr, mm)
```
```

wOut =

-6.0004 - 6.9998i
-5.0000 + 2.0060i
7.9982 - 0.9964i
3.0023 - 3.9998i

vlOut =

0.0000 + 0.0000i

vrOut =

0.3815 - 0.6185i  -0.2691 - 0.5053i   0.0000 + 0.0000i   0.0000 + 0.0000i
-0.1142 - 0.3555i   0.5760 - 0.2995i   0.0000 + 0.0000i   0.0000 + 0.0000i
0.2385 + 0.0716i  -0.9708 + 0.0292i   0.0000 + 0.0000i   0.0000 + 0.0000i
0.0932 - 0.0102i  -0.3048 - 0.2032i   0.0000 + 0.0000i   0.0000 + 0.0000i

m =

2

ifaill =

0

ifailr =

0
0
0
0

info =

0

```