# ?tgexc

Reorders the generalized Schur decomposition of a pair of matrices (A,B) so that one diagonal block of (A,B) moves to another row index.

## Syntax

FORTRAN 77:

call stgexc(wantq, wantz, n, a, lda, b, ldb, q, ldq, z, ldz, ifst, ilst, work, lwork, info)

call dtgexc(wantq, wantz, n, a, lda, b, ldb, q, ldq, z, ldz, ifst, ilst, work, lwork, info)

call ctgexc(wantq, wantz, n, a, lda, b, ldb, q, ldq, z, ldz, ifst, ilst, info)

call ztgexc(wantq, wantz, n, a, lda, b, ldb, q, ldq, z, ldz, ifst, ilst, info)

Fortran 95:

call tgexc(a, b [,ifst] [,ilst] [,z] [,q] [,info])

## Description

This routine reorders the generalized real-Schur/Schur decomposition of a real/complex matrix pair (A,B) using an orthogonal/unitary equivalence transformation

`(A,B) = Q*(A,B)*ZH`,

so that the diagonal block of (A, B) with row index ifst is moved to row ilst. Matrix pair (A, B) must be in a generalized real-Schur/Schur canonical form (as returned by ?gges), that is, A is block upper triangular with 1-by-1 and 2-by-2 diagonal blocks and B is upper triangular. Optionally, the matrices Q and Z of generalized Schur vectors are updated.

`Q(in)*A(in)*Z(in)' = Q(out)*A(out)*Z(out)'`

`Q(in)*B(in)*Z(in)' = Q(out)*B(out)*Z(out)'`.

## Input Parameters

wantq, wantz

  LOGICAL.

  If `wantq = .TRUE.`, update the left transformation matrix Q;

  If `wantq = .FALSE.`, do not update Q;

  If `wantz = .TRUE.`, update the right transformation matrix Z;

  If `wantz = .FALSE.`, do not update Z.

n

  INTEGER. The order of the matrices A and B (n ≥ 0).

a, b, q,

  REAL for stgexc

  DOUBLE PRECISION for dtgexc

  COMPLEX for ctgexc

  DOUBLE COMPLEX for ztgexc.

  Arrays:

  a(lda,*) contains the matrix A.

  The second dimension of a must be at least max(1, n).

  b(ldb,*) contains the matrix B. The second dimension of b must be at least max(1, n).

  q (ldq,*)

  If `wantq = .FALSE.`, then q is not referenced.

  If `wantq = .TRUE.`, then q must contain the orthogonal/unitary matrix Q.

  The second dimension of q must be at least max(1, n).

  z (ldz,*)

  If `wantz = .FALSE.`, then z is not referenced.

  If `wantz = .TRUE.`, then z must contain the orthogonal/unitary matrix Z.

  The second dimension of z must be at least max(1, n).

lda

  INTEGER. The first dimension of a; at least max(1, n).

ldb

  INTEGER. The first dimension of b; at least max(1, n).

ldq

  INTEGER. The first dimension of q;

  If `wantq = .FALSE.`, then ldq ≥ 1.

  If `wantq = .TRUE.`, then ldq ≥ max(1, n).

ldz

  INTEGER. The first dimension of z;

  If `wantz = .FALSE.`, then ldz ≥ 1.

  If `wantz = .TRUE.`, then ldz ≥ max(1, n).

ifst, ilst

  INTEGER. Specify the reordering of the diagonal blocks of (A, B). The block with row index ifst is moved to row ilst, by a sequence of swapping between adjacent blocks. Constraint: `1 ≤ ifst, ilst ≤ n`.

work

  REAL for stgexc;

  DOUBLE PRECISION for dtgexc.

  Workspace array, DIMENSION (lwork). Used in real flavors only.

lwork

  INTEGER. The dimension of work; must be at least `4n +16`.

  If `lwork = -1`, then a workspace query is assumed; the routine only calculates the optimal 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 by xerbla. See Application Notes for details.

## Output Parameters

a, b

  Overwritten by the updated matrices A and B.

ifst, ilst

  Overwritten for real flavors only.

  If ifst pointed to the second row of a 2 by 2 block on entry, 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).

info

  INTEGER.

  If `info = 0`, the execution is successful.

  If `info = -i`, the i-th parameter had an illegal value.

  If `info = 1`, the transformed matrix pair (A, B) would be too far from generalized Schur form; the problem is ill-conditioned. (A, B) may have been partially reordered, and ilst points to the first row of the current position of the block being moved.

## Fortran 95 Interface Notes

Routines in Fortran 95 interface have fewer arguments in the calling sequence than their FORTRAN 77 counterparts. For general conventions applied to skip redundant or restorable arguments, see Fortran 95 Interface Conventions.

Specific details for the routine tgexc interface are the following:

a

  Holds the matrix A of size (n,n).

b

  Holds the matrix B of size (n,n).

z

  Holds the matrix Z of size (n,n).

q

  Holds the matrix Q of size (n,n).

wantq

  Restored based on the presence of the argument q as follows:

  wantq = .TRUE, if q is present,

  wantq = .FALSE, if q is omitted.

wantz

  Restored based on the presence of the argument z as follows:

  wantz = .TRUE, if z is present,

  wantz = .FALSE, if z is omitted.

## Application Notes

If it is not clear how much workspace to supply, use a generous value of lwork for the first run, or set `lwork = -1`.

In first case the routine completes the task, though probably not so fast as with a recommended workspace, and provides the recommended workspace in the first element of the corresponding array work on exit. Use this value (`work(1)`) for subsequent runs.

If `lwork = -1`, then the routine returns immediately and provides the recommended workspace in the first element of the corresponding array (work). This operation is called a workspace query.

Note that if lwork is less than the minimal required value and is not equal to -1, then the routine returns immediately with an error exit and does not provide any information on the recommended workspace.

Parent topic: Generalized Nonsymmetric Eigenvalue Problems