# NAG Library Routine Document

## 1Purpose

f01qkf returns the first $\ell$ rows of the real $n$ by $n$ orthogonal matrix ${P}^{\mathrm{T}}$, where $P$ is given as the product of Householder transformation matrices.
This routine is intended for use following f01qjf.

## 2Specification

Fortran Interface
 Subroutine f01qkf ( m, n, a, lda, zeta, work,
 Integer, Intent (In) :: m, n, nrowp, lda Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: zeta(*) Real (Kind=nag_wp), Intent (Inout) :: a(lda,*) Real (Kind=nag_wp), Intent (Out) :: work(max(m-1,nrowp-m,1)) Character (1), Intent (In) :: wheret
#include nagmk26.h
 void f01qkf_ (const char *wheret, const Integer *m, const Integer *n, const Integer *nrowp, double a[], const Integer *lda, const double zeta[], double work[], Integer *ifail, const Charlen length_wheret)

## 3Description

$P$ is assumed to be given by
 $P=PmPm-1⋯P1$
where
 $Pk = I - uk ukT , uk= wk ζk 0 zk ,$
${\zeta }_{k}$ is a scalar, ${w}_{k}$ is a ($k-1$) element vector and ${z}_{k}$ is an ($n-m$) element vector. ${w}_{k}$ must be supplied in the $k$th row of a in elements ${\mathbf{a}}\left(k,1\right),\dots ,{\mathbf{a}}\left(k,k-1\right)$. ${z}_{k}$ must be supplied in the $k$th row of a in elements ${\mathbf{a}}\left(k,m+1\right),\dots ,{\mathbf{a}}\left(k,n\right)$ and ${\zeta }_{k}$ must be supplied either in ${\mathbf{a}}\left(k,k\right)$ or in ${\mathbf{zeta}}\left(k\right)$, depending upon the argument wheret.

## 4References

Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford

## 5Arguments

1:     $\mathbf{wheret}$ – Character(1)Input
On entry: indicates where the elements of $\zeta$ are to be found.
${\mathbf{wheret}}=\text{'I'}$ (In a)
The elements of $\zeta$ are in a.
${\mathbf{wheret}}=\text{'S'}$ (Separate)
The elements of $\zeta$ are separate from a, in zeta.
Constraint: ${\mathbf{wheret}}=\text{'I'}$ or $\text{'S'}$.
2:     $\mathbf{m}$ – IntegerInput
On entry: $m$, the number of rows of the matrix $A$.
Constraint: ${\mathbf{m}}\ge 0$.
3:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of columns of the matrix $A$.
Constraint: ${\mathbf{n}}\ge {\mathbf{m}}$.
4:     $\mathbf{nrowp}$ – IntegerInput
On entry: $\ell$, the required number of rows of $P$.
If ${\mathbf{nrowp}}=0$, an immediate return is effected.
Constraint: $0\le {\mathbf{nrowp}}\le {\mathbf{n}}$.
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: the leading $m$ by $m$ strictly lower triangular part of the array a, and the $m$ by $\left(n-m\right)$ rectangular part of a with top left-hand corner at element ${\mathbf{a}}\left(1,{\mathbf{m}}+1\right)$ must contain details of the matrix $P$. In addition, if ${\mathbf{wheret}}=\text{'I'}$, the diagonal elements of a must contain the elements of $\zeta$.
On exit: the first nrowp rows of the array a are overwritten by the first nrowp rows of the $n$ by $n$ orthogonal matrix ${P}^{\mathrm{T}}$.
6:     $\mathbf{lda}$ – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f01qkf is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}},{\mathbf{nrowp}}\right)$.
7:     $\mathbf{zeta}\left(*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array zeta must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ if ${\mathbf{wheret}}=\text{'S'}$, and at least $1$ otherwise.
On entry: with ${\mathbf{wheret}}=\text{'S'}$, the array zeta must contain the elements of $\zeta$. If ${\mathbf{zeta}}\left(k\right)=0.0$ then ${P}_{k}$ is assumed to be $I$, otherwise ${\mathbf{zeta}}\left(k\right)$ is assumed to contain ${\zeta }_{k}$.
When ${\mathbf{wheret}}=\text{'I'}$, the array zeta is not referenced.
8:     $\mathbf{work}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}}-1,{\mathbf{nrowp}}-{\mathbf{m}},1\right)\right)$ – Real (Kind=nag_wp) arrayWorkspace
Note: the dimension of the array work must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}}-1,{\mathbf{nrowp}}-{\mathbf{m}},1\right)$.
9:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=-1$
 On entry, ${\mathbf{wheret}}\ne \text{'I'}$ or $\text{'S'}$, or ${\mathbf{m}}<0$, or ${\mathbf{n}}<{\mathbf{m}}$, or ${\mathbf{nrowp}}<0$ or ${\mathbf{nrowp}}>{\mathbf{n}}$, or ${\mathbf{lda}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{nrowp}}\right)$.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

The computed matrix $P$ satisfies the relation
 $P=Q+E,$
where $Q$ is an exactly orthogonal matrix and
 $E≤cε,$
$\epsilon$ is the machine precision (see x02ajf), $c$ is a modest function of $n$, and $‖.‖$ denotes the spectral (two) norm. See also Section 7 in f01qjf.

## 8Parallelism and Performance

f01qkf 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 approximate number of floating-point operations is given by
 $23m3n-m2ℓ-m-mℓ-m, if ​ℓ≥m, and ​ 23ℓ23n-ℓ, if ​ℓ

## 10Example

This example obtains the $5$ by $5$ orthogonal matrix $P$ following the $RQ$ factorization of the $3$ by $5$ matrix $A$ given by
 $A= 2.0 2.0 1.6 2.0 1.2 2.5 2.5 -0.4 -0.5 -0.3 2.5 2.5 2.8 0.5 -2.9 .$

### 10.1Program Text

Program Text (f01qkfe.f90)

### 10.2Program Data

Program Data (f01qkfe.d)

### 10.3Program Results

Program Results (f01qkfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017