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_dtrevc (f08qk)

## Purpose

nag_lapack_dtrevc (f08qk) computes selected left and/or right eigenvectors of a real upper quasi-triangular matrix.

## Syntax

[select, vl, vr, m, info] = f08qk(job, howmny, select, t, vl, vr, mm, 'n', n)
[select, vl, vr, m, info] = nag_lapack_dtrevc(job, howmny, select, t, vl, vr, mm, 'n', n)

## Description

nag_lapack_dtrevc (f08qk) computes left and/or right eigenvectors of a real upper quasi-triangular matrix $T$ in canonical Schur form. Such a matrix arises from the Schur factorization of a real general matrix, as computed by nag_lapack_dhseqr (f08pe), for example.
The right eigenvector $x$, and the left eigenvector $y$, corresponding to an eigenvalue $\lambda$, are defined by:
 $Tx = λx and yHT = λyH or ​ TTy = λ-y .$
Note that even though $T$ 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 function can compute the eigenvectors corresponding to selected eigenvalues, or it can compute all the eigenvectors. In the latter case the eigenvectors may optionally be pre-multiplied by an input matrix $Q$. Normally $Q$ is an orthogonal matrix from the Schur factorization of a matrix $A$ as $A=QT{Q}^{\mathrm{T}}$; if $x$ is a (left or right) eigenvector of $T$, then $Qx$ is an eigenvector of $A$.
The eigenvectors are computed by forward or backward substitution. They are scaled so that, for a real eigenvector $x$, $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\left|{x}_{i}\right|\right)=1$, and for a complex eigenvector, $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\left|\mathrm{Re}\left({x}_{i}\right)\right|+\left|\mathrm{Im}\left({x}_{i}\right)\right|\right)=1$.

## 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{howmny}$ – string (length ≥ 1)
Indicates how many eigenvectors are to be computed.
${\mathbf{howmny}}=\text{'A'}$
All eigenvectors (as specified by job) are computed.
${\mathbf{howmny}}=\text{'B'}$
All eigenvectors (as specified by job) are computed and then pre-multiplied by the matrix $Q$ (which is overwritten).
${\mathbf{howmny}}=\text{'S'}$
Selected eigenvectors (as specified by job and select) are computed.
Constraint: ${\mathbf{howmny}}=\text{'A'}$, $\text{'B'}$ or $\text{'S'}$.
3:     $\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)$ if ${\mathbf{howmny}}=\text{'S'}$, and at least $1$ otherwise
Specifies which eigenvectors are to be computed if ${\mathbf{howmny}}=\text{'S'}$. To obtain the real eigenvector corresponding to the real eigenvalue ${\lambda }_{j}$, ${\mathbf{select}}\left(j\right)$ must be set true. To select the complex eigenvector corresponding to a complex conjugate pair of eigenvalues ${\lambda }_{j}$ and ${\lambda }_{j+1}$, ${\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.
4:     $\mathrm{t}\left(\mathit{ldt},:\right)$ – double array
The first dimension of the array t must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The second dimension of the array t must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The $n$ by $n$ upper quasi-triangular matrix $T$ in canonical Schur form, as returned by nag_lapack_dhseqr (f08pe).
5:     $\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{howmny}}=\text{'B'}$ and ${\mathbf{job}}=\text{'L'}$ or $\text{'B'}$, vl must contain an $n$ by $n$ matrix $Q$ (usually the matrix of Schur vectors returned by nag_lapack_dhseqr (f08pe)).
If ${\mathbf{howmny}}=\text{'A'}$ or $\text{'S'}$, vl need not be set.
6:     $\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{howmny}}=\text{'B'}$ and ${\mathbf{job}}=\text{'R'}$ or $\text{'B'}$, vr must contain an $n$ by $n$ matrix $Q$ (usually the matrix of Schur vectors returned by nag_lapack_dhseqr (f08pe)).
If ${\mathbf{howmny}}=\text{'A'}$ or $\text{'S'}$, vr need not be set.
7:     $\mathrm{mm}$int64int32nag_int scalar
The number of columns in the arrays vl and/or vr. The precise number of columns required, $\mathit{m}$, is $n$ if ${\mathbf{howmny}}=\text{'A'}$ or $\text{'B'}$; if ${\mathbf{howmny}}=\text{'S'}$, $\mathit{m}$ is obtained by counting $1$ for each selected real eigenvector and $2$ for each selected complex eigenvector (see select), in which case $0\le \mathit{m}\le n$.
Constraints:
• if ${\mathbf{howmny}}=\text{'A'}$ or $\text{'B'}$, ${\mathbf{mm}}\ge {\mathbf{n}}$;
• otherwise ${\mathbf{mm}}\ge \mathit{m}$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the array t and the second dimension of the array t. (An error is raised if these dimensions are not equal.)
$n$, the order of the matrix $T$.
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 ${\mathbf{howmny}}=\text{'S'}$ and $1$ otherwise
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.
If ${\mathbf{howmny}}=\text{'A'}$ or $\text{'B'}$, select is not referenced.
2:     $\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 howmny and select). The eigenvectors are stored consecutively in the columns of the array, in the same order as their eigenvalues. Corresponding to each real eigenvalue is a real eigenvector, occupying one column. Corresponding to each complex conjugate pair of eigenvalues, 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.
3:     $\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 howmny and select). The eigenvectors are stored consecutively in the columns of the array, in the same order as their eigenvalues. Corresponding to each real eigenvalue is a real eigenvector, occupying one column. Corresponding to each complex conjugate pair of eigenvalues, 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.
4:     $\mathrm{m}$int64int32nag_int scalar
$\mathit{m}$, the number of columns of vl and/or vr actually used to store the computed eigenvectors. If ${\mathbf{howmny}}=\text{'A'}$ or $\text{'B'}$, m is set to $n$.
5:     $\mathrm{info}$int64int32nag_int scalar
${\mathbf{info}}=0$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and 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: howmny, 3: select, 4: n, 5: t, 6: ldt, 7: vl, 8: ldvl, 9: vr, 10: ldvr, 11: mm, 12: m, 13: work, 14: 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.
${\mathbf{info}}=-11$
On entry, ${\mathbf{mm}}=_$ and ${\mathbf{n}}=_$.
Constraint: if ${\mathbf{howmny}}\ne \text{'S'}$, ${\mathbf{mm}}\ge {\mathbf{n}}$
else ${\mathbf{mm}}\ge \mathit{m}$, where $\mathit{m}$ is obtained by counting $1$ for each selected real eigenvector and $2$ for each selected complex eigenvector.

## Accuracy

If ${x}_{i}$ is an exact right eigenvector, and ${\stackrel{~}{x}}_{i}$ is the corresponding computed eigenvector, then the angle $\theta \left({\stackrel{~}{x}}_{i},{x}_{i}\right)$ between them is bounded as follows:
 $θ x~i,xi ≤ c n ε T2 sepi$
where ${\mathit{sep}}_{i}$ is the reciprocal condition number of ${x}_{i}$.
The condition number ${\mathit{sep}}_{i}$ may be computed by calling nag_lapack_dtrsna (f08ql).

For a description of canonical Schur form, see the document for nag_lapack_dhseqr (f08pe).
The complex analogue of this function is nag_lapack_ztrevc (f08qx).

## Example

See Example in nag_lapack_dgebal (f08nh).
```function f08qk_example

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

n = int64(4);
a = [ 5.14, 0.91,  0.00, -32.80;
0.91, 0.20,  0.00,  34.50;
1.90, 0.80, -0.40,  -3.00;
-0.33, 0.35,  0.00,   0.66];

% Balance a
[a, ilo, ihi, scale, info] = f08nh( ...
'Both', a);

% Reduce a to upper Hessenberg form
[H, tau, info] = f08ne( ...
ilo, ihi, a);

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

% Calculate the eigenvalues and Schur factorisation of A
[H, wr, wi, Z, info] = f08pe( ...
'Schur Form', 'Vectors', ilo, ihi, H, Q);

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

% Calculate the eigenvectors of A
[select, ~, VR, m, info] = ...
f08qk( ...
'Right', 'Backtransform', false, H, zeros(1), Z, n);

% Back scale to get eigenvectors of A
[VR, info] = f08nj( ...
'Both', 'Right', ilo, ihi, scale, VR);

% Normalize eigenvectors: largest element positive
for j = 1:n
[~,k] = max(abs(VR(:,j)));
VR(:,j) =VR(:,j)/norm(VR(:,j));
if VR(k,j) < 0;
VR(:,j) = -VR(:,j);
end
end

disp('Eigenvectors:');
disp(VR);

```
```f08qk example results

Eigenvalues:
-0.4000
-4.0208
3.0136
7.0072

Eigenvectors:
0   -0.4381    0.4654    0.9513
0    0.8923    0.7888   -0.1714
1.0000   -0.0481    0.3981    0.2494
0   -0.0976    0.0521   -0.0589

```