# NAG Library Routine Document

## 1Purpose

f08ngf (dormhr) multiplies an arbitrary real matrix $C$ by the real orthogonal matrix $Q$ which was determined by f08nef (dgehrd) when reducing a real general matrix to Hessenberg form.

## 2Specification

Fortran Interface
 Subroutine f08ngf ( side, m, n, ilo, ihi, a, lda, tau, c, ldc, work, info)
 Integer, Intent (In) :: m, n, ilo, ihi, lda, ldc, lwork Integer, Intent (Out) :: info Real (Kind=nag_wp), Intent (In) :: tau(*) Real (Kind=nag_wp), Intent (Inout) :: a(lda,*), c(ldc,*) Real (Kind=nag_wp), Intent (Out) :: work(max(1,lwork)) Character (1), Intent (In) :: side, trans
#include <nagmk26.h>
 void f08ngf_ (const char *side, const char *trans, const Integer *m, const Integer *n, const Integer *ilo, const Integer *ihi, double a[], const Integer *lda, const double tau[], double c[], const Integer *ldc, double work[], const Integer *lwork, Integer *info, const Charlen length_side, const Charlen length_trans)
The routine may be called by its LAPACK name dormhr.

## 3Description

f08ngf (dormhr) is intended to be used following a call to f08nef (dgehrd), which reduces a real general matrix $A$ to upper Hessenberg form $H$ by an orthogonal similarity transformation: $A=QH{Q}^{\mathrm{T}}$. f08nef (dgehrd) represents the matrix $Q$ as a product of ${i}_{\mathrm{hi}}-{i}_{\mathrm{lo}}$ elementary reflectors. Here ${i}_{\mathrm{lo}}$ and ${i}_{\mathrm{hi}}$ are values determined by f08nhf (dgebal) when balancing the matrix; if the matrix has not been balanced, ${i}_{\mathrm{lo}}=1$ and ${i}_{\mathrm{hi}}=n$.
This routine may be used to form one of the matrix products
 $QC , QTC , CQ ​ or ​ CQT ,$
overwriting the result on $C$ (which may be any real rectangular matrix).
A common application of this routine is to transform a matrix $V$ of eigenvectors of $H$ to the matrix $\mathit{QV}$ of eigenvectors of $A$.

## 4References

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

## 5Arguments

1:     $\mathbf{side}$ – Character(1)Input
On entry: indicates how $Q$ or ${Q}^{\mathrm{T}}$ is to be applied to $C$.
${\mathbf{side}}=\text{'L'}$
$Q$ or ${Q}^{\mathrm{T}}$ is applied to $C$ from the left.
${\mathbf{side}}=\text{'R'}$
$Q$ or ${Q}^{\mathrm{T}}$ is applied to $C$ from the right.
Constraint: ${\mathbf{side}}=\text{'L'}$ or $\text{'R'}$.
2:     $\mathbf{trans}$ – Character(1)Input
On entry: indicates whether $Q$ or ${Q}^{\mathrm{T}}$ is to be applied to $C$.
${\mathbf{trans}}=\text{'N'}$
$Q$ is applied to $C$.
${\mathbf{trans}}=\text{'T'}$
${Q}^{\mathrm{T}}$ is applied to $C$.
Constraint: ${\mathbf{trans}}=\text{'N'}$ or $\text{'T'}$.
3:     $\mathbf{m}$ – IntegerInput
On entry: $m$, the number of rows of the matrix $C$; $m$ is also the order of $Q$ if ${\mathbf{side}}=\text{'L'}$.
Constraint: ${\mathbf{m}}\ge 0$.
4:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of columns of the matrix $C$; $n$ is also the order of $Q$ if ${\mathbf{side}}=\text{'R'}$.
Constraint: ${\mathbf{n}}\ge 0$.
5:     $\mathbf{ilo}$ – IntegerInput
6:     $\mathbf{ihi}$ – IntegerInput
On entry: these must be the same arguments ilo and ihi, respectively, as supplied to f08nef (dgehrd).
Constraints:
• if ${\mathbf{side}}=\text{'L'}$ and ${\mathbf{m}}>0$, $1\le {\mathbf{ilo}}\le {\mathbf{ihi}}\le {\mathbf{m}}$;
• if ${\mathbf{side}}=\text{'L'}$ and ${\mathbf{m}}=0$, ${\mathbf{ilo}}=1$ and ${\mathbf{ihi}}=0$;
• if ${\mathbf{side}}=\text{'R'}$ and ${\mathbf{n}}>0$, $1\le {\mathbf{ilo}}\le {\mathbf{ihi}}\le {\mathbf{n}}$;
• if ${\mathbf{side}}=\text{'R'}$ and ${\mathbf{n}}=0$, ${\mathbf{ilo}}=1$ and ${\mathbf{ihi}}=0$.
7:     $\mathbf{a}\left({\mathbf{lda}},*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the second dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ if ${\mathbf{side}}=\text{'L'}$ and at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{side}}=\text{'R'}$.
On entry: details of the vectors which define the elementary reflectors, as returned by f08nef (dgehrd).
8:     $\mathbf{lda}$ – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f08ngf (dormhr) is called.
Constraints:
• if ${\mathbf{side}}=\text{'L'}$, ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• if ${\mathbf{side}}=\text{'R'}$, ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
9:     $\mathbf{tau}\left(*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array tau must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}-1\right)$ if ${\mathbf{side}}=\text{'L'}$ and at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}-1\right)$ if ${\mathbf{side}}=\text{'R'}$.
On entry: further details of the elementary reflectors, as returned by f08nef (dgehrd).
10:   $\mathbf{c}\left({\mathbf{ldc}},*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array c must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the $m$ by $n$ matrix $C$.
On exit: c is overwritten by $QC$ or ${Q}^{\mathrm{T}}C$ or $CQ$ or $C{Q}^{\mathrm{T}}$ as specified by side and trans.
11:   $\mathbf{ldc}$ – IntegerInput
On entry: the first dimension of the array c as declared in the (sub)program from which f08ngf (dormhr) is called.
Constraint: ${\mathbf{ldc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
12:   $\mathbf{work}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{lwork}}\right)\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:   $\mathbf{lwork}$ – IntegerInput
On entry: the dimension of the array work as declared in the (sub)program from which f08ngf (dormhr) 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}$ if ${\mathbf{side}}=\text{'L'}$ and at least ${\mathbf{m}}×\mathit{nb}$ if ${\mathbf{side}}=\text{'R'}$, where $\mathit{nb}$ is the optimal block size.
Constraints:
• if ${\mathbf{side}}=\text{'L'}$, ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ or ${\mathbf{lwork}}=-1$;
• if ${\mathbf{side}}=\text{'R'}$, ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ or ${\mathbf{lwork}}=-1$.
14:   $\mathbf{info}$ – IntegerOutput
On exit: ${\mathbf{info}}=0$ unless the routine detects an error (see Section 6).

## 6Error 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.

## 7Accuracy

The computed result differs from the exact result by a matrix $E$ such that
 $E2 = Oε C2 ,$
where $\epsilon$ is the machine precision.

## 8Parallelism and Performance

f08ngf (dormhr) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f08ngf (dormhr) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The total number of floating-point operations is approximately $2n{q}^{2}$ if ${\mathbf{side}}=\text{'L'}$ and $2m{q}^{2}$ if ${\mathbf{side}}=\text{'R'}$, where $q={i}_{\mathrm{hi}}-{i}_{\mathrm{lo}}$.
The complex analogue of this routine is f08nuf (zunmhr).

## 10Example

This example computes all the eigenvalues 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 ,$
and those eigenvectors which correspond to eigenvalues $\lambda$ such that $\mathrm{Re}\left(\lambda \right)<0$. Here $A$ is general and must first be reduced to upper Hessenberg form $H$ by f08nef (dgehrd). The program then calls f08pef (dhseqr) to compute the eigenvalues, and f08pkf (dhsein) to compute the required eigenvectors of $H$ by inverse iteration. Finally f08ngf (dormhr) is called to transform the eigenvectors of $H$ back to eigenvectors of the original matrix $A$.

### 10.1Program Text

Program Text (f08ngfe.f90)

### 10.2Program Data

Program Data (f08ngfe.d)

### 10.3Program Results

Program Results (f08ngfe.r)