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_eigen_complex_triang_svd (f02xu)

## Purpose

nag_eigen_complex_triang_svd (f02xu) returns all, or part, of the singular value decomposition of a complex upper triangular matrix.

## Syntax

[a, b, q, sv, rwork, ifail] = f02xu(a, b, wantq, wantp, 'n', n, 'ncolb', ncolb)
[a, b, q, sv, rwork, ifail] = nag_eigen_complex_triang_svd(a, b, wantq, wantp, 'n', n, 'ncolb', ncolb)

## Description

The $n$ by $n$ upper triangular matrix $R$ is factorized as
 $R=QSPH,$
where $Q$ and $P$ are $n$ by $n$ unitary matrices and $S$ is an $n$ by $n$ diagonal matrix with real non-negative diagonal elements, $s{v}_{1},s{v}_{2},\dots ,s{v}_{n}$, ordered such that
 $sv1≥sv2≥⋯≥svn≥0.$
The columns of $Q$ are the left-hand singular vectors of $R$, the diagonal elements of $S$ are the singular values of $R$ and the columns of $P$ are the right-hand singular vectors of $R$.
Either or both of $Q$ and ${P}^{\mathrm{H}}$ may be requested and the matrix $C$ given by
 $C=QHB,$
where $B$ is an $n$ by $\mathit{ncolb}$ given matrix, may also be requested.
nag_eigen_complex_triang_svd (f02xu) obtains the singular value decomposition by first reducing $R$ to bidiagonal form by means of Givens plane rotations and then using the $QR$ algorithm to obtain the singular value decomposition of the bidiagonal form.
Good background descriptions to the singular value decomposition are given in Dongarra et al. (1979), Hammarling (1985) and Wilkinson (1978).
Note that if $K$ is any unitary diagonal matrix so that
 $KKH=I,$
then
 $A=QKSPKH$
is also a singular value decomposition of $A$.

## References

Dongarra J J, Moler C B, Bunch J R and Stewart G W (1979) LINPACK Users' Guide SIAM, Philadelphia
Hammarling S (1985) The singular value decomposition in multivariate statistics SIGNUM Newsl. 20(3) 2–25
Wilkinson J H (1978) Singular Value Decomposition – Basic Aspects Numerical Software – Needs and Availability (ed D A H Jacobs) Academic Press

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{a}\left(\mathit{lda},:\right)$ – complex array
The first dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The second dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The leading $n$ by $n$ upper triangular part of the array a must contain the upper triangular matrix $R$.
2:     $\mathrm{b}\left(\mathit{ldb},:\right)$ – complex array
The first dimension, $\mathit{ldb}$, of the array b must satisfy
• if ${\mathbf{ncolb}}>0$, $\mathit{ldb}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise $\mathit{ldb}\ge 1$.
The second dimension of the array b must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncolb}}\right)$.
If ${\mathbf{ncolb}}>0$, the leading $n$ by $\mathit{ncolb}$ part of the array b must contain the matrix to be transformed.
3:     $\mathrm{wantq}$ – logical scalar
Must be true if the matrix $Q$ is required.
If ${\mathbf{wantq}}=\mathit{false}$ then the array q is not referenced.
4:     $\mathrm{wantp}$ – logical scalar
Must be true if the matrix ${P}^{\mathrm{H}}$ is required, in which case ${P}^{\mathrm{H}}$ is returned in the array a, otherwise wantp must be false.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the array a and the second dimension of the array a.
$n$, the order of the matrix $R$.
If ${\mathbf{n}}=0$, an immediate return is effected.
Constraint: ${\mathbf{n}}\ge 0$.
2:     $\mathrm{ncolb}$int64int32nag_int scalar
Default: the second dimension of the array b.
$\mathit{ncolb}$, the number of columns of the matrix $B$.
If ${\mathbf{ncolb}}=0$, the array b is not referenced.
Constraint: ${\mathbf{ncolb}}\ge 0$.

### Output Parameters

1:     $\mathrm{a}\left(\mathit{lda},:\right)$ – complex array
The first dimension of the array a will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The second dimension of the array a will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
If ${\mathbf{wantp}}=\mathit{true}$, the $n$ by $n$ part of a will contain the $n$ by $n$ unitary matrix ${P}^{\mathrm{H}}$, otherwise the $n$ by $n$ upper triangular part of a is used as internal workspace, but the strictly lower triangular part of a is not referenced.
2:     $\mathrm{b}\left(\mathit{ldb},:\right)$ – complex array
The first dimension, $\mathit{ldb}$, of the array b will be
• if ${\mathbf{ncolb}}>0$, $\mathit{ldb}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise $\mathit{ldb}=1$.
The second dimension of the array b will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncolb}}\right)$.
Stores the $n$ by $\mathit{ncolb}$ matrix ${Q}^{\mathrm{H}}B$.
3:     $\mathrm{q}\left(\mathit{ldq},:\right)$ – complex array
The first dimension, $\mathit{ldq}$, of the array q will be
• if ${\mathbf{wantq}}=\mathit{true}$, $\mathit{ldq}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise $\mathit{ldq}=1$.
The second dimension of the array q will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{wantq}}=\mathit{true}$ and $1$ otherwise.
If ${\mathbf{wantq}}=\mathit{true}$, the leading $n$ by $n$ part of the array q will contain the unitary matrix $Q$. Otherwise the array q is not referenced.
4:     $\mathrm{sv}\left({\mathbf{n}}\right)$ – double array
The $n$ diagonal elements of the matrix $S$.
5:     $\mathrm{rwork}\left(:\right)$ – double array
The dimension of the array rwork will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,2×\left({\mathbf{n}}-1\right)\right)$ if ${\mathbf{ncolb}}=0$ and ${\mathbf{wantq}}=\mathit{false}$ and ${\mathbf{wantp}}=\mathit{false}$, $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,3×\left({\mathbf{n}}-1\right)\right)$ if ${\mathbf{ncolb}}=0$ and ${\mathbf{wantq}}=\mathit{false}$ and ${\mathbf{wantp}}=\mathit{true}$ or ${\mathbf{ncolb}}>0$ and ${\mathbf{wantp}}=\mathit{false}$ or ${\mathbf{wantq}}=\mathit{true}$ and ${\mathbf{wantp}}=\mathit{false}$ and $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,5×\left({\mathbf{n}}-1\right)\right)$ otherwise
rwork(n) contains the total number of iterations taken by the $QR$ algorithm.
The rest of the array is used as workspace.
6:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

${\mathbf{ifail}}=-1$
 On entry, ${\mathbf{n}}<0$, or $\mathit{lda}<{\mathbf{n}}$, or ${\mathbf{ncolb}}<0$, or $\mathit{ldb}<{\mathbf{n}}$ and ${\mathbf{ncolb}}>0$, or $\mathit{ldq}<{\mathbf{n}}$ and ${\mathbf{wantq}}=\mathit{true}$
W  ${\mathbf{ifail}}>0$
The $QR$ algorithm has failed to converge in $50×{\mathbf{n}}$ iterations. In this case ${\mathbf{sv}}\left(1\right),{\mathbf{sv}}\left(2\right),\dots ,{\mathbf{sv}}\left({\mathbf{ifail}}\right)$ may not have been found correctly and the remaining singular values may not be the smallest. The matrix $R$ will nevertheless have been factorized as $R=QE{P}^{\mathrm{H}}$, where $E$ is a bidiagonal matrix with ${\mathbf{sv}}\left(1\right),{\mathbf{sv}}\left(2\right),\dots ,{\mathbf{sv}}\left(n\right)$ as the diagonal elements and ${\mathbf{rwork}}\left(1\right),{\mathbf{rwork}}\left(2\right),\dots ,{\mathbf{rwork}}\left(n-1\right)$ as the superdiagonal elements.
This failure is not likely to occur.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The computed factors $Q$, $S$ and $P$ satisfy the relation
 $QSPH=A+E,$
where
 $E≤cε A,$
$\epsilon$ is the machine precision, $c$ is a modest function of $n$ and $‖.‖$ denotes the spectral (two) norm. Note that $‖A‖=s{v}_{1}$.

For given values of ncolb, wantq and wantp, the number of floating-point operations required is approximately proportional to ${n}^{3}$.
>Following the use of nag_eigen_complex_triang_svd (f02xu) the rank of $R$ may be estimated as follows:
```tol = eps;
irank = 1;
while (irank <= numel(sv) && sv(irank) >= tol*sv(1) )
irank = irank + 1;
end```
returns the value $k$ in irank, where $k$ is the smallest integer for which ${\mathbf{sv}}\left(k\right)<\mathit{tol}×{\mathbf{sv}}\left(1\right)$, where $\mathit{tol}$ is typically the machine precision, so that irank is an estimate of the rank of $S$ and thus also of $R$.

## Example

This example finds the singular value decomposition of the $3$ by $3$ upper triangular matrix
 $A = 1 1+i 1+i 0 -2i+ -1-i 0 0i+ -3i+$
together with the vector ${Q}^{\mathrm{H}}b$ for the vector
 $b= 1+1i -1i+0 -1+1i .$
```function f02xu_example

fprintf('f02xu example results\n\n');

a = [ 1,       1 + 1i,  1 + 1i;
0 + 0i, -2 + 0i, -1 - 1i;
0 + 0i,  0 + 0i, -3 + 0i];
b = [ 1 + 1i; -1 + 0i; -1 + 1i];

wantq = true;
wantp = true;
[a, b, q, sv, rwork, ifail] = f02xu( ...
a, b, wantq, wantp);

fprintf('Singular value decomposition of A\n\n');

disp('Singular values');
disp(sv');
disp('Left-hand singular vectors, by column');
disp(q);
disp('Right-hand singular vectors, by column');
disp(ctranspose(a));
disp('Vector Q^H*B');
disp(transpose(b));

```
```f02xu example results

Singular value decomposition of A

Singular values
3.9263    2.0000    0.7641

Left-hand singular vectors, by column
-0.5005 + 0.0000i  -0.4529 + 0.0000i   0.7378 + 0.0000i
0.5152 - 0.1514i   0.1132 - 0.5661i   0.4190 - 0.4502i
0.4041 - 0.5457i   0.0000 + 0.6794i   0.2741 + 0.0468i

Right-hand singular vectors, by column
-0.1275 + 0.0000i  -0.2265 + 0.0000i   0.9656 + 0.0000i
-0.3899 + 0.2046i  -0.3397 + 0.7926i  -0.1311 + 0.2129i
-0.5289 + 0.7142i  -0.0000 - 0.4529i  -0.0698 - 0.0119i

Vector Q^H*B
-1.9656 - 0.7935i   0.1132 - 0.3397i   0.0915 + 0.6086i

```