F02 Chapter Contents
F02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF02GCF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

F02GCF computes selected eigenvalues and eigenvectors of a complex general matrix.

## 2  Specification

 SUBROUTINE F02GCF ( CRIT, N, A, LDA, WL, WU, MEST, M, W, V, LDV, WORK, LWORK, RWORK, IWORK, BWORK, IFAIL)
 INTEGER N, LDA, MEST, M, LDV, LWORK, IWORK(N), IFAIL REAL (KIND=nag_wp) WL, WU, RWORK(2*N) COMPLEX (KIND=nag_wp) A(LDA,*), W(N), V(LDV,MEST), WORK(LWORK) LOGICAL BWORK(N) CHARACTER(1) CRIT

## 3  Description

F02GCF computes selected eigenvalues and the corresponding right eigenvectors of a complex general matrix $A$:
 $Axi=λixi.$
Eigenvalues ${\lambda }_{i}$ may be selected either by modulus, satisfying
 $wl≤λi≤wu,$
or by real part, satisfying
 $wl≤Reλi≤wu.$

## 4  References

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

## 5  Parameters

1:     CRIT – CHARACTER(1)Input
On entry: 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:     N – INTEGERInput
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{N}}\ge 0$.
3:     A(LDA,$*$) – COMPLEX (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array A must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
On entry: the $n$ by $n$ general matrix $A$.
On exit: contains the Hessenberg form of the balanced input matrix ${A}^{\prime }$ (see Section 8).
4:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F02GCF is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
5:     WL – REAL (KIND=nag_wp)Input
6:     WU – REAL (KIND=nag_wp)Input
On entry: ${w}_{l}$ and ${w}_{u}$, the lower and upper bounds on the criterion for the selected eigenvalues (see CRIT).
Constraint: ${\mathbf{WU}}>{\mathbf{WL}}$.
7:     MEST – INTEGERInput
On entry: the second dimension of the array V as declared in the (sub)program from which F02GCF is called. 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)$.
8:     M – INTEGEROutput
On exit: $m$, the number of eigenvalues actually selected.
9:     W(N) – COMPLEX (KIND=nag_wp) arrayOutput
On exit: the first M elements of W hold the selected eigenvalues; elements ${\mathbf{M}}+1$ to N contain the other eigenvalues.
10:   V(LDV,MEST) – COMPLEX (KIND=nag_wp) arrayOutput
On exit: contains the selected eigenvectors, with the $i$th column holding the eigenvector associated with the eigenvalue ${\lambda }_{i}$ (stored in ${\mathbf{W}}\left(i\right)$).
11:   LDV – INTEGERInput
On entry: the first dimension of the array V as declared in the (sub)program from which F02GCF is called.
Constraint: ${\mathbf{LDV}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
12:   WORK(LWORK) – COMPLEX (KIND=nag_wp) arrayWorkspace
13:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F02GCF is called.
Constraint: ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}×\left({\mathbf{N}}+2\right)\right)$.
14:   RWORK($2×{\mathbf{N}}$) – REAL (KIND=nag_wp) arrayWorkspace
15:   IWORK(N) – INTEGER arrayWorkspace
16:   BWORK(N) – LOGICAL arrayWorkspace
17:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{CRIT}}\ne \text{'M'}$ or $\text{'R'}$, or ${\mathbf{N}}<0$, or ${\mathbf{LDA}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$, or ${\mathbf{WU}}\le {\mathbf{WL}}$, or ${\mathbf{MEST}}<1$, or ${\mathbf{LDV}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$, or ${\mathbf{LWORK}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}×\left({\mathbf{N}}+2\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 ${\mathbf{V}}={\mathbf{MEST}}\ge {\mathbf{M}}$.
${\mathbf{IFAIL}}=4$
Inverse iteration failed to compute all the specified eigenvectors. If an eigenvector failed to converge, the corresponding column of V is set to zero.

## 7  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 Section 8), 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 F08PSF (ZHSEQR) with ${\mathbf{JOB}}=\text{'S'}$ to compute the Schur form of ${A}^{\prime }$, followed by F08QYF (ZTRSNA).

## 8  Further Comments

F02GCF calls routines 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 a unitary similarity transformation: ${A}^{\prime }=QH{Q}^{\mathrm{H}}$. The routine 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$ is normalized so that ${‖x‖}_{2}=1$, and the element of largest absolute value is real and positive.
The inverse iteration routine 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 F02GCF.
The time taken by the routine is approximately proportional to ${n}^{3}$.
The routine can be used to compute all eigenvalues and eigenvectors, by setting WL large and negative, and WU large and positive.

## 9  Example

This example computes those eigenvalues of the matrix $A$ which lie in the range $\left[-5.5,+5.5\right]$, and their corresponding eigenvectors, where
 $A = -3.97-5.04i -4.11+3.70i -0.34+1.01i 1.29-0.86i 0.34-1.50i 1.52-0.43i 1.88-5.38i 3.36+0.65i 3.31-3.85i 2.50+3.45i 0.88-1.08i 0.64-1.48i -1.10+0.82i 1.81-1.59i 3.25+1.33i 1.57-3.44i .$

### 9.1  Program Text

Program Text (f02gcfe.f90)

### 9.2  Program Data

Program Data (f02gcfe.d)

### 9.3  Program Results

Program Results (f02gcfe.r)