F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08PEF (DHSEQR)

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.
Warning. The specification of the parameter LWORK changed at Mark 20: LWORK is no longer redundant.

## 1  Purpose

F08PEF (DHSEQR) computes all the eigenvalues and, optionally, the Schur factorization of a real Hessenberg matrix or a real general matrix which has been reduced to Hessenberg form.

## 2  Specification

 SUBROUTINE F08PEF ( JOB, COMPZ, N, ILO, IHI, H, LDH, WR, WI, Z, LDZ, WORK, LWORK, INFO)
 INTEGER N, ILO, IHI, LDH, LDZ, LWORK, INFO REAL (KIND=nag_wp) H(LDH,*), WR(*), WI(*), Z(LDZ,*), WORK(max(1,LWORK)) CHARACTER(1) JOB, COMPZ
The routine may be called by its LAPACK name dhseqr.

## 3  Description

F08PEF (DHSEQR) computes all the eigenvalues and, optionally, the Schur factorization of a real upper Hessenberg matrix $H$:
 $H = ZTZT ,$
where $T$ is an upper quasi-triangular matrix (the Schur form of $H$), and $Z$ is the orthogonal matrix whose columns are the Schur vectors ${z}_{i}$. See Section 8 for details of the structure of $T$.
The routine may also be used to compute the Schur factorization of a real general matrix $A$ which has been reduced to upper Hessenberg form $H$:
 $A = QHQT, where ​Q​ is orthogonal, = QZTQZT.$
In this case, after F08NEF (DGEHRD) has been called to reduce $A$ to Hessenberg form, F08NFF (DORGHR) must be called to form $Q$ explicitly; $Q$ is then passed to F08PEF (DHSEQR), which must be called with ${\mathbf{COMPZ}}=\text{'V'}$.
The routine can also take advantage of a previous call to F08NHF (DGEBAL) which may have balanced the original matrix before reducing it to Hessenberg form, so that the Hessenberg matrix $H$ has the structure:
 $H11 H12 H13 H22 H23 H33$
where ${H}_{11}$ and ${H}_{33}$ are upper triangular. If so, only the central diagonal block ${H}_{22}$ (in rows and columns ${i}_{\mathrm{lo}}$ to ${i}_{\mathrm{hi}}$) needs to be further reduced to Schur form (the blocks ${H}_{12}$ and ${H}_{23}$ are also affected). Therefore the values of ${i}_{\mathrm{lo}}$ and ${i}_{\mathrm{hi}}$ can be supplied to F08PEF (DHSEQR) directly. Also, F08NJF (DGEBAK) must be called after this routine to permute the Schur vectors of the balanced matrix to those of the original matrix. If F08NHF (DGEBAL) has not been called however, then ${i}_{\mathrm{lo}}$ must be set to $1$ and ${i}_{\mathrm{hi}}$ to $n$. Note that if the Schur factorization of $A$ is required, F08NHF (DGEBAL) must not be called with ${\mathbf{JOB}}=\text{'S'}$ or $\text{'B'}$, because the balancing transformation is not orthogonal.
F08PEF (DHSEQR) uses a multishift form of the upper Hessenberg $QR$ algorithm, due to Bai and Demmel (1989). The Schur vectors are normalized so that ${‖{z}_{i}‖}_{2}=1$, but are determined only to within a factor $±1$.
Bai Z and Demmel J W (1989) On a block implementation of Hessenberg multishift $QR$ iteration Internat. J. High Speed Comput. 1 97–112
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5  Parameters

1:     JOB – CHARACTER(1)Input
On entry: indicates whether eigenvalues only or the Schur form $T$ is required.
${\mathbf{JOB}}=\text{'E'}$
Eigenvalues only are required.
${\mathbf{JOB}}=\text{'S'}$
The Schur form $T$ is required.
Constraint: ${\mathbf{JOB}}=\text{'E'}$ or $\text{'S'}$.
2:     COMPZ – CHARACTER(1)Input
On entry: indicates whether the Schur vectors are to be computed.
${\mathbf{COMPZ}}=\text{'N'}$
No Schur vectors are computed (and the array Z is not referenced).
${\mathbf{COMPZ}}=\text{'I'}$
The Schur vectors of $H$ are computed (and the array Z is initialized by the routine).
${\mathbf{COMPZ}}=\text{'V'}$
The Schur vectors of $A$ are computed (and the array Z must contain the matrix $Q$ on entry).
Constraint: ${\mathbf{COMPZ}}=\text{'N'}$, $\text{'V'}$ or $\text{'I'}$.
3:     N – INTEGERInput
On entry: $n$, the order of the matrix $H$.
Constraint: ${\mathbf{N}}\ge 0$.
4:     ILO – INTEGERInput
5:     IHI – INTEGERInput
On entry: if the matrix $A$ has been balanced by F08NHF (DGEBAL), then ILO and IHI must contain the values returned by that routine. Otherwise, ILO must be set to $1$ and IHI to N.
Constraint: ${\mathbf{ILO}}\ge 1$ and $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ILO}},{\mathbf{N}}\right)\le {\mathbf{IHI}}\le {\mathbf{N}}$.
6:     H(LDH,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array H must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
On entry: the $n$ by $n$ upper Hessenberg matrix $H$, as returned by F08NEF (DGEHRD).
On exit: if ${\mathbf{JOB}}=\text{'E'}$, the array contains no useful information.
If ${\mathbf{JOB}}=\text{'S'}$, H is overwritten by the upper quasi-triangular matrix $T$ from the Schur decomposition (the Schur form) unless ${\mathbf{INFO}}>{\mathbf{0}}$.
7:     LDH – INTEGERInput
On entry: the first dimension of the array H as declared in the (sub)program from which F08PEF (DHSEQR) is called.
Constraint: ${\mathbf{LDH}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
8:     WR($*$) – REAL (KIND=nag_wp) arrayOutput
9:     WI($*$) – REAL (KIND=nag_wp) arrayOutput
Note: the dimension 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 computed eigenvalues, unless ${\mathbf{INFO}}>{\mathbf{0}}$ (in which case see Section 6). Complex conjugate pairs of eigenvalues appear consecutively with the eigenvalue having positive imaginary part first. The eigenvalues are stored in the same order as on the diagonal of the Schur form $T$ (if computed); see Section 8 for details.
10:   Z(LDZ,$*$) – REAL (KIND=nag_wp) arrayInput/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{COMPZ}}=\text{'V'}$ or $\text{'I'}$ and at least $1$ if ${\mathbf{COMPZ}}=\text{'N'}$.
On entry: if ${\mathbf{COMPZ}}=\text{'V'}$, Z must contain the orthogonal matrix $Q$ from the reduction to Hessenberg form.
If ${\mathbf{COMPZ}}=\text{'I'}$, Z need not be set.
On exit: if ${\mathbf{COMPZ}}=\text{'V'}$ or $\text{'I'}$, Z contains the orthogonal matrix of the required Schur vectors, unless ${\mathbf{INFO}}>{\mathbf{0}}$.
If ${\mathbf{COMPZ}}=\text{'N'}$, Z is not referenced.
11:   LDZ – INTEGERInput
On entry: the first dimension of the array Z as declared in the (sub)program from which F08PEF (DHSEQR) is called.
Constraints:
• if ${\mathbf{COMPZ}}=\text{'I'}$ or $\text{'V'}$, ${\mathbf{LDZ}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• if ${\mathbf{COMPZ}}=\text{'N'}$, ${\mathbf{LDZ}}\ge 1$.
12:   WORK($\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{LWORK}}\right)$) – REAL (KIND=nag_wp) arrayWorkspace
On exit: if ${\mathbf{INFO}}={\mathbf{0}}$, ${\mathbf{WORK}}\left(1\right)$ contains the minimum value of LWORK required for optimal performance.
13:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F08PEF (DHSEQR) is called, unless ${\mathbf{LWORK}}=-1$, in which case a workspace query is assumed and the routine only calculates the minimum dimension of WORK.
Constraint: ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$ or ${\mathbf{LWORK}}=-1$.
14:   INFO – INTEGEROutput
On exit: ${\mathbf{INFO}}=0$ unless the routine detects an error (see Section 6).

## 6  Error Indicators and Warnings

Errors or warnings detected by the routine:
${\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}}>0$
The algorithm has failed to find all the eigenvalues after a total of $30×\left({\mathbf{IHI}}-{\mathbf{ILO}}+1\right)$ iterations. If ${\mathbf{INFO}}=i$, elements $1,2,\dots ,{\mathbf{ILO}}-1$ and $i+1,i+2,\dots ,n$ of WR and WI contain the real and imaginary parts of contain the eigenvalues which have been found.
If ${\mathbf{JOB}}=\text{'E'}$, then on exit, the remaining unconverged eigenvalues are the eigenvalues of the upper Hessenberg matrix $\stackrel{^}{H}$, formed from ${\mathbf{H}}\left({\mathbf{ILO}}:{\mathbf{INFO}},{\mathbf{ILO}}:{\mathbf{INFO}}\right)$, i.e., the ILO through INFO rows and columns of the final output matrix $H$.
If ${\mathbf{JOB}}=\text{'S'}$, then on exit
 $* Hi U = U H~$
for some matrix $U$, where ${H}_{i}$ is the input upper Hessenberg matrix and $\stackrel{~}{H}$ is an upper Hessenberg matrix formed from ${\mathbf{H}}\left({\mathbf{INFO}}+1:{\mathbf{IHI}},{\mathbf{INFO}}+1:{\mathbf{IHI}}\right)$.
If ${\mathbf{COMPZ}}=\text{'V'}$, then on exit
 $Zout = Zin U$
where $U$ is defined in $\left(*\right)$ (regardless of the value of JOB).
If ${\mathbf{COMPZ}}=\text{'I'}$, then on exit
 $Zout = U$
where $U$ is defined in $\left(*\right)$ (regardless of the value of JOB).
If ${\mathbf{INFO}}>{\mathbf{0}}$ and ${\mathbf{COMPZ}}=\text{'N'}$, then Z is not accessed.

## 7  Accuracy

The computed Schur factorization is the exact factorization of a nearby matrix $\left(H+E\right)$, where
 $E2 = Oε H2 ,$
and $\epsilon$ is the machine precision.
If ${\lambda }_{i}$ is an exact eigenvalue, and ${\stackrel{~}{\lambda }}_{i}$ is the corresponding computed value, then
 $λ~i - λi ≤ c n ε H2 si ,$
where $c\left(n\right)$ is a modestly increasing function of $n$, and ${s}_{i}$ is the reciprocal condition number of ${\lambda }_{i}$. The condition numbers ${s}_{i}$ may be computed by calling F08QLF (DTRSNA).

The total number of floating point operations depends on how rapidly the algorithm converges, but is typically about:
• $7{n}^{3}$ if only eigenvalues are computed;
• $10{n}^{3}$ if the Schur form is computed;
• $20{n}^{3}$ if the full Schur factorization is computed.
The Schur form $T$ has the following structure (referred to as canonical Schur form).
If all the computed eigenvalues are real, $T$ is upper triangular, and the diagonal elements of $T$ are the eigenvalues; ${\mathbf{WR}}\left(\mathit{i}\right)={t}_{\mathit{i}\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, and ${\mathbf{WI}}\left(i\right)=0.0$.
If some of the computed eigenvalues form complex conjugate pairs, then $T$ has $2$ by $2$ diagonal blocks. Each diagonal block has the form
 $tii ti,i+1 ti+1,i ti+1,i+1 = α β γ α$
where $\beta \gamma <0$. The corresponding eigenvalues are $\alpha ±\sqrt{\beta \gamma }$; ${\mathbf{WR}}\left(i\right)={\mathbf{WR}}\left(i+1\right)=\alpha$; ${\mathbf{WI}}\left(i\right)=+\sqrt{\left|\beta \gamma \right|}$; ${\mathbf{WI}}\left(i+1\right)=-{\mathbf{WI}}\left(i\right)$.
The complex analogue of this routine is F08PSF (ZHSEQR).

## 9  Example

This example computes all the eigenvalues and the Schur factorization of the upper Hessenberg matrix $H$, where
 $H = 0.3500 -0.1160 -0.3886 -0.2942 -0.5140 0.1225 0.1004 0.1126 0.0000 0.6443 -0.1357 -0.0977 0.0000 0.0000 0.4262 0.1632 .$
See also Section 9 in F08NFF (DORGHR), which illustrates the use of this routine to compute the Schur factorization of a general matrix.

### 9.1  Program Text

Program Text (f08pefe.f90)

### 9.2  Program Data

Program Data (f08pefe.d)

### 9.3  Program Results

Program Results (f08pefe.r)