f01 Chapter Contents
f01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_complex_qr (f01rcc)

## 1  Purpose

nag_complex_qr (f01rcc) finds the $QR$ factorization of the complex $m$ by $n$ matrix $A$, where $m\ge n$.

## 2  Specification

 #include #include
 void nag_complex_qr (Integer m, Integer n, Complex a[], Integer tda, Complex theta[], NagError *fail)

## 3  Description

The $m$ by $n$ matrix $A$ is factorized as
 $A = Q R 0 when ​ m > n A = QR when ​ m = n$
where $Q$ is an $m$ by $m$ unitary matrix and $R$ is an $n$ by $n$ upper triangular matrix with real diagonal elements.
The factorization is obtained by Householder's method. The $k$th transformation matrix, ${Q}_{k}$, which is used to introduce zeros into the $k$th column of $A$ is given in the form
 $Q k = I 0 0 T k ,$
 $T k = I - u k ukT ,$
 $u k = ζ k z k ,$
${\gamma }_{k}$ is a scalar for which ${\mathrm{Re}\gamma }_{k}=1.0$, ${\zeta }_{k}$ is a real scalar and ${z}_{k}$ is an $\left(m-k\right)$ element vector. ${\gamma }_{k}$, ${\zeta }_{k}$ and ${z}_{k}$ are chosen to annihilate the elements below the triangular part of $A$ and to make the diagonal elements real.
The scalar ${\gamma }_{k}$ and the vector ${u}_{k}$ are returned in the $\left(k-1\right)$th element of the array theta and in the $\left(k-1\right)$th column of a, such that ${\theta }_{k}$, given by
 $θ k = ζ k ,Im⁡ γ k ,$
is in ${\mathbf{theta}}\left[k-1\right]$ and the elements of ${z}_{k}$ are in ${\mathbf{a}}\left[\left(k\right)×{\mathbf{tda}}+k+1\right],\dots ,{\mathbf{a}}\left[\left(m-1\right)×{\mathbf{tda}}+k-1\right]$. The elements of $R$ are returned in the upper triangular part of $A$.
$Q$ is given by
 $Q = Q n Q n-1 ⋯ Q 1 H .$
A good background description to the $QR$ factorization is given in Dongarra et al. (1979).

## 4  References

Dongarra J J, Moler C B, Bunch J R and Stewart G W (1979) LINPACK Users' Guide SIAM, Philadelphia
Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford

## 5  Arguments

1:     mIntegerInput
On entry: $m$, the number of rows of $A$.
Constraint: ${\mathbf{m}}\ge {\mathbf{n}}$.
2:     nIntegerInput
On entry: $n$, the number of columns of $A$.
Constraints:
• ${\mathbf{n}}\ge 0$;
• when ${\mathbf{n}}=0$ then an immediate return is effected.
3:     a[${\mathbf{m}}×{\mathbf{tda}}$]ComplexInput/Output
On entry: the leading $m$ by $n$ part of the array a must contain the matrix to be factorized.
On exit: the $n$ by $n$ upper triangular part of a will contain the upper triangular matrix $R$, with the imaginary parts of the diagonal elements set to zero, and the $m$ by $n$ strictly lower triangular part of a will contain details of the factorization as described above.
4:     tdaIntegerInput
On entry: the stride separating matrix column elements in the array a.
Constraint: ${\mathbf{tda}}\ge {\mathbf{n}}$.
5:     theta[n]ComplexOutput
On exit: the scalar ${\theta }_{k}$ for the $k$th transformation. If ${T}_{k}=I$ then ${\mathbf{theta}}\left[k-1\right]=0.0$; if
 $T k = α 0 0 I Re⁡α < 0.0$
then ${\mathbf{theta}}\left[k-1\right]=\alpha$; otherwise ${\mathbf{theta}}\left[k-1\right]$ contains ${\mathbf{theta}}\left[k-1\right]$ as described in Section 3 and Re$\left({\mathbf{theta}}\left[k-1\right]\right)$ is always in the range $\left(1.0,\sqrt{2.0}\right)\text{.}$
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$ while ${\mathbf{n}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{m}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{tda}}=〈\mathit{\text{value}}〉$ while ${\mathbf{n}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{tda}}\ge {\mathbf{n}}$.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.

## 7  Accuracy

The computed factors $Q$ and $R$ satisfy the relation
 $Q R 0 = A + E$
where $‖E‖\le c\epsilon ‖A‖$, $\epsilon$ being the machine precision, $c$ is a modest function of $m$ and $n$ and $\text{.}$ denotes the spectral (two) norm.

## 8  Further Comments

The approximate number of real floating point operations is given by $8{n}^{2}\left(3m-n\right)/3$.
Following the use of this function the operations
 $B := QB and B := Q H B$
where $B$ is an $m$ by $k$ matrix, can be performed by calls to nag_complex_apply_q (f01rdc).
The operation $B:=QB$ can be obtained by the call:
and $B:={Q}^{H}B$ can be obtained by the call:
If $B$ is a one-dimensional array (single column) then the argument $tdb$ can be replaced by $1$. See nag_complex_apply_q (f01rdc) for further details.
The first $k$ columns of the unitary matrix $Q$ can either be obtained by setting $B$ to the first $k$ columns of the unit matrix and using the first of the above two calls, or by calling nag_complex_form_q (f01rec), which overwrites the $k$ columns of $Q$ on the first $k$ columns of the array a. $Q$ is obtained by the call:
If $k$ is larger than $n$, then $A$ must have been declared to have at least $k$ columns.

## 9  Example

To obtain the $QR$ factorization of the 5 by 3 matrix
 $A = 0.5 i -0.5 + 1.5 i -1.0 + 1.0 i 0.4 + 0.3 i - 0.9 + 1.3 i - 0.2 + 1.4 i 0.4 +0.3 i -0.4 + 0.4 i - 1.8 +1.4 i 0.3 - 0.4 i 0.1 + 0.7 i - 0.0 +0.3 i -0.3 i 0.3 + 0.3 i 2.4 i$

### 9.1  Program Text

Program Text (f01rcce.c)

### 9.2  Program Data

Program Data (f01rcce.d)

### 9.3  Program Results

Program Results (f01rcce.r)