F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08NEF (DGEHRD)

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.

## 1  Purpose

F08NEF (DGEHRD) reduces a real general matrix to Hessenberg form.

## 2  Specification

 SUBROUTINE F08NEF ( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO)
 INTEGER N, ILO, IHI, LDA, LWORK, INFO REAL (KIND=nag_wp) A(LDA,*), TAU(*), WORK(max(1,LWORK))
The routine may be called by its LAPACK name dgehrd.

## 3  Description

F08NEF (DGEHRD) reduces a real general matrix $A$ to upper Hessenberg form $H$ by an orthogonal similarity transformation: $A=QH{Q}^{\mathrm{T}}$.
The matrix $Q$ is not formed explicitly, but is represented as a product of elementary reflectors (see the F08 Chapter Introduction for details). Routines are provided to work with $Q$ in this representation (see Section 8).
The routine can take advantage of a previous call to F08NHF (DGEBAL), which may produce a matrix with the structure:
 $A11 A12 A13 A22 A23 A33$
where ${A}_{11}$ and ${A}_{33}$ are upper triangular. If so, only the central diagonal block ${A}_{22}$, in rows and columns ${i}_{\mathrm{lo}}$ to ${i}_{\mathrm{hi}}$, needs to be reduced to Hessenberg form (the blocks ${A}_{12}$ and ${A}_{23}$ will also be affected by the reduction). Therefore the values of ${i}_{\mathrm{lo}}$ and ${i}_{\mathrm{hi}}$ determined by F08NHF (DGEBAL) can be supplied to the routine directly. If F08NHF (DGEBAL) has not previously been called however, then ${i}_{\mathrm{lo}}$ must be set to $1$ and ${i}_{\mathrm{hi}}$ to $n$.

## 4  References

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

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{N}}\ge 0$.
2:     ILO – INTEGERInput
3:     IHI – INTEGERInput
On entry: if $A$ has been output 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.
Constraints:
• if ${\mathbf{N}}>0$, $1\le {\mathbf{ILO}}\le {\mathbf{IHI}}\le {\mathbf{N}}$;
• if ${\mathbf{N}}=0$, ${\mathbf{ILO}}=1$ and ${\mathbf{IHI}}=0$.
4:     A(LDA,$*$) – REAL (KIND=nag_wp) arrayInput/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 $n$ by $n$ general matrix $A$.
On exit: A is overwritten by the upper Hessenberg matrix $H$ and details of the orthogonal matrix $Q$.
5:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F08NEF (DGEHRD) is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
6:     TAU($*$) – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array TAU must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}-1\right)$.
On exit: further details of the orthogonal matrix $Q$.
7:     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.
8:     LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F08NEF (DGEHRD) is called.
If ${\mathbf{LWORK}}=-1$, 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.
Suggested value: for optimal performance, ${\mathbf{LWORK}}\ge {\mathbf{N}}×\mathit{nb}$, where $\mathit{nb}$ is the optimal block size.
Constraint: ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$ or ${\mathbf{LWORK}}=-1$.
9:     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.

## 7  Accuracy

The computed Hessenberg matrix $H$ is exactly similar to a nearby matrix $\left(A+E\right)$, where
 $E2 ≤ c n ε A2 ,$
$c\left(n\right)$ is a modestly increasing function of $n$, and $\epsilon$ is the machine precision.
The elements of $H$ themselves may be sensitive to small perturbations in $A$ or to rounding errors in the computation, but this does not affect the stability of the eigenvalues, eigenvectors or Schur factorization.

The total number of floating point operations is approximately $\frac{2}{3}{q}^{2}\left(2q+3n\right)$, where $q={i}_{\mathrm{hi}}-{i}_{\mathrm{lo}}$; if ${i}_{\mathrm{lo}}=1$ and ${i}_{\mathrm{hi}}=n$, the number is approximately $\frac{10}{3}{n}^{3}$.
To form the orthogonal matrix $Q$ F08NEF (DGEHRD) may be followed by a call to F08NFF (DORGHR):
```CALL DORGHR(N,ILO,IHI,A,LDA,TAU,WORK,LWORK,INFO)
```
To apply $Q$ to an $m$ by $n$ real matrix $C$ F08NEF (DGEHRD) may be followed by a call to F08NGF (DORMHR). For example,
```CALL DORMHR('Left','No Transpose',M,N,ILO,IHI,A,LDA,TAU,C,LDC, &
WORK,LWORK,INFO)
```
forms the matrix product $QC$.
The complex analogue of this routine is F08NSF (ZGEHRD).

## 9  Example

This example computes the upper Hessenberg form of the matrix $A$, where
 $A = 0.35 0.45 -0.14 -0.17 0.09 0.07 -0.54 0.35 -0.44 -0.33 -0.03 0.17 0.25 -0.32 -0.13 0.11 .$

### 9.1  Program Text

Program Text (f08nefe.f90)

### 9.2  Program Data

Program Data (f08nefe.d)

### 9.3  Program Results

Program Results (f08nefe.r)