# NAG FL Interfacef08ygf (dtgsen)

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine f08ygf ( ijob, n, a, lda, b, ldb, beta, q, ldq, z, ldz, m, pl, pr, dif, work, info)
 Integer, Intent (In) :: ijob, n, lda, ldb, ldq, ldz, lwork, liwork Integer, Intent (Out) :: m, iwork(max(1,liwork)), info Real (Kind=nag_wp), Intent (Inout) :: a(lda,*), b(ldb,*), q(ldq,*), z(ldz,*), dif(*) Real (Kind=nag_wp), Intent (Out) :: alphar(n), alphai(n), beta(n), pl, pr, work(max(1,lwork)) Logical, Intent (In) :: wantq, wantz, select(n)
#include <nag.h>
 void f08ygf_ (const Integer *ijob, const logical *wantq, const logical *wantz, const logical sel[], const Integer *n, double a[], const Integer *lda, double b[], const Integer *ldb, double alphar[], double alphai[], double beta[], double q[], const Integer *ldq, double z[], const Integer *ldz, Integer *m, double *pl, double *pr, double dif[], double work[], const Integer *lwork, Integer iwork[], const Integer *liwork, Integer *info)
The routine may be called by the names f08ygf, nagf_lapackeig_dtgsen or its LAPACK name dtgsen.

## 3Description

f08ygf 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, or f08xef 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)$.

## 4References

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 https://www.netlib.org/lapack/lug

## 5Arguments

1: $\mathbf{ijob}$Integer Input
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: $\mathbf{wantq}$Logical Input
On entry: if ${\mathbf{wantq}}=\mathrm{.TRUE.}$, update the left transformation matrix $Q$.
If ${\mathbf{wantq}}=\mathrm{.FALSE.}$, do not update $Q$.
3: $\mathbf{wantz}$Logical Input
On entry: if ${\mathbf{wantz}}=\mathrm{.TRUE.}$, update the right transformation matrix $Z$.
If ${\mathbf{wantz}}=\mathrm{.FALSE.}$, do not update $Z$.
4: $\mathbf{select}\left({\mathbf{n}}\right)$Logical array Input
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: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrices $S$ and $T$.
Constraint: ${\mathbf{n}}\ge 0$.
6: $\mathbf{a}\left({\mathbf{lda}},*\right)$Real (Kind=nag_wp) array Input/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: $\mathbf{lda}$Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which f08ygf is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
8: $\mathbf{b}\left({\mathbf{ldb}},*\right)$Real (Kind=nag_wp) array Input/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: $\mathbf{ldb}$Integer Input
On entry: the first dimension of the array b as declared in the (sub)program from which f08ygf is called.
Constraint: ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
10: $\mathbf{alphar}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: see the description of beta.
11: $\mathbf{alphai}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: see the description of beta.
12: $\mathbf{beta}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
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: $\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{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: $\mathbf{ldq}$Integer Input
On entry: the first dimension of the array q as declared in the (sub)program from which f08ygf 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: $\mathbf{z}\left({\mathbf{ldz}},*\right)$Real (Kind=nag_wp) array Input/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: $\mathbf{ldz}$Integer Input
On entry: the first dimension of the array z as declared in the (sub)program from which f08ygf 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: $\mathbf{m}$Integer Output
On exit: the dimension of the specified pair of left and right eigenspaces (deflating subspaces).
18: $\mathbf{pl}$Real (Kind=nag_wp) Output
19: $\mathbf{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: $\mathbf{dif}\left(*\right)$Real (Kind=nag_wp) array Output
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: $\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)$ returns the minimum lwork.
If ${\mathbf{ijob}}=0$, work is not referenced.
22: $\mathbf{lwork}$Integer Input
On entry: the dimension of the array work as declared in the (sub)program from which f08ygf 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: $\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)$ returns the minimum liwork.
If ${\mathbf{ijob}}=0$, iwork is not referenced.
24: $\mathbf{liwork}$Integer Input
On entry: the dimension of the array iwork as declared in the (sub)program from which f08ygf 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: $\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$
Reordering of $\left(S,T\right)$ failed because the transformed matrix pair 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\right)$ and ${\mathbf{dif}}\left(2\right)$, pl and pr.

## 7Accuracy

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.

## 8Parallelism and Performance

f08ygf 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 complex analogue of this routine is f08yuf.

## 10Example

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.

### 10.1Program Text

Program Text (f08ygfe.f90)

### 10.2Program Data

Program Data (f08ygfe.d)

### 10.3Program Results

Program Results (f08ygfe.r)