# NAG Library Function Document

## 1Purpose

nag_zunmqr (f08auc) multiplies an arbitrary complex matrix $C$ by the complex unitary matrix $Q$ from a $QR$ factorization computed by nag_zgeqrf (f08asc), nag_zgeqpf (f08bsc) or nag_zgeqp3 (f08btc).

## 2Specification

 #include #include
 void nag_zunmqr (Nag_OrderType order, Nag_SideType side, Nag_TransType trans, Integer m, Integer n, Integer k, const Complex a[], Integer pda, const Complex tau[], Complex c[], Integer pdc, NagError *fail)

## 3Description

nag_zunmqr (f08auc) is intended to be used after a call to nag_zgeqrf (f08asc), nag_zgeqpf (f08bsc) or nag_zgeqp3 (f08btc), which perform a $QR$ factorization of a complex matrix $A$. The unitary matrix $Q$ is represented as a product of elementary reflectors.
This function may be used to form one of the matrix products
 $QC , QHC , CQ ​ or ​ CQH ,$
overwriting the result on ${\mathbf{c}}$ (which may be any complex rectangular matrix).
A common application of this function is in solving linear least squares problems, as described in the f08 Chapter Introduction and illustrated in Section 10 in nag_zgeqrf (f08asc).

## 4References

Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5Arguments

1:    $\mathbf{order}$Nag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2:    $\mathbf{side}$Nag_SideTypeInput
On entry: indicates how $Q$ or ${Q}^{\mathrm{H}}$ is to be applied to $C$.
${\mathbf{side}}=\mathrm{Nag_LeftSide}$
$Q$ or ${Q}^{\mathrm{H}}$ is applied to $C$ from the left.
${\mathbf{side}}=\mathrm{Nag_RightSide}$
$Q$ or ${Q}^{\mathrm{H}}$ is applied to $C$ from the right.
Constraint: ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_RightSide}$.
3:    $\mathbf{trans}$Nag_TransTypeInput
On entry: indicates whether $Q$ or ${Q}^{\mathrm{H}}$ is to be applied to $C$.
${\mathbf{trans}}=\mathrm{Nag_NoTrans}$
$Q$ is applied to $C$.
${\mathbf{trans}}=\mathrm{Nag_ConjTrans}$
${Q}^{\mathrm{H}}$ is applied to $C$.
Constraint: ${\mathbf{trans}}=\mathrm{Nag_NoTrans}$ or $\mathrm{Nag_ConjTrans}$.
4:    $\mathbf{m}$IntegerInput
On entry: $m$, the number of rows of the matrix $C$.
Constraint: ${\mathbf{m}}\ge 0$.
5:    $\mathbf{n}$IntegerInput
On entry: $n$, the number of columns of the matrix $C$.
Constraint: ${\mathbf{n}}\ge 0$.
6:    $\mathbf{k}$IntegerInput
On entry: $k$, the number of elementary reflectors whose product defines the matrix $Q$.
Constraints:
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{m}}\ge {\mathbf{k}}\ge 0$;
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{n}}\ge {\mathbf{k}}\ge 0$.
7:    $\mathbf{a}\left[\mathit{dim}\right]$const ComplexInput
Note: the dimension, dim, of the array a must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pda}}×{\mathbf{k}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}×{\mathbf{pda}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ and ${\mathbf{side}}=\mathrm{Nag_LeftSide}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×{\mathbf{pda}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ and ${\mathbf{side}}=\mathrm{Nag_RightSide}$.
On entry: details of the vectors which define the elementary reflectors, as returned by nag_zgeqrf (f08asc), nag_zgeqpf (f08bsc) or nag_zgeqp3 (f08btc).
8:    $\mathbf{pda}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array a.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{k}}\right)$.
9:    $\mathbf{tau}\left[\mathit{dim}\right]$const ComplexInput
Note: the dimension, dim, of the array tau must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{k}}\right)$.
On entry: further details of the elementary reflectors, as returned by nag_zgeqrf (f08asc), nag_zgeqpf (f08bsc) or nag_zgeqp3 (f08btc).
10:  $\mathbf{c}\left[\mathit{dim}\right]$ComplexInput/Output
Note: the dimension, dim, of the array c must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdc}}×{\mathbf{n}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}×{\mathbf{pdc}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
The $\left(i,j\right)$th element of the matrix $C$ is stored in
• ${\mathbf{c}}\left[\left(j-1\right)×{\mathbf{pdc}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{c}}\left[\left(i-1\right)×{\mathbf{pdc}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the $m$ by $n$ matrix $C$.
On exit: c is overwritten by $QC$ or ${Q}^{\mathrm{H}}C$ or $CQ$ or $C{Q}^{\mathrm{H}}$ as specified by side and trans.
11:  $\mathbf{pdc}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array c.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
12:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_ENUM_INT_3
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{m}}=〈\mathit{\text{value}}〉$, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{k}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{m}}\ge {\mathbf{k}}\ge 0$;
if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{n}}\ge {\mathbf{k}}\ge 0$.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{m}}=〈\mathit{\text{value}}〉$, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{pda}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
NE_INT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 0$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{pda}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pda}}>0$.
On entry, ${\mathbf{pdc}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdc}}>0$.
NE_INT_2
On entry, ${\mathbf{pda}}=〈\mathit{\text{value}}〉$ and ${\mathbf{k}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{k}}\right)$.
On entry, ${\mathbf{pdc}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
On entry, ${\mathbf{pdc}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

The computed result differs from the exact result by a matrix $E$ such that
 $E2 = Oε C2 ,$
where $\epsilon$ is the machine precision.

## 8Parallelism and Performance

nag_zunmqr (f08auc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_zunmqr (f08auc) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The total number of real floating-point operations is approximately $8nk\left(2m-k\right)$ if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ and $8mk\left(2n-k\right)$ if ${\mathbf{side}}=\mathrm{Nag_RightSide}$.