Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_lapack_dorghr (f08nf)

## Purpose

nag_lapack_dorghr (f08nf) generates the real orthogonal matrix $Q$ which was determined by nag_lapack_dgehrd (f08ne) when reducing a real general matrix $A$ to Hessenberg form.

## Syntax

[a, info] = f08nf(ilo, ihi, a, tau, 'n', n)
[a, info] = nag_lapack_dorghr(ilo, ihi, a, tau, 'n', n)

## Description

nag_lapack_dorghr (f08nf) is intended to be used following a call to nag_lapack_dgehrd (f08ne), which reduces a real general matrix $A$ to upper Hessenberg form $H$ by an orthogonal similarity transformation: $A=QH{Q}^{\mathrm{T}}$. nag_lapack_dgehrd (f08ne) 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 nag_lapack_dgebal (f08nh) when balancing the matrix; if the matrix has not been balanced, ${i}_{\mathrm{lo}}=1$ and ${i}_{\mathrm{hi}}=n$.
This function may be used to generate $Q$ explicitly as a square matrix. $Q$ has the structure:
 $Q = I 0 0 0 Q22 0 0 0 I$
where ${Q}_{22}$ occupies rows and columns ${i}_{\mathrm{lo}}$ to ${i}_{\mathrm{hi}}$.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{ilo}$int64int32nag_int scalar
2:     $\mathrm{ihi}$int64int32nag_int scalar
These must be the same arguments ilo and ihi, respectively, as supplied to nag_lapack_dgehrd (f08ne).
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$.
3:     $\mathrm{a}\left(\mathit{lda},:\right)$ – double array
The first dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The second dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
Details of the vectors which define the elementary reflectors, as returned by nag_lapack_dgehrd (f08ne).
4:     $\mathrm{tau}\left(:\right)$ – double array
The dimension of the array tau must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}-1\right)$
Further details of the elementary reflectors, as returned by nag_lapack_dgehrd (f08ne).

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the array a and the second dimension of the array a.
$n$, the order of the matrix $Q$.
Constraint: ${\mathbf{n}}\ge 0$.

### Output Parameters

1:     $\mathrm{a}\left(\mathit{lda},:\right)$ – double array
The first dimension of the array a will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The second dimension of the array a will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The $n$ by $n$ orthogonal matrix $Q$.
2:     $\mathrm{info}$int64int32nag_int scalar
${\mathbf{info}}=0$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

${\mathbf{info}}=-i$
If ${\mathbf{info}}=-i$, parameter $i$ had an illegal value on entry. The parameters are numbered as follows:
1: n, 2: ilo, 3: ihi, 4: a, 5: lda, 6: tau, 7: work, 8: lwork, 9: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.

## Accuracy

The computed matrix $Q$ differs from an exactly orthogonal matrix by a matrix $E$ such that
 $E2 = Oε ,$
where $\epsilon$ is the machine precision.

The total number of floating-point operations is approximately $\frac{4}{3}{q}^{3}$, where $q={i}_{\mathrm{hi}}-{i}_{\mathrm{lo}}$.
The complex analogue of this function is nag_lapack_zunghr (f08nt).

## Example

This example computes the Schur factorization 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 .$
Here $A$ is general and must first be reduced to Hessenberg form by nag_lapack_dgehrd (f08ne). The program then calls nag_lapack_dorghr (f08nf) to form $Q$, and passes this matrix to nag_lapack_dhseqr (f08pe) which computes the Schur factorization of $A$.
```function f08nf_example

fprintf('f08nf example results\n\n');

ilo = int64(1);
ihi = int64(4);
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];

% Reduce A to upper Hessenberg Form A = QHQ^T
[H, tau, info] = f08ne( ...
ilo, ihi, a);

% Form Q
[Q, info] = f08nf( ...
ilo, ihi, H, tau);

% Schur factorize H = Y*T*Y' and form Z = QY  A = QY*T*(QQY)'
job   = 'Schur form';
compz = 'Vectors';
[~, wr, wi, Z, info] = f08pe( ...
job, compz, ilo, ihi, H, Q);

w = wr + i*wi;
disp('Eigenvalues of A');
disp(w);

```
```f08nf example results

Eigenvalues of A
0.7995 + 0.0000i
-0.0994 + 0.4008i
-0.0994 - 0.4008i
-0.1007 + 0.0000i

```