# NAG Library Routine Document

## 1Purpose

f08kff (dorgbr) generates one of the real orthogonal matrices $Q$ or ${P}^{\mathrm{T}}$ which were determined by f08kef (dgebrd) when reducing a real matrix to bidiagonal form.

## 2Specification

Fortran Interface
 Subroutine f08kff ( vect, m, n, k, a, lda, tau, work, info)
 Integer, Intent (In) :: m, n, k, lda, lwork Integer, Intent (Out) :: info Real (Kind=nag_wp), Intent (In) :: tau(*) Real (Kind=nag_wp), Intent (Inout) :: a(lda,*) Real (Kind=nag_wp), Intent (Out) :: work(max(1,lwork)) Character (1), Intent (In) :: vect
#include <nagmk26.h>
 void f08kff_ (const char *vect, const Integer *m, const Integer *n, const Integer *k, double a[], const Integer *lda, const double tau[], double work[], const Integer *lwork, Integer *info, const Charlen length_vect)
The routine may be called by its LAPACK name dorgbr.

## 3Description

f08kff (dorgbr) is intended to be used after a call to f08kef (dgebrd), which reduces a real rectangular matrix $A$ to bidiagonal form $B$ by an orthogonal transformation: $A=QB{P}^{\mathrm{T}}$. f08kef (dgebrd) represents the matrices $Q$ and ${P}^{\mathrm{T}}$ as products of elementary reflectors.
This routine may be used to generate $Q$ or ${P}^{\mathrm{T}}$ explicitly as square matrices, or in some cases just the leading columns of $Q$ or the leading rows of ${P}^{\mathrm{T}}$.
The various possibilities are specified by the arguments vect, m, n and k. The appropriate values to cover the most likely cases are as follows (assuming that $A$ was an $m$ by $n$ matrix):
 1 To form the full $m$ by $m$ matrix $Q$: ```Call dorgbr('Q',m,m,n,...) ``` (note that the array a must have at least $m$ columns). 2 If $m>n$, to form the $n$ leading columns of $Q$: ```Call dorgbr('Q',m,n,n,...) ``` 3 To form the full $n$ by $n$ matrix ${P}^{\mathrm{T}}$: ```Call dorgbr('P',n,n,m,...) ``` (note that the array a must have at least $n$ rows). 4 If $m, to form the $m$ leading rows of ${P}^{\mathrm{T}}$: ```Call dorgbr('P',m,n,m,...) ```
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5Arguments

1:     $\mathbf{vect}$ – Character(1)Input
On entry: indicates whether the orthogonal matrix $Q$ or ${P}^{\mathrm{T}}$ is generated.
${\mathbf{vect}}=\text{'Q'}$
$Q$ is generated.
${\mathbf{vect}}=\text{'P'}$
${P}^{\mathrm{T}}$ is generated.
Constraint: ${\mathbf{vect}}=\text{'Q'}$ or $\text{'P'}$.
2:     $\mathbf{m}$ – IntegerInput
On entry: $m$, the number of rows of the orthogonal matrix $Q$ or ${P}^{\mathrm{T}}$ to be returned.
Constraint: ${\mathbf{m}}\ge 0$.
3:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of columns of the orthogonal matrix $Q$ or ${P}^{\mathrm{T}}$ to be returned.
Constraints:
• ${\mathbf{n}}\ge 0$;
• if ${\mathbf{vect}}=\text{'Q'}$ and ${\mathbf{m}}>{\mathbf{k}}$, ${\mathbf{m}}\ge {\mathbf{n}}\ge {\mathbf{k}}$;
• if ${\mathbf{vect}}=\text{'Q'}$ and ${\mathbf{m}}\le {\mathbf{k}}$, ${\mathbf{m}}={\mathbf{n}}$;
• if ${\mathbf{vect}}=\text{'P'}$ and ${\mathbf{n}}>{\mathbf{k}}$, ${\mathbf{n}}\ge {\mathbf{m}}\ge {\mathbf{k}}$;
• if ${\mathbf{vect}}=\text{'P'}$ and ${\mathbf{n}}\le {\mathbf{k}}$, ${\mathbf{n}}={\mathbf{m}}$.
4:     $\mathbf{k}$ – IntegerInput
On entry: if ${\mathbf{vect}}=\text{'Q'}$, the number of columns in the original matrix $A$.
If ${\mathbf{vect}}=\text{'P'}$, the number of rows in the original matrix $A$.
Constraint: ${\mathbf{k}}\ge 0$.
5:     $\mathbf{a}\left({\mathbf{lda}},*\right)$ – 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: details of the vectors which define the elementary reflectors, as returned by f08kef (dgebrd).
On exit: the orthogonal matrix $Q$ or ${P}^{\mathrm{T}}$, or the leading rows or columns thereof, as specified by vect, m and n.
6:     $\mathbf{lda}$ – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f08kff (dorgbr) is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
7:     $\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,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{k}}\right)\right)$ if ${\mathbf{vect}}=\text{'Q'}$ and at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},{\mathbf{k}}\right)\right)$ if ${\mathbf{vect}}=\text{'P'}$.
On entry: further details of the elementary reflectors, as returned by f08kef (dgebrd) in its argument tauq if ${\mathbf{vect}}=\text{'Q'}$, or in its argument taup if ${\mathbf{vect}}=\text{'P'}$.
8:     $\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.
9:     $\mathbf{lwork}$ – IntegerInput
On entry: the dimension of the array work as declared in the (sub)program from which f08kff (dorgbr) 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 \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{n}}\right)×\mathit{nb}$, where $\mathit{nb}$ is the optimal block size.
Constraint: ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{n}}\right)\right)$ or ${\mathbf{lwork}}=-1$.
10:   $\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 matrix $Q$ differs from an exactly orthogonal matrix by a matrix $E$ such that
 $E2 = Oε ,$
where $\epsilon$ is the machine precision. A similar statement holds for the computed matrix ${P}^{\mathrm{T}}$.

## 8Parallelism and Performance

f08kff (dorgbr) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f08kff (dorgbr) 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 for the cases listed in Section 3 are approximately as follows:
 1 To form the whole of $Q$: $\frac{4}{3}n\left(3{m}^{2}-3mn+{n}^{2}\right)$ if $m>n$,$\frac{4}{3}{m}^{3}$ if $m\le n$; 2 To form the $n$ leading columns of $Q$ when $m>n$: $\frac{2}{3}{n}^{2}\left(3m-n\right)$; 3 To form the whole of ${P}^{\mathrm{T}}$: $\frac{4}{3}{n}^{3}$ if $m\ge n$,$\frac{4}{3}m\left(3{n}^{2}-3mn+{m}^{2}\right)$ if $m; 4 To form the $m$ leading rows of ${P}^{\mathrm{T}}$ when $m: $\frac{2}{3}{m}^{2}\left(3n-m\right)$.
The complex analogue of this routine is f08ktf (zungbr).

## 10Example

For this routine two examples are presented, both of which involve computing the singular value decomposition of a matrix $A$, where
 $A = -0.57 -1.28 -0.39 0.25 -1.93 1.08 -0.31 -2.14 2.30 0.24 0.40 -0.35 -1.93 0.64 -0.66 0.08 0.15 0.30 0.15 -2.13 -0.02 1.03 -1.43 0.50$
in the first example and
 $A = -5.42 3.28 -3.68 0.27 2.06 0.46 -1.65 -3.40 -3.20 -1.03 -4.06 -0.01 -0.37 2.35 1.90 4.31 -1.76 1.13 -3.15 -0.11 1.99 -2.70 0.26 4.50$
in the second. $A$ must first be reduced to tridiagonal form by f08kef (dgebrd). The program then calls f08kff (dorgbr) twice to form $Q$ and ${P}^{\mathrm{T}}$, and passes these matrices to f08mef (dbdsqr), which computes the singular value decomposition of $A$.

### 10.1Program Text

Program Text (f08kffe.f90)

### 10.2Program Data

Program Data (f08kffe.d)

### 10.3Program Results

Program Results (f08kffe.r)