# NAG FL Interfacef08yff (dtgexc)

## 1Purpose

f08yff reorders the generalized Schur factorization of a matrix pair in real generalized Schur form.

## 2Specification

Fortran Interface
 Subroutine f08yff ( n, a, lda, b, ldb, q, ldq, z, ldz, ifst, ilst, work, info)
 Integer, Intent (In) :: n, lda, ldb, ldq, ldz, lwork Integer, Intent (Inout) :: ifst, ilst Integer, Intent (Out) :: info Real (Kind=nag_wp), Intent (Inout) :: a(lda,*), b(ldb,*), q(ldq,*), z(ldz,*) Real (Kind=nag_wp), Intent (Out) :: work(max(1,lwork)) Logical, Intent (In) :: wantq, wantz
#include <nag.h>
 void f08yff_ (const logical *wantq, const logical *wantz, const Integer *n, double a[], const Integer *lda, double b[], const Integer *ldb, double q[], const Integer *ldq, double z[], const Integer *ldz, Integer *ifst, Integer *ilst, double work[], const Integer *lwork, Integer *info)
The routine may be called by the names f08yff, nagf_lapackeig_dtgexc or its LAPACK name dtgexc.

## 3Description

f08yff reorders the generalized real $n$ by $n$ matrix pair $\left(S,T\right)$ in real generalized Schur form, so that the diagonal element or block of $\left(S,T\right)$ with row index ${i}_{1}$ is moved to row ${i}_{2}$, using an orthogonal equivalence transformation. That is, $S$ and $T$ are factorized 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.
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'}$.
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}$.

## 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{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$.
2: $\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$.
3: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrices $S$ and $T$.
Constraint: ${\mathbf{n}}\ge 0$.
4: $\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}$.
5: $\mathbf{lda}$Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which f08yff is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
6: $\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}$
7: $\mathbf{ldb}$Integer Input
On entry: the first dimension of the array b as declared in the (sub)program from which f08yff is called.
Constraint: ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
8: $\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 orthogonal matrix $Q$.
On exit: if ${\mathbf{wantq}}=\mathrm{.TRUE.}$, the updated matrix $Q\stackrel{^}{Q}$.
If ${\mathbf{wantq}}=\mathrm{.FALSE.}$, q is not referenced.
9: $\mathbf{ldq}$Integer Input
On entry: the first dimension of the array q as declared in the (sub)program from which f08yff 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$.
10: $\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 orthogonal matrix $Z$.
On exit: if ${\mathbf{wantz}}=\mathrm{.TRUE.}$, the updated matrix $Z\stackrel{^}{Z}$.
If ${\mathbf{wantz}}=\mathrm{.FALSE.}$, z is not referenced.
11: $\mathbf{ldz}$Integer Input
On entry: the first dimension of the array z as declared in the (sub)program from which f08yff 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$.
12: $\mathbf{ifst}$Integer Input/Output
13: $\mathbf{ilst}$Integer Input/Output
On entry: the indices ${i}_{1}$ and ${i}_{2}$ that specify the reordering of the diagonal blocks of $\left(S,T\right)$. The block with row index ifst is moved to row ilst, by a sequence of swapping between adjacent blocks.
On exit: if ifst pointed on entry to the second row of a $2$ by $2$ block, it is changed to point to the first row; ilst always points to the first row of the block in its final position (which may differ from its input value by $+1$ or $-1$).
Constraint: $1\le {\mathbf{ifst}}\le {\mathbf{n}}$ and $1\le {\mathbf{ilst}}\le {\mathbf{n}}$.
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 f08yff is called.
If ${\mathbf{lwork}}=-1$, a workspace query is assumed; the routine only calculates the minimum size of the work array, returns this value as the first entry of the work array, and no error message related to lwork is issued.
Constraints:
if ${\mathbf{lwork}}\ne -1$,
• if ${\mathbf{n}}\le 1$, ${\mathbf{lwork}}\ge 1$;
• otherwise ${\mathbf{lwork}}\ge 4×{\mathbf{n}}+16$.
16: $\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 transformed matrix pair would be too far from generalized Schur form; the problem is ill-conditioned. $\left(S,T\right)$ may have been partially reordered, and ilst points to the first row of the current position of the block being moved.

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

## 8Parallelism and Performance

f08yff 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 f08ytf.

## 10Example

This example exchanges blocks $2$ and $1$ of the matrix pair $\left(S,T\right)$, where
 $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 and 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 .$

### 10.1Program Text

Program Text (f08yffe.f90)

### 10.2Program Data

Program Data (f08yffe.d)

### 10.3Program Results

Program Results (f08yffe.r)