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_eigen_real_gen_eigsys (f02ec)

## Purpose

nag_eigen_real_gen_eigsys (f02ec) computes selected eigenvalues and eigenvectors of a real general matrix.

## Syntax

[a, m, wr, wi, vr, vi, ifail] = f02ec(crit, a, wl, wu, mest, 'n', n)
[a, m, wr, wi, vr, vi, ifail] = nag_eigen_real_gen_eigsys(crit, a, wl, wu, mest, 'n', n)

## Description

nag_eigen_real_gen_eigsys (f02ec) computes selected eigenvalues and the corresponding right eigenvectors of a real general matrix $A$:
 $Axi = λi xi .$
Eigenvalues ${\lambda }_{i}$ may be selected either by modulus, satisfying:
 $wl ≤ λi ≤ wu ,$
or by real part, satisfying:
 $wl ≤ Reλi ≤ wu .$
Note that even though $A$ is real, ${\lambda }_{i}$ and ${x}_{i}$ may be complex. If ${x}_{i}$ is an eigenvector corresponding to a complex eigenvalue ${\lambda }_{i}$, then the complex conjugate vector ${\stackrel{-}{x}}_{i}$ is the eigenvector corresponding to the complex conjugate eigenvalue ${\stackrel{-}{\lambda }}_{i}$. The eigenvalues in a complex conjugate pair ${\lambda }_{i}$ and ${\stackrel{-}{\lambda }}_{i}$ are either both selected or both not selected.

## 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{crit}$ – string (length ≥ 1)
Indicates the criterion for selecting eigenvalues.
${\mathbf{crit}}=\text{'M'}$
Eigenvalues are selected according to their moduli: ${w}_{l}\le \left|{\lambda }_{i}\right|\le {w}_{u}$.
${\mathbf{crit}}=\text{'R'}$
Eigenvalues are selected according to their real parts: ${w}_{l}\le \mathrm{Re}\left({\lambda }_{i}\right)\le {w}_{u}$.
Constraint: ${\mathbf{crit}}=\text{'M'}$ or $\text{'R'}$.
2:     $\mathrm{a}\left(\mathit{lda},{\mathbf{n}}\right)$ – double array
lda, the first dimension of the array, must satisfy the constraint $\mathit{lda}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The $n$ by $n$ general matrix $A$.
3:     $\mathrm{wl}$ – double scalar
4:     $\mathrm{wu}$ – double scalar
${w}_{l}$ and ${w}_{u}$, the lower and upper bounds on the criterion for the selected eigenvalues (see crit).
Constraint: ${\mathbf{wu}}>{\mathbf{wl}}$.
5:     $\mathrm{mest}$int64int32nag_int scalar
The second dimension of the arrays vr and vi. mest must be an upper bound on $m$, the number of eigenvalues and eigenvectors selected. No eigenvectors are computed if ${\mathbf{mest}}.
Constraint: ${\mathbf{mest}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,m\right)$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the second dimension of the array a.
$n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.

### Output Parameters

1:     $\mathrm{a}\left(\mathit{lda},{\mathbf{n}}\right)$ – double array
Contains the Hessenberg form of the balanced input matrix ${A}^{\prime }$ (see Further Comments).
2:     $\mathrm{m}$int64int32nag_int scalar
$m$, the number of eigenvalues actually selected.
3:     $\mathrm{wr}\left({\mathbf{n}}\right)$ – double array
4:     $\mathrm{wi}\left({\mathbf{n}}\right)$ – double array
The first m elements of wr and wi hold the real and imaginary parts, respectively, of the selected eigenvalues; elements ${\mathbf{m}}+1$ to n contain the other eigenvalues. Complex conjugate pairs of eigenvalues are stored in consecutive elements of the arrays, with the eigenvalue having positive imaginary part first. See also Further Comments.
5:     $\mathrm{vr}\left(\mathit{ldvr},{\mathbf{mest}}\right)$ – double array
Contains the real parts of the selected eigenvectors, with the $i$th column holding the real part of the eigenvector associated with the eigenvalue ${\lambda }_{i}$ (stored in ${\mathbf{wr}}\left(i\right)$ and ${\mathbf{wi}}\left(i\right)$).
6:     $\mathrm{vi}\left(\mathit{ldvi},{\mathbf{mest}}\right)$ – double array
Contains the imaginary parts of the selected eigenvectors, with the $i$th column holding the imaginary part of the eigenvector associated with the eigenvalue ${\lambda }_{i}$ (stored in ${\mathbf{wr}}\left(i\right)$ and ${\mathbf{wi}}\left(i\right)$).
7:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:

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

${\mathbf{ifail}}=1$
 On entry, ${\mathbf{crit}}\ne \text{'M'}$ or $\text{'R'}$, or ${\mathbf{n}}<0$, or $\mathit{lda}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$, or ${\mathbf{wu}}\le {\mathbf{wl}}$, or ${\mathbf{mest}}<1$, or $\mathit{ldvr}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$, or $\mathit{ldvi}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$, or $\mathit{lwork}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+4\right)\right)$.
${\mathbf{ifail}}=2$
The $QR$ algorithm failed to compute all the eigenvalues. No eigenvectors have been computed.
${\mathbf{ifail}}=3$
There are more than mest eigenvalues in the specified range. The actual number of eigenvalues in the range is returned in m. No eigenvectors have been computed. Rerun with the second dimension of vr and ${\mathbf{vi}}={\mathbf{mest}}\ge {\mathbf{m}}$.
W  ${\mathbf{ifail}}=4$
Inverse iteration failed to compute all the specified eigenvectors. If an eigenvector failed to converge, the corresponding column of vr and vi is set to zero.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

If ${\lambda }_{i}$ is an exact eigenvalue, and ${\stackrel{~}{\lambda }}_{i}$ is the corresponding computed value, then
 $λ~i-λi≤cnεA′2si,$
where $c\left(n\right)$ is a modestly increasing function of $n$, $\epsilon$ is the machine precision, and ${s}_{i}$ is the reciprocal condition number of ${\lambda }_{i}$; ${A}^{\prime }$ is the balanced form of the original matrix $A$ (see Further Comments), and $‖{A}^{\prime }‖\le ‖A‖$.
If ${x}_{i}$ is the corresponding exact 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≤cnεA′2sepi,$
where ${\mathit{sep}}_{i}$ is the reciprocal condition number of ${x}_{i}$.
The condition numbers ${s}_{i}$ and ${\mathit{sep}}_{i}$ may be computed from the Hessenberg form of the balanced matrix ${A}^{\prime }$ which is returned in the array a. This requires calling nag_lapack_dhseqr (f08pe) with ${\mathbf{job}}=\text{'S'}$ to compute the Schur form of ${A}^{\prime }$, followed by nag_lapack_dtrsna (f08ql).

nag_eigen_real_gen_eigsys (f02ec) calls functions from LAPACK in Chapter F08. It first balances the matrix, using a diagonal similarity transformation to reduce its norm; and then reduces the balanced matrix ${A}^{\prime }$ to upper Hessenberg form $H$, using an orthogonal similarity transformation: ${A}^{\prime }=QH{Q}^{\mathrm{T}}$. The function uses the Hessenberg $QR$ algorithm to compute all the eigenvalues of $H$, which are the same as the eigenvalues of $A$. It computes the eigenvectors of $H$ which correspond to the selected eigenvalues, using inverse iteration. It premultiplies the eigenvectors by $Q$ to form the eigenvectors of ${A}^{\prime }$; and finally transforms the eigenvectors to those of the original matrix $A$.
Each eigenvector $x$ (real or complex) is normalized so that ${‖x‖}_{2}=1$, and the element of largest absolute value is real.
The inverse iteration function may make a small perturbation to the real parts of close eigenvalues, and this may shift their moduli just outside the specified bounds. If you are relying on eigenvalues being within the bounds, you should test them on return from nag_eigen_real_gen_eigsys (f02ec).
The time taken by the function is approximately proportional to ${n}^{3}$.
The function can be used to compute all eigenvalues and eigenvectors, by setting wl large and negative, and wu large and positive.

## Example

This example computes those eigenvalues of the matrix $A$ whose moduli lie in the range $\left[0.2,0.5\right]$, and their corresponding eigenvectors, where
 $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 .$
```function f02ec_example

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

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];

% Find eigenvalues of A such that 0.2 <= |eig| <= 0.5
crit = 'Moduli';
wl   = 0.2;
wu   = 0.5;
mest = int64(3);

[a, m, wr, wi, vr, vi, ifail] = f02ec( ...
crit, a, wl, wu, mest);

evals = wr(1:m) + i*wi(1:m);
disp('Eigenvalues');
disp(evals);

evecs = vr(:,1:m) + i*vi(:,1:m);
disp('Eigenvectors');
disp(evecs);

```
```f02ec example results

Eigenvalues
-0.0994 + 0.4008i
-0.0994 - 0.4008i

Eigenvectors
-0.1933 + 0.2546i  -0.1933 - 0.2546i
0.2519 - 0.5224i   0.2519 + 0.5224i
0.0972 - 0.3084i   0.0972 + 0.3084i
0.6760 + 0.0000i   0.6760 + 0.0000i

```