# NAG FL Interfacef02ecf (real_​gen_​eigsys)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

f02ecf computes selected eigenvalues and eigenvectors of a real general matrix.

## 2Specification

Fortran Interface
 Subroutine f02ecf ( crit, n, a, lda, wl, wu, mest, m, wr, wi, vr, ldvr, vi, ldvi, work,
 Integer, Intent (In) :: n, lda, mest, ldvr, ldvi, lwork Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: m, iwork(n) Real (Kind=nag_wp), Intent (In) :: wl, wu Real (Kind=nag_wp), Intent (Inout) :: a(lda,n), vr(ldvr,mest), vi(ldvi,mest) Real (Kind=nag_wp), Intent (Out) :: wr(n), wi(n), work(lwork) Logical, Intent (Out) :: bwork(n) Character (1), Intent (In) :: crit
#include <nag.h>
 void f02ecf_ (const char *crit, const Integer *n, double a[], const Integer *lda, const double *wl, const double *wu, const Integer *mest, Integer *m, double wr[], double wi[], double vr[], const Integer *ldvr, double vi[], const Integer *ldvi, double work[], const Integer *lwork, Integer iwork[], logical bwork[], Integer *ifail, const Charlen length_crit)
The routine may be called by the names f02ecf or nagf_eigen_real_gen_eigsys.

## 3Description

f02ecf 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 ${\overline{x}}_{i}$ is the eigenvector corresponding to the complex conjugate eigenvalue ${\overline{\lambda }}_{i}$. The eigenvalues in a complex conjugate pair ${\lambda }_{i}$ and ${\overline{\lambda }}_{i}$ are either both selected or both not selected.

## 4References

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

## 5Arguments

1: $\mathbf{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 |{\lambda }_{i}|\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: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.
3: $\mathbf{a}\left({\mathbf{lda}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: the $n×n$ general matrix $A$.
On exit: contains the Hessenberg form of the balanced input matrix ${A}^{\prime }$ (see Section 9).
4: $\mathbf{lda}$Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which f02ecf is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
5: $\mathbf{wl}$Real (Kind=nag_wp) Input
6: $\mathbf{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: $\mathbf{mest}$Integer Input
On entry: the second dimension of the arrays vr and vi as declared in the (sub)program from which f02ecf 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: $\mathbf{m}$Integer Output
On exit: $m$, the number of eigenvalues actually selected.
9: $\mathbf{wr}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
10: $\mathbf{wi}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: 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 Section 9.
11: $\mathbf{vr}\left({\mathbf{ldvr}},{\mathbf{mest}}\right)$Real (Kind=nag_wp) array Output
On exit: 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)$).
12: $\mathbf{ldvr}$Integer Input
On entry: the first dimension of the array vr as declared in the (sub)program from which f02ecf is called.
Constraint: ${\mathbf{ldvr}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
13: $\mathbf{vi}\left({\mathbf{ldvi}},{\mathbf{mest}}\right)$Real (Kind=nag_wp) array Output
On exit: 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)$).
14: $\mathbf{ldvi}$Integer Input
On entry: the first dimension of the array vi as declared in the (sub)program from which f02ecf is called.
Constraint: ${\mathbf{ldvi}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
15: $\mathbf{work}\left({\mathbf{lwork}}\right)$Real (Kind=nag_wp) array Workspace
16: $\mathbf{lwork}$Integer Input
On entry: the dimension of the array work as declared in the (sub)program from which f02ecf is called.
Constraint: ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+4\right)\right)$.
17: $\mathbf{iwork}\left({\mathbf{n}}\right)$Integer array Workspace
18: $\mathbf{bwork}\left({\mathbf{n}}\right)$Logical array Workspace
19: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{crit}}=\text{'M'}$ or $\text{'R'}$.
On entry, ${\mathbf{lda}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{ldvi}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldvi}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{ldvr}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldvr}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{lwork}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+4\right)\right)$.
On entry, ${\mathbf{mest}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{mest}}\ge 1$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{wu}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{wl}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{wu}}>{\mathbf{wl}}$.
${\mathbf{ifail}}=2$
The $QR$ algorithm failed to converge: only $⟨\mathit{\text{value}}⟩$ eigenvalues have been computed; no eigenvectors have been computed.
${\mathbf{ifail}}=3$
There are more than mest eigenvalues in the specified range. m (number of eigenvalues in range) $\text{}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{mest}}=⟨\mathit{\text{value}}⟩$. No eigenvectors have been computed. Rerun with second dimension of vr and ${\mathbf{vi}}={\mathbf{mest}}\ge {\mathbf{m}}$.
${\mathbf{ifail}}=4$
Inverse iteration failed to compute all the specified eigenvectors. The number of eigenvectors which failed to converge is $⟨\mathit{\text{value}}⟩$. The corresponding columns of vr and vi are set to zero.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

If ${\lambda }_{i}$ is an exact eigenvalue, and ${\stackrel{~}{\lambda }}_{i}$ is the corresponding computed value, then
 $|λ~i-λi|≤c(n)ε‖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 9), 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)≤c(n)ε‖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 f08pef with ${\mathbf{job}}=\text{'S'}$ to compute the Schur form of ${A}^{\prime }$, followed by f08qlf.

## 8Parallelism and Performance

f02ecf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f02ecf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

f02ecf 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 an orthogonal similarity transformation: ${A}^{\prime }=QH{Q}^{\mathrm{T}}$. 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$ (real or complex) 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 f02ecf.
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.

## 10Example

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 ) .$

### 10.1Program Text

Program Text (f02ecfe.f90)

### 10.2Program Data

Program Data (f02ecfe.d)

### 10.3Program Results

Program Results (f02ecfe.r)