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_dorgrq (f08cj)

## Purpose

nag_lapack_dorgrq (f08cj) generates all or part of the real n$n$ by n$n$ orthogonal matrix Q$Q$ from an RQ$RQ$ factorization computed by nag_lapack_dgerqf (f08ch).

## Syntax

[a, info] = f08cj(a, tau, 'm', m, 'n', n, 'k', k)
[a, info] = nag_lapack_dorgrq(a, tau, 'm', m, 'n', n, 'k', k)

## Description

nag_lapack_dorgrq (f08cj) is intended to be used following a call to nag_lapack_dgerqf (f08ch), which performs an RQ$RQ$ factorization of a real matrix A$A$ and represents the orthogonal matrix Q$Q$ as a product of k$k$ elementary reflectors of order n$n$.
This function may be used to generate Q$Q$ explicitly as a square matrix, or to form only its trailing rows.
Usually Q$Q$ is determined from the RQ$RQ$ factorization of a p$p$ by n$n$ matrix A$A$ with pn$p\le n$. The whole of Q$Q$ may be computed by:
```[a, info] = f08cj(a, tau);
```
(note that the matrix A$A$ must have at least n$n$ rows), or its trailing p$p$ rows as:
```[a, info] = f08cj(a(1:p,:), tau, 'k', p);
```
The rows of Q$Q$ returned by the last call form an orthonormal basis for the space spanned by the rows of A$A$; thus nag_lapack_dgerqf (f08ch) followed by nag_lapack_dorgrq (f08cj) can be used to orthogonalize the rows of A$A$.
The information returned by nag_lapack_dgerqf (f08ch) also yields the RQ$RQ$ factorization of the trailing k$k$ rows of A$A$, where k < p$k. The orthogonal matrix arising from this factorization can be computed by:
```[a, info] = f08cj(a, tau, 'k', k);
```
or its leading k$k$ columns by:
```[a, info] = f08cj(a(1:k,:), tau, 'k', k);
```

## References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia http://www.netlib.org/lapack/lug
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## Parameters

### Compulsory Input Parameters

1:     a(lda, : $:$) – double array
The first dimension of the array a must be at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The second dimension of the array must be at least max (1,n)$\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_dgerqf (f08ch).
2:     tau( : $:$) – double array
Note: the dimension of the array tau must be at least max (1,k)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{k}}\right)$.
tau(i)${\mathbf{tau}}\left(i\right)$ must contain the scalar factor of the elementary reflector Hi${H}_{i}$, as returned by nag_lapack_dgerqf (f08ch).

### Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The first dimension of the array a.
m$m$, the number of rows of the matrix Q$Q$.
Constraint: m0${\mathbf{m}}\ge 0$.
2:     n – int64int32nag_int scalar
Default: The second dimension of the array a.
n$n$, the number of columns of the matrix Q$Q$.
Constraint: nm${\mathbf{n}}\ge {\mathbf{m}}$.
3:     k – int64int32nag_int scalar
Default: The dimension of the array tau.
k$k$, the number of elementary reflectors whose product defines the matrix Q$Q$.
Constraint: mk0${\mathbf{m}}\ge {\mathbf{k}}\ge 0$.

lda work lwork

### Output Parameters

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

## Error Indicators and Warnings

info = i${\mathbf{info}}=-i$
If info = i${\mathbf{info}}=-i$, parameter i$i$ had an illegal value on entry. The parameters are numbered as follows:
1: m, 2: n, 3: k, 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$Q$ differs from an exactly orthogonal matrix by a matrix E$E$ such that
 ‖E‖2 = Oε $‖E‖2 = O⁡ε$
and ε$\epsilon$ is the machine precision.

The total number of floating point operations is approximately 4mnk2(m + n)k2 + (4/3)k3$4mnk-2\left(m+n\right){k}^{2}+\frac{4}{3}{k}^{3}$; when m = k$m=k$ this becomes (2/3)m2(3nm)$\frac{2}{3}{m}^{2}\left(3n-m\right)$.
The complex analogue of this function is nag_lapack_zungrq (f08cw).

## Example

```function nag_lapack_dorgrq_example
a = [-0.2536561223671959, -0.09569528025093453, -2.894845895288455,  ...
-0.5041099118295458, 1.921275206091976, -0.8729501828758776;
-0.7751853859846198, 0.2275943648113135, 0.2084279305583289,  ...
-1.581266529610948, -1.053208461749375, 0.9018026937371963;
0.1094532397645297, 0.5121810603924651, -0.0952450839256265,  ...
0.2476000680518517, 1.692758571755385, 0.213935545781127;
0.06960714430288747, -0.5958371552327169, -0.09745000202404246,  ...
0.02227428617692399, -0.5930528694606012, -3.091585353827385];
tau = [1.863066450840819;
1.179138368141079;
1.487335114645626;
1.16172932097152];
[aOut, info] = nag_lapack_dorgrq(a, tau)
```
```

aOut =

-0.0833    0.2972   -0.6404    0.4461   -0.2938   -0.4575
0.9100   -0.1080   -0.2351   -0.1620    0.2022   -0.1946
-0.2202   -0.2706    0.2220   -0.3866    0.0015   -0.8243
-0.0809    0.6922    0.1132   -0.0259    0.6890   -0.1617

info =

0

```
```function f08cj_example
a = [-0.2536561223671959, -0.09569528025093453, -2.894845895288455,  ...
-0.5041099118295458, 1.921275206091976, -0.8729501828758776;
-0.7751853859846198, 0.2275943648113135, 0.2084279305583289,  ...
-1.581266529610948, -1.053208461749375, 0.9018026937371963;
0.1094532397645297, 0.5121810603924651, -0.0952450839256265,  ...
0.2476000680518517, 1.692758571755385, 0.213935545781127;
0.06960714430288747, -0.5958371552327169, -0.09745000202404246,  ...
0.02227428617692399, -0.5930528694606012, -3.091585353827385];
tau = [1.863066450840819;
1.179138368141079;
1.487335114645626;
1.16172932097152];
[aOut, info] = f08cj(a, tau)
```
```

aOut =

-0.0833    0.2972   -0.6404    0.4461   -0.2938   -0.4575
0.9100   -0.1080   -0.2351   -0.1620    0.2022   -0.1946
-0.2202   -0.2706    0.2220   -0.3866    0.0015   -0.8243
-0.0809    0.6922    0.1132   -0.0259    0.6890   -0.1617

info =

0

```