F01 Chapter Contents
F01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF01RJF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

F01RJF finds the $RQ$ factorization of the complex $m$ by $n$ ($m\le n$), matrix $A$, so that $A$ is reduced to upper triangular form by means of unitary transformations from the right.

## 2  Specification

 SUBROUTINE F01RJF ( M, N, A, LDA, THETA, IFAIL)
 INTEGER M, N, LDA, IFAIL COMPLEX (KIND=nag_wp) A(LDA,*), THETA(M)

## 3  Description

The $m$ by $n$ matrix $A$ is factorized as
 $A= R 0 PH when ​m
where $P$ is an $n$ by $n$ unitary matrix and $R$ is an $m$ by $m$ upper triangular matrix.
$P$ is given as a sequence of Householder transformation matrices
 $P=Pm⋯P2P1,$
the $\left(m-k+1\right)$th transformation matrix, ${P}_{k}$, being used to introduce zeros into the $k$th row of $A$. ${P}_{k}$ has the form
 $Pk=I-γkukukH,$
where
 $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. ${\gamma }_{k}$ and ${u}_{k}$ are chosen to annihilate the elements in the $k$th row of $A$.
The scalar ${\gamma }_{k}$ and the vector ${u}_{k}$ are returned in the $k$th element of THETA and in the $k$th row of A, such that ${\theta }_{k}$, given by
 $θk=ζk,Imγk.$
is in ${\mathbf{THETA}}\left(k\right)$, the elements of ${w}_{k}$ are in ${\mathbf{A}}\left(k,1\right),\dots ,{\mathbf{A}}\left(k,k-1\right)$ and the elements of ${z}_{k}$ are in ${\mathbf{A}}\left(k,m+1\right),\dots ,{\mathbf{A}}\left(k,n\right)$. The elements of $R$ are returned in the upper triangular part of A.
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

## 5  Parameters

1:     M – INTEGERInput
On entry: $m$, the number of rows of the matrix $A$.
When ${\mathbf{M}}=0$ then an immediate return is effected.
Constraint: ${\mathbf{M}}\ge 0$.
2:     N – INTEGERInput
On entry: $n$, the number of columns of the matrix $A$.
Constraint: ${\mathbf{N}}\ge {\mathbf{M}}$.
3:     A(LDA,$*$) – 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 $n$ part of the array A must contain the matrix to be factorized.
On exit: the $m$ by $m$ upper triangular part of A will contain the upper triangular matrix $R$, and the $m$ by $m$ strictly lower triangular part of A and the $m$ by $\left(n-m\right)$ rectangular part of A to the right of the upper triangular part will contain details of the factorization as described in Section 3.
4:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F01RJF is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$.
5:     THETA(M) – COMPLEX (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{THETA}}\left(k\right)$ contains the scalar ${\theta }_{k}$ for the $\left(m-k+1\right)$th transformation. If ${P}_{k}=I$ then ${\mathbf{THETA}}\left(k\right)=0.0$; if
 $Tk= I 0 0 0 α 0 0 0 I , Reα<0.0$
then ${\mathbf{THETA}}\left(k\right)=\alpha$, otherwise ${\mathbf{THETA}}\left(k\right)$ contains ${\theta }_{k}$ as described in Section 3 and ${\theta }_{k}$ is always in the range $\left(1.0,\sqrt{2.0}\right)$.
6:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction 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 parameter, 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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{M}}<0$, or ${\mathbf{N}}<{\mathbf{M}}$, or ${\mathbf{LDA}}<{\mathbf{M}}$.

## 7  Accuracy

The computed factors $R$ and $P$ satisfy the relation
 $R0PH=A+E,$
where
 $E≤cε A,$
$\epsilon$ is the machine precision (see X02AJF), $c$ is a modest function of $m$ and $n$, and $‖.‖$ denotes the spectral (two) norm.

The approximate number of floating point operations is given by $8{m}^{2}\left(3n-m\right)/3$.
The first $k$ rows of the unitary matrix ${P}^{\mathrm{H}}$ can be obtained by calling F01RKF, which overwrites the $k$ rows of ${P}^{\mathrm{H}}$ on the first $k$ rows of the array A. ${P}^{\mathrm{H}}$ is obtained by the call:
```IFAIL = 0
CALL F01RKF('Separate',M,N,K,A,LDA,THETA,WORK,IFAIL)
```
$\mathrm{WORK}$ must be a $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(m-1,k-m,1\right)$ element array. If $\mathrm{K}$ is larger than $\mathrm{M}$, then A must have been declared to have at least $\mathrm{K}$ rows.
Operations involving the matrix $R$ can readily be performed by the Level 2 BLAS routines F06SFF (ZTRMV) and F06SJF (ZTRSV), (see Chapter F06), but note that no test for near singularity of $R$ is incorporated into F06SFF (ZTRMV). If $R$ is singular, or nearly singular then F02XUF can be used to determine the singular value decomposition of $R$.

## 9  Example

This example obtains the $RQ$ factorization of the $3$ by $5$ matrix
 $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 .$

### 9.1  Program Text

Program Text (f01rjfe.f90)

### 9.2  Program Data

Program Data (f01rjfe.d)

### 9.3  Program Results

Program Results (f01rjfe.r)
{"ft_lang_label":"__label__en","ft_lang_prob":0.71713597,"math_prob":0.99983233,"size":4183,"snap":"2023-40-2023-50","text_gpt3_token_len":1154,"char_repetition_ratio":0.110792056,"word_repetition_ratio":0.021136064,"special_character_ratio":0.24432226,"punctuation_ratio":0.13043478,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9999777,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-04T09:00:57Z\",\"WARC-Record-ID\":\"<urn:uuid:d1cd19c8-165a-49d2-8ed9-acf9dffc4e2f>\",\"Content-Length\":\"26011\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f8354226-ae61-4d2b-9aa3-25d4d885dca8>\",\"WARC-Concurrent-To\":\"<urn:uuid:2567c040-2df5-464a-a598-9d0bc4b549c5>\",\"WARC-IP-Address\":\"78.129.168.4\",\"WARC-Target-URI\":\"https://support.nag.com/numeric/nl/nagdoc_24/nagdoc_fl24/html/f01/f01rjf.html\",\"WARC-Payload-Digest\":\"sha1:XRW45L7MMETARGSXA5NRPKPBYBKU64EX\",\"WARC-Block-Digest\":\"sha1:LRUQHHUM7KSU3MECAKHHQJHZVY5EPFI5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100527.35_warc_CC-MAIN-20231204083733-20231204113733-00748.warc.gz\"}"}