f08 Chapter Contents
f08 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_dtrsen (f08qgc)

## 1  Purpose

nag_dtrsen (f08qgc) reorders the Schur factorization of a real general matrix so that a selected cluster of eigenvalues appears in the leading elements or blocks on the diagonal of the Schur form. The function also optionally computes the reciprocal condition numbers of the cluster of eigenvalues and/or the invariant subspace.

## 2  Specification

 #include #include
 void nag_dtrsen (Nag_OrderType order, Nag_JobType job, Nag_ComputeQType compq, const Nag_Boolean select[], Integer n, double t[], Integer pdt, double q[], Integer pdq, double wr[], double wi[], Integer *m, double *s, double *sep, NagError *fail)

## 3  Description

nag_dtrsen (f08qgc) reorders the Schur factorization of a real general matrix $A=QT{Q}^{\mathrm{T}}$, so that a selected cluster of eigenvalues appears in the leading diagonal elements or blocks of the Schur form.
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}}$.
Let $\stackrel{~}{T}=\left(\begin{array}{cc}{T}_{11}& {T}_{12}\\ 0& {T}_{22}\end{array}\right)$, where the selected eigenvalues are precisely the eigenvalues of the leading $m$ by $m$ sub-matrix ${T}_{11}$. Let $\stackrel{~}{Q}$ be correspondingly partitioned as $\left(\begin{array}{cc}{Q}_{1}& {Q}_{2}\end{array}\right)$ where ${Q}_{1}$ consists of the first $m$ columns of $Q$. Then $A{Q}_{1}={Q}_{1}{T}_{11}$, and so the $m$ columns of ${Q}_{1}$ form an orthonormal basis for the invariant subspace corresponding to the selected cluster of eigenvalues.
Optionally the function also computes estimates of the reciprocal condition numbers of the average of the cluster of eigenvalues and of the invariant subspace.

## 4  References

Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5  Arguments

1:     orderNag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or Nag_ColMajor.
2:     jobNag_JobTypeInput
On entry: indicates whether condition numbers are required for the cluster of eigenvalues and/or the invariant subspace.
${\mathbf{job}}=\mathrm{Nag_DoNothing}$
No condition numbers are required.
${\mathbf{job}}=\mathrm{Nag_EigVals}$
Only the condition number for the cluster of eigenvalues is computed.
${\mathbf{job}}=\mathrm{Nag_Subspace}$
Only the condition number for the invariant subspace is computed.
${\mathbf{job}}=\mathrm{Nag_DoBoth}$
Condition numbers for both the cluster of eigenvalues and the invariant subspace are computed.
Constraint: ${\mathbf{job}}=\mathrm{Nag_DoNothing}$, $\mathrm{Nag_EigVals}$, $\mathrm{Nag_Subspace}$ or $\mathrm{Nag_DoBoth}$.
3:     compqNag_ComputeQTypeInput
On entry: indicates whether the matrix $Q$ of Schur vectors is to be updated.
${\mathbf{compq}}=\mathrm{Nag_UpdateSchur}$
The matrix $Q$ of Schur vectors is updated.
${\mathbf{compq}}=\mathrm{Nag_NotQ}$
No Schur vectors are updated.
Constraint: ${\mathbf{compq}}=\mathrm{Nag_UpdateSchur}$ or $\mathrm{Nag_NotQ}$.
4:     select[$\mathit{dim}$]const Nag_BooleanInput
Note: the dimension, dim, of the array select must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the eigenvalues in the selected cluster. To select a real eigenvalue ${\lambda }_{j}$, ${\mathbf{select}}\left[j-1\right]$ must be set Nag_TRUE. To select a complex conjugate pair of eigenvalues ${\lambda }_{j}$ and ${\lambda }_{j+1}$ (corresponding to a $2$ by $2$ diagonal block), ${\mathbf{select}}\left[j-1\right]$ and/or ${\mathbf{select}}\left[j\right]$ must be set to Nag_TRUE. A complex conjugate pair of eigenvalues must be either both included in the cluster or both excluded. See also Section 8.
5:     nIntegerInput
On entry: $n$, the order of the matrix $T$.
Constraint: ${\mathbf{n}}\ge 0$.
6:     t[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array t must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdt}}×{\mathbf{n}}\right)$.
The $\left(i,j\right)$th element of the matrix $T$ is stored in
• ${\mathbf{t}}\left[\left(j-1\right)×{\mathbf{pdt}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{t}}\left[\left(i-1\right)×{\mathbf{pdt}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the $n$ by $n$ upper quasi-triangular matrix $T$ in canonical Schur form, as returned by nag_dhseqr (f08pec). See also Section 8.
On exit: t is overwritten by the updated matrix $\stackrel{~}{T}$.
7:     pdtIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array t.
Constraint: ${\mathbf{pdt}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
8:     q[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array q must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdq}}×{\mathbf{n}}\right)$ when ${\mathbf{compq}}=\mathrm{Nag_UpdateSchur}$;
• $1$ when ${\mathbf{compq}}=\mathrm{Nag_NotQ}$.
The $\left(i,j\right)$th element of the matrix $Q$ is stored in
• ${\mathbf{q}}\left[\left(j-1\right)×{\mathbf{pdq}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{q}}\left[\left(i-1\right)×{\mathbf{pdq}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: if ${\mathbf{compq}}=\mathrm{Nag_UpdateSchur}$, q must contain the $n$ by $n$ orthogonal matrix $Q$ of Schur vectors, as returned by nag_dhseqr (f08pec).
On exit: if ${\mathbf{compq}}=\mathrm{Nag_UpdateSchur}$, q contains the updated matrix of Schur vectors; the first $m$ columns of $Q$ form an orthonormal basis for the specified invariant subspace.
If ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, q is not referenced.
9:     pdqIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array q.
Constraints:
• if ${\mathbf{compq}}=\mathrm{Nag_UpdateSchur}$, ${\mathbf{pdq}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, ${\mathbf{pdq}}\ge 1$.
10:   wr[$\mathit{dim}$]doubleOutput
11:   wi[$\mathit{dim}$]doubleOutput
Note: the dimension, dim, of the arrays wr and wi must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On exit: the real and imaginary parts, respectively, of the reordered eigenvalues of $\stackrel{~}{T}$. The eigenvalues are stored in the same order as on the diagonal of $\stackrel{~}{T}$; see Section 8 for details. Note that if a complex eigenvalue is sufficiently ill-conditioned, then its value may differ significantly from its value before reordering.
12:   mInteger *Output
On exit: $m$, the dimension of the specified invariant subspace. The value of $m$ is obtained by counting $1$ for each selected real eigenvalue and $2$ for each selected complex conjugate pair of eigenvalues (see select); $0\le m\le n$.
13:   sdouble *Output
On exit: if ${\mathbf{job}}=\mathrm{Nag_EigVals}$ or $\mathrm{Nag_DoBoth}$, s is a lower bound on the reciprocal condition number of the average of the selected cluster of eigenvalues. If ${\mathbf{m}}=0\text{​ or ​}{\mathbf{n}}$, ${\mathbf{s}}=1$; if NE_REORDER (see Section 6), s is set to zero.
If ${\mathbf{job}}=\mathrm{Nag_DoNothing}$ or $\mathrm{Nag_Subspace}$, s is not referenced.
14:   sepdouble *Output
On exit: if ${\mathbf{job}}=\mathrm{Nag_Subspace}$ or $\mathrm{Nag_DoBoth}$, sep is the estimated reciprocal condition number of the specified invariant subspace. If ${\mathbf{m}}=0\text{​ or ​}{\mathbf{n}}$, ${\mathbf{sep}}=‖T‖$; if NE_REORDER (see Section 6), sep is set to zero.
If ${\mathbf{job}}=\mathrm{Nag_DoNothing}$ or $\mathrm{Nag_EigVals}$, sep is not referenced.
15:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_ENUM_INT_2
On entry, ${\mathbf{compq}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdq}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{compq}}=\mathrm{Nag_UpdateSchur}$, ${\mathbf{pdq}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
if ${\mathbf{compq}}=\mathrm{Nag_NotQ}$, ${\mathbf{pdq}}\ge 1$.
NE_INT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{pdq}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdq}}>0$.
On entry, ${\mathbf{pdt}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdt}}>0$.
NE_INT_2
On entry, ${\mathbf{pdt}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdt}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REORDER
The reordering of $T$ failed because a selected eigenvalue was too close to an eigenvalue which was not selected; this error exit can only occur if at least one of the eigenvalues involved was complex. The problem is too ill-conditioned: consider modifying the selection of eigenvalues so that eigenvalues which are very close together are either all included in the cluster or all excluded. On exit, $T$ may have been partially reordered, but wr, wi and $Q$ (if requested) are updated consistently with $T$; s and sep (if requested) are both set to zero.

## 7  Accuracy

The computed matrix $\stackrel{~}{T}$ is similar to a matrix $\left(T+E\right)$, where
 $E2 = Oε T2 ,$
and $\epsilon$ is the machine precision.
s cannot underestimate the true reciprocal condition number by more than a factor of $\sqrt{\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n-m\right)}$. sep may differ from the true value by $\sqrt{m\left(n-m\right)}$. The angle between the computed invariant subspace and the true subspace is $\frac{\mathit{O}\left(\epsilon \right){‖A‖}_{2}}{\mathit{sep}}$.
Note that if a $2$ by $2$ diagonal block is involved in the reordering, its off-diagonal elements are in general changed; the diagonal elements and the eigenvalues of the block are unchanged unless the block is sufficiently ill-conditioned, 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 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, $\stackrel{~}{T}$ is upper triangular, and the diagonal elements of $\stackrel{~}{T}$ are the eigenvalues; ${\mathbf{wr}}\left[\mathit{i}-1\right]={\stackrel{~}{t}}_{\mathit{i}\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$ and ${\mathbf{wi}}\left[i-1\right]=0.0$.
If some of the computed eigenvalues form complex conjugate pairs, then $\stackrel{~}{T}$ has $2$ by $2$ diagonal blocks. Each diagonal block has the form
 $t~ii t~i,i+1 t~i+1,i t~i+1,i+1 = α β γ α$
where $\beta \gamma <0$. The corresponding eigenvalues are $\alpha ±\sqrt{\beta \gamma }$; ${\mathbf{wr}}\left[i-1\right]={\mathbf{wr}}\left[i\right]=\alpha$; ${\mathbf{wi}}\left[i-1\right]=+\sqrt{\left|\beta \gamma \right|}$; ${\mathbf{wi}}\left[i\right]=-{\mathbf{wi}}\left[i-1\right]$.
The complex analogue of this function is nag_ztrsen (f08quc).

## 9  Example

This example reorders the Schur factorization of the matrix $A=QT{Q}^{\mathrm{T}}$ such that the two real eigenvalues appear as the leading elements on the diagonal of the reordered matrix $\stackrel{~}{T}$, where
 $T = 0.7995 -0.1144 0.0060 0.0336 0.0000 -0.0994 0.2478 0.3474 0.0000 -0.6483 -0.0994 0.2026 0.0000 0.0000 0.0000 -0.1007$
and
 $Q = 0.6551 0.1037 0.3450 0.6641 0.5236 -0.5807 -0.6141 -0.1068 -0.5362 -0.3073 -0.2935 0.7293 0.0956 0.7467 -0.6463 0.1249 .$
The example program for nag_dtrsen (f08qgc) illustrates the computation of error bounds for the eigenvalues.
The original matrix $A$ is given in Section 9 in nag_dorghr (f08nfc).

### 9.1  Program Text

Program Text (f08qgce.c)

### 9.2  Program Data

Program Data (f08qgce.d)

### 9.3  Program Results

Program Results (f08qgce.r)