F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08YGF (DTGSEN)

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

F08YGF (DTGSEN) reorders the generalized Schur factorization of a matrix pair in real generalized Schur form, so that a selected cluster of eigenvalues appears in the leading elements, or blocks on the diagonal of the generalized Schur form. The routine also, optionally, computes the reciprocal condition numbers of the cluster of eigenvalues and/or corresponding deflating subspaces.

## 2  Specification

 SUBROUTINE F08YGF ( IJOB, WANTQ, WANTZ, SELECT, N, A, LDA, B, LDB, ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, M, PL, PR, DIF, WORK, LWORK, IWORK, LIWORK, INFO)
 INTEGER IJOB, N, LDA, LDB, LDQ, LDZ, M, LWORK, IWORK(*), LIWORK, INFO REAL (KIND=nag_wp) A(LDA,*), B(LDB,*), ALPHAR(N), ALPHAI(N), BETA(N), Q(LDQ,*), Z(LDZ,*), PL, PR, DIF(*), WORK(max(1,LWORK)) LOGICAL WANTQ, WANTZ, SELECT(N)
The routine may be called by its LAPACK name dtgsen.

## 3  Description

F08YGF (DTGSEN) factorizes the generalized real $n$ by $n$ matrix pair $\left(S,T\right)$ in real generalized Schur form, using an orthogonal equivalence transformation as
 $S = Q^ S^ Z^T , T= Q^ T^ Z^T ,$
where $\left(\stackrel{^}{S},\stackrel{^}{T}\right)$ are also in real generalized Schur form and have the selected eigenvalues as the leading diagonal elements, or diagonal blocks. The leading columns of $Q$ and $Z$ are the generalized Schur vectors corresponding to the selected eigenvalues and form orthonormal subspaces for the left and right eigenspaces (deflating subspaces) of the pair $\left(S,T\right)$.
The pair $\left(S,T\right)$ are in real generalized Schur form if $S$ is block upper triangular with $1$ by $1$ and $2$ by $2$ diagonal blocks and $T$ is upper triangular as returned, for example, by F08XAF (DGGES), or F08XEF (DHGEQZ) with ${\mathbf{JOB}}=\text{'S'}$. The diagonal elements, or blocks, define the generalized eigenvalues $\left({\alpha }_{\mathit{i}},{\beta }_{\mathit{i}}\right)$, for $\mathit{i}=1,2,\dots ,n$, of the pair $\left(S,T\right)$. The eigenvalues are given by
 $λi = αi / βi ,$
but are returned as the pair $\left({\alpha }_{i},{\beta }_{i}\right)$ in order to avoid possible overflow in computing ${\lambda }_{i}$. Optionally, the routine returns reciprocals of condition number estimates for the selected eigenvalue cluster, $p$ and $q$, the right and left projection norms, and of deflating subspaces, ${\mathrm{Dif}}_{u}$ and ${\mathrm{Dif}}_{l}$. For more information see Sections 2.4.8 and 4.11 of Anderson et al. (1999).
If $S$ and $T$ are the result of a generalized Schur factorization of a matrix pair $\left(A,B\right)$
 $A = QSZT , B= QTZT$
then, optionally, the matrices $Q$ and $Z$ can be updated as $Q\stackrel{^}{Q}$ and $Z\stackrel{^}{Z}$. Note that the condition numbers of the pair $\left(S,T\right)$ are the same as those of the pair $\left(A,B\right)$.

## 4  References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia http://www.netlib.org/lapack/lug

## 5  Parameters

1:     IJOB – INTEGERInput
On entry: specifies whether condition numbers are required for the cluster of eigenvalues ($p$ and $q$) or the deflating subspaces (${\mathrm{Dif}}_{u}$ and ${\mathrm{Dif}}_{l}$).
${\mathbf{IJOB}}=0$
Only reorder with respect to SELECT. No extras.
${\mathbf{IJOB}}=1$
Reciprocal of norms of ‘projections’ onto left and right eigenspaces with respect to the selected cluster ($p$ and $q$).
${\mathbf{IJOB}}=2$
The upper bounds on ${\mathrm{Dif}}_{u}$ and ${\mathrm{Dif}}_{l}$. $F$-norm-based estimate (${\mathbf{DIF}}\left(1:2\right)$).
${\mathbf{IJOB}}=3$
Estimate of ${\mathrm{Dif}}_{u}$ and ${\mathrm{Dif}}_{l}$. $1$-norm-based estimate (${\mathbf{DIF}}\left(1:2\right)$). About five times as expensive as ${\mathbf{IJOB}}=2$.
${\mathbf{IJOB}}=4$
Compute PL, PR and DIF as in ${\mathbf{IJOB}}=0$, $1$ and $2$. Economic version to get it all.
${\mathbf{IJOB}}=5$
Compute PL, PR and DIF as in ${\mathbf{IJOB}}=0$, $1$ and $3$.
Constraint: $0\le {\mathbf{IJOB}}\le 5$.
2:     WANTQ – LOGICALInput
On entry: if ${\mathbf{WANTQ}}=\mathrm{.TRUE.}$, update the left transformation matrix $Q$.
If ${\mathbf{WANTQ}}=\mathrm{.FALSE.}$, do not update $Q$.
3:     WANTZ – LOGICALInput
On entry: if ${\mathbf{WANTZ}}=\mathrm{.TRUE.}$, update the right transformation matrix $Z$.
If ${\mathbf{WANTZ}}=\mathrm{.FALSE.}$, do not update $Z$.
4:     SELECT(N) – LOGICAL arrayInput
On entry: specifies the eigenvalues in the selected cluster. To select a real eigenvalue ${\lambda }_{j}$, ${\mathbf{SELECT}}\left(j\right)$ must be set to .TRUE..
To select a complex conjugate pair of eigenvalues ${\lambda }_{j}$ and ${\lambda }_{j+1}$, corresponding to a $2$ by $2$ diagonal block, either ${\mathbf{SELECT}}\left(j\right)$ or ${\mathbf{SELECT}}\left(j+1\right)$ or both must be set to .TRUE.; a complex conjugate pair of eigenvalues must be either both included in the cluster or both excluded.
5:     N – INTEGERInput
On entry: $n$, the order of the matrices $S$ and $T$.
Constraint: ${\mathbf{N}}\ge 0$.
6:     A(LDA,$*$) – REAL (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 matrix $S$ in the pair $\left(S,T\right)$.
On exit: the updated matrix $\stackrel{^}{S}$.
7:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F08YGF (DTGSEN) is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
8:     B(LDB,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array B must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
On entry: the matrix $T$, in the pair $\left(S,T\right)$.
On exit: the updated matrix $\stackrel{^}{T}$
9:     LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which F08YGF (DTGSEN) is called.
Constraint: ${\mathbf{LDB}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
10:   ALPHAR(N) – REAL (KIND=nag_wp) arrayOutput
On exit: see the description of BETA.
11:   ALPHAI(N) – REAL (KIND=nag_wp) arrayOutput
On exit: see the description of BETA.
12:   BETA(N) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{ALPHAR}}\left(\mathit{j}\right)/{\mathbf{BETA}}\left(\mathit{j}\right)$ and ${\mathbf{ALPHAI}}\left(\mathit{j}\right)/{\mathbf{BETA}}\left(\mathit{j}\right)$ are the real and imaginary parts respectively of the $\mathit{j}$th eigenvalue, for $\mathit{j}=1,2,\dots ,{\mathbf{N}}$.
If ${\mathbf{ALPHAI}}\left(j\right)$ is zero, then the $j$th eigenvalue is real; if positive then ${\mathbf{ALPHAI}}\left(j+1\right)$ is negative, and the $j$th and $\left(j+1\right)$st eigenvalues are a complex conjugate pair.
Conjugate pairs of eigenvalues correspond to the $2$ by $2$ diagonal blocks of $\stackrel{^}{S}$. These $2$ by $2$ blocks can be reduced by applying complex unitary transformations to $\left(\stackrel{^}{S},\stackrel{^}{T}\right)$ to obtain the complex Schur form $\left(\stackrel{~}{S},\stackrel{~}{T}\right)$, where $\stackrel{~}{S}$ is triangular (and complex). In this form ${\mathbf{ALPHAR}}+i{\mathbf{ALPHAI}}$ and BETA are the diagonals of $\stackrel{~}{S}$ and $\stackrel{~}{T}$ respectively.
13:   Q(LDQ,$*$) – REAL (KIND=nag_wp) arrayInput/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{WANTQ}}=\mathrm{.TRUE.}$, and at least $1$ otherwise.
On entry: if ${\mathbf{WANTQ}}=\mathrm{.TRUE.}$, the $n$ by $n$ matrix $Q$.
On exit: if ${\mathbf{WANTQ}}=\mathrm{.TRUE.}$, the updated matrix $Q\stackrel{^}{Q}$.
If ${\mathbf{WANTQ}}=\mathrm{.FALSE.}$, Q is not referenced.
14:   LDQ – INTEGERInput
On entry: the first dimension of the array Q as declared in the (sub)program from which F08YGF (DTGSEN) is called.
Constraints:
• if ${\mathbf{WANTQ}}=\mathrm{.TRUE.}$, ${\mathbf{LDQ}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• otherwise ${\mathbf{LDQ}}\ge 1$.
15:   Z(LDZ,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array Z must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$ if ${\mathbf{WANTZ}}=\mathrm{.TRUE.}$, and at least $1$ otherwise.
On entry: if ${\mathbf{WANTZ}}=\mathrm{.TRUE.}$, the $n$ by $n$ matrix $Z$.
On exit: if ${\mathbf{WANTZ}}=\mathrm{.TRUE.}$, the updated matrix $Z\stackrel{^}{Z}$.
If ${\mathbf{WANTZ}}=\mathrm{.FALSE.}$, Z is not referenced.
16:   LDZ – INTEGERInput
On entry: the first dimension of the array Z as declared in the (sub)program from which F08YGF (DTGSEN) is called.
Constraints:
• if ${\mathbf{WANTZ}}=\mathrm{.TRUE.}$, ${\mathbf{LDZ}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• otherwise ${\mathbf{LDZ}}\ge 1$.
17:   M – INTEGEROutput
On exit: the dimension of the specified pair of left and right eigenspaces (deflating subspaces).
18:   PL – REAL (KIND=nag_wp)Output
19:   PR – REAL (KIND=nag_wp)Output
On exit: if ${\mathbf{IJOB}}=1$, $4$ or $5$, PL and PR are lower bounds on the reciprocal of the norm of ‘projections’ $p$ and $q$ onto left and right eigenspaces with respect to the selected cluster. $0<{\mathbf{PL}}$, ${\mathbf{PR}}\le 1$.
If ${\mathbf{M}}=0$ or ${\mathbf{M}}={\mathbf{N}}$, ${\mathbf{PL}}={\mathbf{PR}}=1$.
If ${\mathbf{IJOB}}=0$, $2$ or $3$, PL and PR are not referenced.
20:   DIF($*$) – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array DIF must be at least $2$.
On exit: if ${\mathbf{IJOB}}\ge 2$, ${\mathbf{DIF}}\left(1:2\right)$ store the estimates of ${\mathrm{Dif}}_{u}$ and ${\mathrm{Dif}}_{l}$.
If ${\mathbf{IJOB}}=2$ or $4$, ${\mathbf{DIF}}\left(1:2\right)$ are $F$-norm-based upper bounds on ${\mathrm{Dif}}_{u}$ and ${\mathrm{Dif}}_{l}$.
If ${\mathbf{IJOB}}=3$ or $5$, ${\mathbf{DIF}}\left(1:2\right)$ are $1$-norm-based estimates of ${\mathrm{Dif}}_{u}$ and ${\mathrm{Dif}}_{l}$.
If ${\mathbf{M}}=0$ or $n$, ${\mathbf{DIF}}\left(1:2\right)$ $={‖\left(A,B\right)‖}_{F}$.
If ${\mathbf{IJOB}}=0$ or $1$, DIF is not referenced.
21:   WORK($\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{LWORK}}\right)$) – REAL (KIND=nag_wp) arrayWorkspace
On exit: if ${\mathbf{INFO}}={\mathbf{0}}$, ${\mathbf{WORK}}\left(1\right)$ returns the minimum LWORK.
If ${\mathbf{IJOB}}=0$, WORK is not referenced.
22:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F08YGF (DTGSEN) is called.
If ${\mathbf{LWORK}}=-1$, a workspace query is assumed; the routine only calculates the minimum sizes of the WORK and IWORK arrays, returns these values as the first entries of the WORK and IWORK arrays, and no error message related to LWORK or LIWORK is issued.
Constraints:
if ${\mathbf{LWORK}}\ne -1$,
• if ${\mathbf{N}}=0$, ${\mathbf{LWORK}}\ge 1$;
• if ${\mathbf{IJOB}}=1$, $2$ or $4$, ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(4×{\mathbf{N}}+16,2×{\mathbf{M}}×\left({\mathbf{N}}-{\mathbf{M}}\right)\right)$;
• if ${\mathbf{IJOB}}=3$ or $5$, ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(4×{\mathbf{N}}+16,4×{\mathbf{M}}×\left({\mathbf{N}}-{\mathbf{M}}\right)\right)$;
• otherwise ${\mathbf{LWORK}}\ge 4×{\mathbf{N}}+16$.
23:   IWORK($*$) – INTEGER arrayWorkspace
Note: the dimension of the array IWORK must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{LIWORK}}\right)$.
On exit: if ${\mathbf{INFO}}={\mathbf{0}}$, ${\mathbf{IWORK}}\left(1\right)$ returns the minimum LIWORK.
If ${\mathbf{IJOB}}=0$, IWORK is not referenced.
24:   LIWORK – INTEGERInput
On entry: the dimension of the array IWORK as declared in the (sub)program from which F08YGF (DTGSEN) is called.
If ${\mathbf{LIWORK}}=-1$, a workspace query is assumed; the routine only calculates the minimum sizes of the WORK and IWORK arrays, returns these values as the first entries of the WORK and IWORK arrays, and no error message related to LWORK or LIWORK is issued.
Constraints:
if ${\mathbf{LIWORK}}\ne -1$,
• if ${\mathbf{IJOB}}=1$, $2$ or $4$, ${\mathbf{LIWORK}}\ge {\mathbf{N}}+6$;
• if ${\mathbf{IJOB}}=3$ or $5$, ${\mathbf{LIWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(2×{\mathbf{M}}×\left({\mathbf{N}}-{\mathbf{M}}\right),{\mathbf{N}}+6\right)$;
• otherwise ${\mathbf{LIWORK}}\ge 1$.
25:   INFO – INTEGEROutput
On exit: ${\mathbf{INFO}}=0$ unless the routine detects an error (see Section 6).

## 6  Error Indicators and Warnings

Errors or warnings detected by the routine:
${\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$
Reordering of $\left(S,T\right)$ failed because the transformed matrix pair $\left(\stackrel{^}{S},\stackrel{^}{T}\right)$ would be too far from generalized Schur form; the problem is very ill-conditioned. $\left(S,T\right)$ may have been partially reordered. If requested, $0$ is returned in ${\mathbf{DIF}}\left(1:2\right)$, PL and PR.

## 7  Accuracy

The computed generalized Schur form is nearly the exact generalized Schur form for nearby matrices $\left(S+E\right)$ and $\left(T+F\right)$, where
 $E2 = O⁡ε S2 and F2= O⁡ε T2 ,$
and $\epsilon$ is the machine precision. See Section 4.11 of Anderson et al. (1999) for further details of error bounds for the generalized nonsymmetric eigenproblem, and for information on the condition numbers returned.

The complex analogue of this routine is F08YUF (ZTGSEN).

## 9  Example

This example reorders the generalized Schur factors $S$ and $T$ and update the matrices $Q$ and $Z$ given by
 $S = 4.0 1.0 1.0 2.0 0.0 3.0 4.0 1.0 0.0 1.0 3.0 1.0 0.0 0.0 0.0 6.0 , T= 2.0 1.0 1.0 3.0 0.0 1.0 2.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 2.0 ,$
 $Q = 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 and Z= 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 ,$
selecting the first and fourth generalized eigenvalues to be moved to the leading positions. Bases for the left and right deflating subspaces, and estimates of the condition numbers for the eigenvalues and Frobenius norm based bounds on the condition numbers for the deflating subspaces are also output.

### 9.1  Program Text

Program Text (f08ygfe.f90)

### 9.2  Program Data

Program Data (f08ygfe.d)

### 9.3  Program Results

Program Results (f08ygfe.r)