NAG Library Routine Document
F08QFF (DTREXC)
1 Purpose
F08QFF (DTREXC) reorders the Schur factorization of a real general matrix.
2 Specification
INTEGER 
N, LDT, LDQ, IFST, ILST, INFO 
REAL (KIND=nag_wp) 
T(LDT,*), Q(LDQ,*), WORK(N) 
CHARACTER(1) 
COMPQ 

The routine may be called by its
LAPACK
name dtrexc.
3 Description
F08QFF (DTREXC) reorders the Schur factorization of a real general matrix
$A=QT{Q}^{\mathrm{T}}$, so that the diagonal element or block of
$T$ with row index
IFST is moved to row
ILST.
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}}$.
4 References
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
5 Parameters
 1: 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'}$.
 2: N – INTEGERInput
On entry: $n$, the order of the matrix $T$.
Constraint:
${\mathbf{N}}\ge 0$.
 3: T(LDT,$*$) – REAL (KIND=nag_wp) arrayInput/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 quasitriangular matrix
$T$ in canonical Schur form, as returned by
F08PEF (DHSEQR).
On exit:
T is overwritten by the updated matrix
$\stackrel{~}{T}$. See also
Section 8.
 4: LDT – INTEGERInput
On entry: the first dimension of the array
T as declared in the (sub)program from which F08QFF (DTREXC) is called.
Constraint:
${\mathbf{LDT}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
 5: 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{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.
On exit: if
${\mathbf{COMPQ}}=\text{'V'}$,
Q contains the updated matrix of Schur vectors.
If
${\mathbf{COMPQ}}=\text{'N'}$,
Q is not referenced.
 6: LDQ – INTEGERInput
On entry: the first dimension of the array
Q as declared in the (sub)program from which F08QFF (DTREXC) 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$.
 7: IFST – INTEGERInput/Output
 8: ILST – INTEGERInput/Output
On entry:
IFST and
ILST must specify the reordering of the diagonal elements or blocks of
$T$. The element or block with row index
IFST is moved to row
ILST by a sequence of exchanges between adjacent elements or blocks.
On exit: 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
$\pm 1$).
Constraint:
$1\le {\mathbf{IFST}}\le {\mathbf{N}}$ and $1\le {\mathbf{ILST}}\le {\mathbf{N}}$.
 9: WORK(N) – REAL (KIND=nag_wp) arrayWorkspace
 10: INFO – INTEGEROutput
On exit:
${\mathbf{INFO}}=0$ unless the routine detects an error (see
Section 6).
6 Error 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$
Two adjacent diagonal elements or blocks could not be successfully exchanged. This error can only occur if the exchange involves at least one
$2$ by
$2$ block; it implies that the problem is very illconditioned, and that the eigenvalues of the two blocks are very close. On exit,
$T$ may have been partially reordered, and
ILST points to the first row of the current position of the block being moved;
$Q$ (if requested) is updated consistently with
$T$.
7 Accuracy
The computed matrix
$\stackrel{~}{T}$ is exactly similar to a matrix
$\left(T+E\right)$, where
and
$\epsilon $ is the
machine precision.
Note that if a $2$ by $2$ diagonal block is involved in the reordering, its offdiagonal elements are in general changed; the diagonal elements and the eigenvalues of the block are unchanged unless the block is sufficiently illconditioned, 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.
The total number of floating point operations is approximately $6nr$ if ${\mathbf{COMPQ}}=\text{'N'}$, and $12nr$ if ${\mathbf{COMPQ}}=\text{'V'}$, where $r=\left{\mathbf{IFST}}{\mathbf{ILST}}\right$.
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, $T$ is upper triangular and its diagonal elements are the eigenvalues.
If some of the computed eigenvalues form complex conjugate pairs, then
$T$ has
$2$ by
$2$ diagonal blocks. Each diagonal block has the form
where
$\beta \gamma <0$. The corresponding eigenvalues are
$\alpha \pm \sqrt{\beta \gamma}$.
The complex analogue of this routine is
F08QTF (ZTREXC).
9 Example
This example reorders the Schur factorization of the matrix
$T$ so that the
$2$ by
$2$ block with row index
$2$ is moved to row
$1$, where
9.1 Program Text
Program Text (f08qffe.f90)
9.2 Program Data
Program Data (f08qffe.d)
9.3 Program Results
Program Results (f08qffe.r)