Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_lapack_zgeqp3 (f08bt)

## Purpose

nag_lapack_zgeqp3 (f08bt) computes the QR$QR$ factorization, with column pivoting, of a complex m$m$ by n$n$ matrix.

## Syntax

[a, jpvt, tau, info] = f08bt(a, jpvt, 'm', m, 'n', n)
[a, jpvt, tau, info] = nag_lapack_zgeqp3(a, jpvt, 'm', m, 'n', n)

## Description

nag_lapack_zgeqp3 (f08bt) forms the QR$QR$ factorization, with column pivoting, of an arbitrary rectangular complex m$m$ by n$n$ matrix.
If mn$m\ge n$, the factorization is given by:
AP = Q
 ( R ) 0
,
$AP= Q R 0 ,$
where R$R$ is an n$n$ by n$n$ upper triangular matrix (with real diagonal elements), Q$Q$ is an m$m$ by m$m$ unitary matrix and P$P$ is an n$n$ by n$n$ permutation matrix. It is sometimes more convenient to write the factorization as
AP =
 ( Q1 Q2 )
 ( R ) 0
,
$AP= Q1 Q2 R 0 ,$
which reduces to
 AP = Q1 R , $AP= Q1 R ,$
where Q1${Q}_{1}$ consists of the first n$n$ columns of Q$Q$, and Q2${Q}_{2}$ the remaining mn$m-n$ columns.
If m < n$m, R$R$ is trapezoidal, and the factorization can be written
AP = Q
 ( R1 R2 )
,
$AP= Q R1 R2 ,$
where R1${R}_{1}$ is upper triangular and R2${R}_{2}$ is rectangular.
The matrix Q$Q$ is not formed explicitly but is represented as a product of min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ elementary reflectors (see the F08 Chapter Introduction for details). Functions are provided to work with Q$Q$ in this representation (see Section [Further Comments]).
Note also that for any k < n$k, the information returned in the first k$k$ columns of the array a represents a QR$QR$ factorization of the first k$k$ columns of the permuted matrix AP$AP$.
The function allows specified columns of A$A$ to be moved to the leading columns of AP$AP$ at the start of the factorization and fixed there. The remaining columns are free to be interchanged so that at the i$i$th stage the pivot column is chosen to be the column which maximizes the 2$2$-norm of elements i$i$ to m$m$ over columns i$i$ to n$n$.

## References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia http://www.netlib.org/lapack/lug
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## Parameters

### Compulsory Input Parameters

1:     a(lda, : $:$) – complex array
The first dimension of the array a must be at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The second dimension of the array must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The m$m$ by n$n$ matrix A$A$.
2:     jpvt( : $:$) – int64int32nag_int array
Note: the dimension of the array jpvt must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
If jpvt(j)0${\mathbf{jpvt}}\left(j\right)\ne 0$, then the j$j$ th column of A$A$ is moved to the beginning of AP$AP$ before the decomposition is computed and is fixed in place during the computation. Otherwise, the j$j$ th column of A$A$ is a free column (i.e., one which may be interchanged during the computation with any other free column).

### Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The first dimension of the array a.
m$m$, the number of rows of the matrix A$A$.
Constraint: m0${\mathbf{m}}\ge 0$.
2:     n – int64int32nag_int scalar
Default: The second dimension of the array a.
n$n$, the number of columns of the matrix A$A$.
Constraint: n0${\mathbf{n}}\ge 0$.

### Input Parameters Omitted from the MATLAB Interface

lda work lwork rwork

### Output Parameters

1:     a(lda, : $:$) – complex array
The first dimension of the array a will be max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The second dimension of the array will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
ldamax (1,m)$\mathit{lda}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
If mn$m\ge n$, the elements below the diagonal store details of the unitary matrix Q$Q$ and the upper triangle stores the corresponding elements of the n$n$ by n$n$ upper triangular matrix R$R$.
If m < n$m, the strictly lower triangular part stores details of the unitary matrix Q$Q$ and the remaining elements store the corresponding elements of the m$m$ by n$n$ upper trapezoidal matrix R$R$.
The diagonal elements of R$R$ are real.
2:     jpvt( : $:$) – int64int32nag_int array
Note: the dimension of the array jpvt must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
Details of the permutation matrix P$P$. More precisely, if jpvt(j) = k${\mathbf{jpvt}}\left(j\right)=k$, then the k$k$th column of A$A$ is moved to become the j$j$ th column of AP$AP$; in other words, the columns of AP$AP$ are the columns of A$A$ in the order jpvt(1),jpvt(2),,jpvt(n)${\mathbf{jpvt}}\left(1\right),{\mathbf{jpvt}}\left(2\right),\dots ,{\mathbf{jpvt}}\left(n\right)$.
3:     tau( : $:$) – complex array
Note: the dimension of the array tau must be at least max (1,min (m,n))$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{n}}\right)\right)$.
Further details of the unitary matrix Q$Q$.
4:     info – int64int32nag_int scalar
info = 0${\mathbf{info}}=0$ unless the function detects an error (see Section [Error Indicators and Warnings]).

## Error Indicators and Warnings

info = i${\mathbf{info}}=-i$
If info = i${\mathbf{info}}=-i$, parameter i$i$ had an illegal value on entry. The parameters are numbered as follows:
1: m, 2: n, 3: a, 4: lda, 5: jpvt, 6: tau, 7: work, 8: lwork, 9: rwork, 10: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.

## Accuracy

The computed factorization is the exact factorization of a nearby matrix (A + E)$\left(A+E\right)$, where
 ‖E‖2 = O(ε) ‖A‖2 , $‖E‖2 = O(ε) ‖A‖2 ,$
and ε$\epsilon$ is the machine precision.

The total number of real floating point operations is approximately (8/3) n2 (3mn) $\frac{8}{3}{n}^{2}\left(3m-n\right)$ if mn$m\ge n$ or (8/3) m2 (3nm) $\frac{8}{3}{m}^{2}\left(3n-m\right)$ if m < n$m.
To form the unitary matrix Q$Q$ nag_lapack_zgeqp3 (f08bt) may be followed by a call to nag_lapack_zungqr (f08at):
```[a, info] = f08at(a(:,1:m), tau);
```
but note that the second dimension of the array a must be at least m, which may be larger than was required by nag_lapack_zgeqp3 (f08bt).
When mn$m\ge n$, it is often only the first n$n$ columns of Q$Q$ that are required, and they may be formed by the call:
```[a, info] = f08at(a, tau);
```
To apply Q$Q$ to an arbitrary complex rectangular matrix C$C$, nag_lapack_zgeqp3 (f08bt) may be followed by a call to nag_lapack_zunmqr (f08au). For example,
```[c, info] = f08au('Left','Conjugate Transpose', a(:,min(m,n)), tau, c);
```
forms C = QHC$C={Q}^{\mathrm{H}}C$, where C$C$ is m$m$ by p$p$.
To compute a QR$QR$ factorization without column pivoting, use nag_lapack_zgeqrf (f08as).
The real analogue of this function is nag_lapack_dgeqp3 (f08bf).

## Example

```function nag_lapack_zgeqp3_example
a = [ 0.47 - 0.34i,  -0.4 + 0.54i,  0.6 + 0.01i,  0.8 - 1.02i;
-0.32 - 0.23i,  -0.05 + 0.2i,  -0.26 - 0.44i,  -0.43 + 0.17i;
0.35 - 0.6i,  -0.52 - 0.34i,  0.87 - 0.11i,  -0.34 - 0.09i;
0.89 + 0.71i,  -0.45 - 0.45i,  -0.02 - 0.57i,  1.14 - 0.78i;
-0.19 + 0.06i,  0.11 - 0.85i,  1.44 + 0.8i,  0.07 + 1.14i];

b = [ -1.08 - 2.59i,  2.22 + 2.35i;
-2.61 - 1.49i,  1.62 - 1.48i;
3.13 - 3.61i,  1.65 + 3.43i;
7.33 - 8.01i,  -0.98 + 3.08i;
9.12 + 7.63i,  -2.84 + 2.78i];

jpvt = [int64(0);0;0;0];

% Compute the QR factorization of a
[a, jpvt, tau, info] = nag_lapack_zgeqp3(a, jpvt);

% Compute C = (C1) = (Q^H)*b, storing the result in c
%             (C2)
[c, info] = nag_lapack_zunmqr('Left', 'Conjugate Transpose', a, tau, b);

% Choose tol to reflect the relative accuracy of the input data
tol = 0.01;

% Determine and print the rank, k, of r relative to tol
k = find(abs(diag(a)) <= tol*abs(a(1,1)));
if numel(k) == 0
k = numel(diag(a));
else
k = k(1)-1;
end

fprintf('\nTolerance used to estimate the rank of a\n     %11.2e\n', tol);
fprintf('Estimated rank of a\n        %d\n', k);

% Compute least-squares solution by backsubstitution in r(1:k, 1:k)*c = c1
c1 = zeros(5, 2);
c1(1:k, :) = inv(triu(a(1:k,1:k)))*c(1:k,:);

% Compute estimates of the square roots of the residual sums of
% squares (2-norm of each of the columns of C2)
rnorm = [norm(c(k+1:5,1)), norm(c(k+1:5,2))];

% Permute the least-squares solutions stored in c1 to give x = p*y
x = zeros(4, 2);
for i=1:4
x(jpvt(i), :) = c1(i, :);
end
fprintf('\nLeast-squares solution(s)\n');
disp(x);
fprintf('Square root(s) of the residual sum(s) of squares\n');
disp(rnorm);
```
```

Tolerance used to estimate the rank of a
1.00e-02
Estimated rank of a
3

Least-squares solution(s)
0.0000 + 0.0000i   0.0000 + 0.0000i
2.7020 + 8.0911i  -2.2682 - 2.9884i
2.8888 + 2.5012i   0.9779 + 1.3565i
2.7100 + 0.4791i  -1.3734 + 0.2212i

Square root(s) of the residual sum(s) of squares
0.2513    0.0810

```
```function f08bt_example
a = [ 0.47 - 0.34i,  -0.4 + 0.54i,  0.6 + 0.01i,  0.8 - 1.02i;
-0.32 - 0.23i,  -0.05 + 0.2i,  -0.26 - 0.44i,  -0.43 + 0.17i;
0.35 - 0.6i,  -0.52 - 0.34i,  0.87 - 0.11i,  -0.34 - 0.09i;
0.89 + 0.71i,  -0.45 - 0.45i,  -0.02 - 0.57i,  1.14 - 0.78i;
-0.19 + 0.06i,  0.11 - 0.85i,  1.44 + 0.8i,  0.07 + 1.14i];

b = [ -1.08 - 2.59i,  2.22 + 2.35i;
-2.61 - 1.49i,  1.62 - 1.48i;
3.13 - 3.61i,  1.65 + 3.43i;
7.33 - 8.01i,  -0.98 + 3.08i;
9.12 + 7.63i,  -2.84 + 2.78i];

jpvt = [int64(0);0;0;0];

% Compute the QR factorization of a
[a, jpvt, tau, info] = f08bt(a, jpvt);

% Compute C = (C1) = (Q^H)*b, storing the result in c
%             (C2)
[c, info] = f08au('Left', 'Conjugate Transpose', a, tau, b);

% Choose tol to reflect the relative accuracy of the input data
tol = 0.01;

% Determine and print the rank, k, of r relative to tol
k = find(abs(diag(a)) <= tol*abs(a(1,1)));
if numel(k) == 0
k = numel(diag(a));
else
k = k(1)-1;
end

fprintf('\nTolerance used to estimate the rank of a\n     %11.2e\n', tol);
fprintf('Estimated rank of a\n        %d\n', k);

% Compute least-squares solution by backsubstitution in r(1:k, 1:k)*c = c1
c1 = zeros(5, 2);
c1(1:k, :) = inv(triu(a(1:k,1:k)))*c(1:k,:);

% Compute estimates of the square roots of the residual sums of
% squares (2-norm of each of the columns of C2)
rnorm = [norm(c(k+1:5,1)), norm(c(k+1:5,2))];

% Permute the least-squares solutions stored in c1 to give x = p*y
x = zeros(4, 2);
for i=1:4
x(jpvt(i), :) = c1(i, :);
end
fprintf('\nLeast-squares solution(s)\n');
disp(x);
fprintf('Square root(s) of the residual sum(s) of squares\n');
disp(rnorm);
```
```

Tolerance used to estimate the rank of a
1.00e-02
Estimated rank of a
3

Least-squares solution(s)
0.0000 + 0.0000i   0.0000 + 0.0000i
2.7020 + 8.0911i  -2.2682 - 2.9884i
2.8888 + 2.5012i   0.9779 + 1.3565i
2.7100 + 0.4791i  -1.3734 + 0.2212i

Square root(s) of the residual sum(s) of squares
0.2513    0.0810

```