# NAG FL Interfacef08qgf (dtrsen)

## 1Purpose

f08qgf reorders the Schur factorization of a real general matrix so that a selected cluster of eigenvalues appears in the leading elements or blocks on the diagonal of the Schur form. The routine also optionally computes the reciprocal condition numbers of the cluster of eigenvalues and/or the invariant subspace.

## 2Specification

Fortran Interface
 Subroutine f08qgf ( job, n, t, ldt, q, ldq, wr, wi, m, s, sep, work, info)
 Integer, Intent (In) :: n, ldt, ldq, lwork, liwork Integer, Intent (Out) :: m, iwork(max(1,liwork)), info Real (Kind=nag_wp), Intent (Inout) :: t(ldt,*), q(ldq,*), wr(*), wi(*) Real (Kind=nag_wp), Intent (Out) :: s, sep, work(max(1,lwork)) Logical, Intent (In) :: select(*) Character (1), Intent (In) :: job, compq
#include <nag.h>
 void f08qgf_ (const char *job, const char *compq, const logical sel[], const Integer *n, double t[], const Integer *ldt, double q[], const Integer *ldq, double wr[], double wi[], Integer *m, double *s, double *sep, double work[], const Integer *lwork, Integer iwork[], const Integer *liwork, Integer *info, const Charlen length_job, const Charlen length_compq)
The routine may be called by the names f08qgf, nagf_lapackeig_dtrsen or its LAPACK name dtrsen.

## 3Description

f08qgf reorders the Schur factorization of a real general matrix $A=QT{Q}^{\mathrm{T}}$, so that a selected cluster of eigenvalues appears in the leading diagonal elements or blocks of the Schur form.
The reordered Schur form $\stackrel{~}{T}$ is computed by an orthogonal similarity transformation: $\stackrel{~}{T}={Z}^{\mathrm{T}}TZ$. Optionally the updated matrix $\stackrel{~}{Q}$ of Schur vectors is computed as $\stackrel{~}{Q}=QZ$, giving $A=\stackrel{~}{Q}\stackrel{~}{T}{\stackrel{~}{Q}}^{\mathrm{T}}$.
Let $\stackrel{~}{T}=\left(\begin{array}{cc}{T}_{11}& {T}_{12}\\ 0& {T}_{22}\end{array}\right)$, where the selected eigenvalues are precisely the eigenvalues of the leading $m$ by $m$ sub-matrix ${T}_{11}$. Let $\stackrel{~}{Q}$ be correspondingly partitioned as $\left(\begin{array}{cc}{Q}_{1}& {Q}_{2}\end{array}\right)$ where ${Q}_{1}$ consists of the first $m$ columns of $Q$. Then $A{Q}_{1}={Q}_{1}{T}_{11}$, and so the $m$ columns of ${Q}_{1}$ form an orthonormal basis for the invariant subspace corresponding to the selected cluster of eigenvalues.
Optionally the routine also computes estimates of the reciprocal condition numbers of the average of the cluster of eigenvalues and of the invariant subspace.

## 4References

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

## 5Arguments

1: $\mathbf{job}$Character(1) Input
On entry: indicates whether condition numbers are required for the cluster of eigenvalues and/or the invariant subspace.
${\mathbf{job}}=\text{'N'}$
No condition numbers are required.
${\mathbf{job}}=\text{'E'}$
Only the condition number for the cluster of eigenvalues is computed.
${\mathbf{job}}=\text{'V'}$
Only the condition number for the invariant subspace is computed.
${\mathbf{job}}=\text{'B'}$
Condition numbers for both the cluster of eigenvalues and the invariant subspace are computed.
Constraint: ${\mathbf{job}}=\text{'N'}$, $\text{'E'}$, $\text{'V'}$ or $\text{'B'}$.
2: $\mathbf{compq}$Character(1) Input
On entry: indicates whether the matrix $Q$ of Schur vectors is to be updated.
${\mathbf{compq}}=\text{'V'}$
The matrix $Q$ of Schur vectors is updated.
${\mathbf{compq}}=\text{'N'}$
No Schur vectors are updated.
Constraint: ${\mathbf{compq}}=\text{'V'}$ or $\text{'N'}$.
3: $\mathbf{select}\left(*\right)$Logical array Input
Note: the dimension of the array select must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the eigenvalues in the selected cluster. To select a real eigenvalue ${\lambda }_{j}$, ${\mathbf{select}}\left(j\right)$ must be set .TRUE.. To select a complex conjugate pair of eigenvalues ${\lambda }_{j}$ and ${\lambda }_{j+1}$ (corresponding to a $2$ by $2$ diagonal block), ${\mathbf{select}}\left(j\right)$ and/or ${\mathbf{select}}\left(j+1\right)$ must be set to .TRUE.. A complex conjugate pair of eigenvalues must be either both included in the cluster or both excluded. See also Section 9.
4: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrix $T$.
Constraint: ${\mathbf{n}}\ge 0$.
5: $\mathbf{t}\left({\mathbf{ldt}},*\right)$Real (Kind=nag_wp) array Input/Output
Note: the second dimension of the array t must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the $n$ by $n$ upper quasi-triangular matrix $T$ in canonical Schur form, as returned by f08pef. See also Section 9.
On exit: t is overwritten by the updated matrix $\stackrel{~}{T}$.
6: $\mathbf{ldt}$Integer Input
On entry: the first dimension of the array t as declared in the (sub)program from which f08qgf is called.
Constraint: ${\mathbf{ldt}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
7: $\mathbf{q}\left({\mathbf{ldq}},*\right)$Real (Kind=nag_wp) array Input/Output
Note: the second dimension of the array q must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{compq}}=\text{'V'}$ and at least $1$ if ${\mathbf{compq}}=\text{'N'}$.
On entry: if ${\mathbf{compq}}=\text{'V'}$, q must contain the $n$ by $n$ orthogonal matrix $Q$ of Schur vectors, as returned by f08pef.
On exit: if ${\mathbf{compq}}=\text{'V'}$, q contains the updated matrix of Schur vectors; the first $m$ columns of $Q$ form an orthonormal basis for the specified invariant subspace.
If ${\mathbf{compq}}=\text{'N'}$, q is not referenced.
8: $\mathbf{ldq}$Integer Input
On entry: the first dimension of the array q as declared in the (sub)program from which f08qgf is called.
Constraints:
• if ${\mathbf{compq}}=\text{'V'}$, ${\mathbf{ldq}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{compq}}=\text{'N'}$, ${\mathbf{ldq}}\ge 1$.
9: $\mathbf{wr}\left(*\right)$Real (Kind=nag_wp) array Output
10: $\mathbf{wi}\left(*\right)$Real (Kind=nag_wp) array Output
Note: the dimension of the arrays wr and wi must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On exit: the real and imaginary parts, respectively, of the reordered eigenvalues of $\stackrel{~}{T}$. The eigenvalues are stored in the same order as on the diagonal of $\stackrel{~}{T}$; see Section 9 for details. Note that if a complex eigenvalue is sufficiently ill-conditioned, then its value may differ significantly from its value before reordering.
11: $\mathbf{m}$Integer Output
On exit: $m$, the dimension of the specified invariant subspace. The value of $m$ is obtained by counting $1$ for each selected real eigenvalue and $2$ for each selected complex conjugate pair of eigenvalues (see select); $0\le m\le n$.
12: $\mathbf{s}$Real (Kind=nag_wp) Output
On exit: if ${\mathbf{job}}=\text{'E'}$ or $\text{'B'}$, s is a lower bound on the reciprocal condition number of the average of the selected cluster of eigenvalues. If ${\mathbf{m}}=0$ or ${\mathbf{n}}$, ${\mathbf{s}}=1$; if ${\mathbf{info}}={\mathbf{1}}$ (see Section 6), s is set to zero.
If ${\mathbf{job}}=\text{'N'}$ or $\text{'V'}$, s is not referenced.
13: $\mathbf{sep}$Real (Kind=nag_wp) Output
On exit: if ${\mathbf{job}}=\text{'V'}$ or $\text{'B'}$, sep is the estimated reciprocal condition number of the specified invariant subspace. If ${\mathbf{m}}=0$ or ${\mathbf{n}}$, ${\mathbf{sep}}=‖T‖$; if ${\mathbf{info}}={\mathbf{1}}$ (see Section 6), sep is set to zero.
If ${\mathbf{job}}=\text{'N'}$ or $\text{'E'}$, sep is not referenced.
14: $\mathbf{work}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{lwork}}\right)\right)$Real (Kind=nag_wp) array Workspace
On exit: if ${\mathbf{info}}={\mathbf{0}}$, ${\mathbf{work}}\left(1\right)$ contains the minimum value of lwork required for optimal performance.
15: $\mathbf{lwork}$Integer Input
On entry: the dimension of the array work as declared in the (sub)program from which f08qgf is called, unless ${\mathbf{lwork}}=-1$, in which case a workspace query is assumed and the routine only calculates the minimum dimension of work.
Constraints:
• if ${\mathbf{job}}=\text{'N'}$, ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ or ${\mathbf{lwork}}=-1$;
• if ${\mathbf{job}}=\text{'E'}$, ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathit{m}×\left({\mathbf{n}}-\mathit{m}\right)\right)$ or ${\mathbf{lwork}}=-1$;
• if ${\mathbf{job}}=\text{'V'}$ or $\text{'B'}$, ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,2\mathit{m}×\left({\mathbf{n}}-\mathit{m}\right)\right)$ or ${\mathbf{lwork}}=-1$.
The actual amount of workspace required cannot exceed ${{\mathbf{n}}}^{2}/4$ if ${\mathbf{job}}=\text{'E'}$ or ${{\mathbf{n}}}^{2}/2$ if ${\mathbf{job}}=\text{'V'}$ or $\text{'B'}$.
16: $\mathbf{iwork}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{liwork}}\right)\right)$Integer array Workspace
On exit: if ${\mathbf{info}}={\mathbf{0}}$, ${\mathbf{iwork}}\left(1\right)$ contains the required minimal size of liwork.
17: $\mathbf{liwork}$Integer Input
On entry: the dimension of the array iwork as declared in the (sub)program from which f08qgf is called, unless ${\mathbf{liwork}}=-1$, in which case a workspace query is assumed and the routine only calculates the minimum dimension of iwork.
Constraints:
• if ${\mathbf{job}}=\text{'N'}$ or $\text{'E'}$, ${\mathbf{liwork}}\ge 1$ or ${\mathbf{liwork}}=-1$;
• if ${\mathbf{job}}=\text{'V'}$ or $\text{'B'}$, ${\mathbf{liwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathit{m}×\left({\mathbf{n}}-\mathit{m}\right)\right)$ or ${\mathbf{liwork}}=-1$.
The actual amount of workspace required cannot exceed ${{\mathbf{n}}}^{2}/2$ if ${\mathbf{job}}=\text{'V'}$ or $\text{'B'}$.
18: $\mathbf{info}$Integer Output
On exit: ${\mathbf{info}}=0$ unless the routine detects an error (see Section 6).

## 6Error Indicators and Warnings

${\mathbf{info}}<0$
If ${\mathbf{info}}=-i$, argument $i$ had an illegal value. An explanatory message is output, and execution of the program is terminated.
${\mathbf{info}}=1$
The reordering of $T$ failed because a selected eigenvalue was too close to an unselected eigenvalue.
The reordering of $T$ failed because a selected eigenvalue was too close to an eigenvalue which was not selected; this error exit can only occur if at least one of the eigenvalues involved was complex. The problem is too ill-conditioned: consider modifying the selection of eigenvalues so that eigenvalues which are very close together are either all included in the cluster or all excluded. On exit, $T$ may have been partially reordered, but wr, wi and $Q$ (if requested) are updated consistently with $T$; s and sep (if requested) are both set to zero.

## 7Accuracy

The computed matrix $\stackrel{~}{T}$ is similar to a matrix $\left(T+E\right)$, where
 $E2 = Oε T2 ,$
and $\epsilon$ is the machine precision.
s cannot underestimate the true reciprocal condition number by more than a factor of $\sqrt{\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n-m\right)}$. sep may differ from the true value by $\sqrt{m\left(n-m\right)}$. The angle between the computed invariant subspace and the true subspace is $\frac{\mathit{O}\left(\epsilon \right){‖A‖}_{2}}{\mathit{sep}}$.
Note that if a $2$ by $2$ diagonal block is involved in the reordering, its off-diagonal elements are in general changed; the diagonal elements and the eigenvalues of the block are unchanged unless the block is sufficiently ill-conditioned, in which case they may be noticeably altered. It is possible for a $2$ by $2$ block to break into two $1$ by $1$ blocks, i.e., for a pair of complex eigenvalues to become purely real. The values of real eigenvalues however are never changed by the reordering.

## 8Parallelism and Performance

f08qgf 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.

The input matrix $T$ must be in canonical Schur form, as is the output matrix $\stackrel{~}{T}$. This has the following structure.
If all the computed eigenvalues are real, $\stackrel{~}{T}$ is upper triangular, and the diagonal elements of $\stackrel{~}{T}$ are the eigenvalues; ${\mathbf{wr}}\left(\mathit{i}\right)={\stackrel{~}{t}}_{\mathit{i}\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$ and ${\mathbf{wi}}\left(i\right)=0.0$.
If some of the computed eigenvalues form complex conjugate pairs, then $\stackrel{~}{T}$ has $2$ by $2$ diagonal blocks. Each diagonal block has the form
 $t~ii t~i,i+1 t~i+1,i t~i+1,i+1 = α β γ α$
where $\beta \gamma <0$. The corresponding eigenvalues are $\alpha ±\sqrt{\beta \gamma }$; ${\mathbf{wr}}\left(i\right)={\mathbf{wr}}\left(i+1\right)=\alpha$; ${\mathbf{wi}}\left(i\right)=+\sqrt{\left|\beta \gamma \right|}$; ${\mathbf{wi}}\left(i+1\right)=-{\mathbf{wi}}\left(i\right)$.
The complex analogue of this routine is f08quf.

## 10Example

This example reorders the Schur factorization of the matrix $A=QT{Q}^{\mathrm{T}}$ such that the two real eigenvalues appear as the leading elements on the diagonal of the reordered matrix $\stackrel{~}{T}$, where
 $T = 0.7995 -0.1144 0.0060 0.0336 0.0000 -0.0994 0.2478 0.3474 0.0000 -0.6483 -0.0994 0.2026 0.0000 0.0000 0.0000 -0.1007$
and
 $Q = 0.6551 0.1037 0.3450 0.6641 0.5236 -0.5807 -0.6141 -0.1068 -0.5362 -0.3073 -0.2935 0.7293 0.0956 0.7467 -0.6463 0.1249 .$
The example program for f08qgf illustrates the computation of error bounds for the eigenvalues.
The original matrix $A$ is given in Section 10 in f08nff.

### 10.1Program Text

Program Text (f08qgfe.f90)

### 10.2Program Data

Program Data (f08qgfe.d)

### 10.3Program Results

Program Results (f08qgfe.r)