# NAG Library Routine Document

## 1Purpose

f01rkf returns the first $\ell$ rows of the $n$ by $n$ unitary matrix ${P}^{\mathrm{H}}$, where $P$ is given as the product of Householder transformation matrices.
This routine is intended for use following f01rjf.

## 2Specification

Fortran Interface
 Subroutine f01rkf ( m, n, a, lda, work,
 Integer, Intent (In) :: m, n, nrowp, lda Integer, Intent (Inout) :: ifail Complex (Kind=nag_wp), Intent (In) :: theta(*) Complex (Kind=nag_wp), Intent (Inout) :: a(lda,*) Complex (Kind=nag_wp), Intent (Out) :: work(max(m-1,nrowp-m,1)) Character (1), Intent (In) :: wheret
#include <nagmk26.h>
 void f01rkf_ (const char *wheret, const Integer *m, const Integer *n, const Integer *nrowp, Complex a[], const Integer *lda, const Complex theta[], Complex work[], Integer *ifail, const Charlen length_wheret)

## 3Description

$P$ is assumed to be given by
 $P = Pm P m-1 ⋯ P1 ,$
where
 $Pk=I-γkukukH, uk= wk ζk 0 zk$
${\gamma }_{k}$ is a scalar for which $\mathrm{Re}\left({\gamma }_{k}\right)=1.0$, ${\zeta }_{k}$ is a real scalar, ${w}_{k}$ is a $\left(k-1\right)$ element vector and ${z}_{k}$ is an $\left(n-m\right)$ 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 ${\theta }_{k}$, given by
 $θk=ζk,Imγk,$
must be supplied either in ${\mathbf{a}}\left(k,k\right)$ or in ${\mathbf{theta}}\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 $\theta$ are to be found.
${\mathbf{wheret}}=\text{'I'}$ (In a)
The elements of $\theta$ are in a.
${\mathbf{wheret}}=\text{'S'}$ (Separate)
The elements of $\theta$ are separate from a, in theta.
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)$ – Complex (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 $\theta$.
On exit: the first nrowp rows of the array a are overwritten by the first nrowp rows of the $n$ by $n$ unitary matrix ${P}^{\mathrm{H}}$.
6:     $\mathbf{lda}$ – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f01rkf is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}},{\mathbf{nrowp}}\right)$.
7:     $\mathbf{theta}\left(*\right)$ – Complex (Kind=nag_wp) arrayInput
Note: the dimension of the array theta 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: if ${\mathbf{wheret}}=\text{'S'}$, the array theta must contain the elements of $\theta$. If ${\mathbf{theta}}\left(k\right)=0.0$, ${P}_{k}$ is assumed to be $I$, if ${\mathbf{theta}}\left(k\right)=\alpha$ and $\mathrm{Re}\left(\alpha \right)<0.0$, ${P}_{k}$ is assumed to be of the form
 $Pk= I 0 0 0 α 0 0 0 I ,$
otherwise ${\mathbf{theta}}\left(k\right)$ is assumed to contain ${\theta }_{k}$ given by
 $θk=ζk,Imγk.$
If ${\mathbf{wheret}}=\text{'I'}$, the array theta 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)$ – Complex (Kind=nag_wp) arrayWorkspace
9:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . 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  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  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{lda}}=〈\mathit{\text{value}}〉$, ${\mathbf{m}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nrowp}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{nrowp}}\right)$.
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 0$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge {\mathbf{m}}$.
On entry, ${\mathbf{nrowp}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nrowp}}\ge 0$ and ${\mathbf{nrowp}}\le {\mathbf{n}}$.
On entry, ${\mathbf{wheret}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{wheret}}=\text{'I'}$ or $\text{'S'}$.
${\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 unitary matrix and
 $E≤cε,$
where $\epsilon$ the machine precision (see x02ajf), $c$ is a modest function of $n$, and $‖.‖$ denotes the spectral (two) norm. See also Section 7 in f01rjf.

## 8Parallelism and Performance

f01rkf 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
 $83n3n-m2ℓ-m-mℓ-m, if ​ℓ≥m, and ​ 83ℓ23n-ℓ, if ​ℓ

## 10Example

This example obtains the $5$ by $5$ unitary matrix $P$ following the $RQ$ factorization of the $3$ by $5$ matrix $A$ given by
 $A = -0.5i 0.4-0.3i 0.4i+0.0 0.3-0.4i 0.3i -0.5-1.5i 0.9-1.3i -0.4-0.4i 0.1-0.7i 0.3-0.3i -1.0-1.0i 0.2-1.4i 1.8i+0.0 0.0i+0.0 -2.4i .$

### 10.1Program Text

Program Text (f01rkfe.f90)

### 10.2Program Data

Program Data (f01rkfe.d)

### 10.3Program Results

Program Results (f01rkfe.r)