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_zgesvd (f08kp)

## Purpose

nag_lapack_zgesvd (f08kp) computes the singular value decomposition (SVD) of a complex m$m$ by n$n$ matrix A$A$, optionally computing the left and/or right singular vectors.

## Syntax

[a, s, u, vt, rwork, info] = f08kp(jobu, jobvt, a, 'm', m, 'n', n)
[a, s, u, vt, rwork, info] = nag_lapack_zgesvd(jobu, jobvt, a, 'm', m, 'n', n)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: rwork is now an output parameter
.

## Description

The SVD is written as
 A = UΣVH , $A = UΣVH ,$
where Σ$\Sigma$ is an m$m$ by n$n$ matrix which is zero except for its min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ diagonal elements, U$U$ is an m$m$ by m$m$ unitary matrix, and V$V$ is an n$n$ by n$n$ unitary matrix. The diagonal elements of Σ$\Sigma$ are the singular values of A$A$; they are real and non-negative, and are returned in descending order. The first min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of U$U$ and V$V$ are the left and right singular vectors of A$A$.
Note that the function returns VH${V}^{\mathrm{H}}$, not V$V$.

## 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:     jobu – string (length ≥ 1)
Specifies options for computing all or part of the matrix U$U$.
jobu = 'A'${\mathbf{jobu}}=\text{'A'}$
All m$m$ columns of U$U$ are returned in array u.
jobu = 'S'${\mathbf{jobu}}=\text{'S'}$
The first min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of U$U$ (the left singular vectors) are returned in the array u.
jobu = 'O'${\mathbf{jobu}}=\text{'O'}$
The first min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of U$U$ (the left singular vectors) are overwritten on the array a.
jobu = 'N'${\mathbf{jobu}}=\text{'N'}$
No columns of U$U$ (no left singular vectors) are computed.
Constraint: jobu = 'A'${\mathbf{jobu}}=\text{'A'}$, 'S'$\text{'S'}$, 'O'$\text{'O'}$ or 'N'$\text{'N'}$.
2:     jobvt – string (length ≥ 1)
Specifies options for computing all or part of the matrix VH${V}^{\mathrm{H}}$.
jobvt = 'A'${\mathbf{jobvt}}=\text{'A'}$
All n$n$ rows of VH${V}^{\mathrm{H}}$ are returned in the array vt.
jobvt = 'S'${\mathbf{jobvt}}=\text{'S'}$
The first min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of VH${V}^{\mathrm{H}}$ (the right singular vectors) are returned in the array vt.
jobvt = 'O'${\mathbf{jobvt}}=\text{'O'}$
The first min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of VH${V}^{\mathrm{H}}$ (the right singular vectors) are overwritten on the array a.
jobvt = 'N'${\mathbf{jobvt}}=\text{'N'}$
No rows of VH${V}^{\mathrm{H}}$ (no right singular vectors) are computed.
Constraints:
• jobvt = 'A'${\mathbf{jobvt}}=\text{'A'}$, 'S'$\text{'S'}$, 'O'$\text{'O'}$ or 'N'$\text{'N'}$;
• jobvt and jobu cannot both be 'O'$\text{'O'}$.
3:     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$.

### 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 ldu ldvt work lwork

### 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 jobu = 'O'${\mathbf{jobu}}=\text{'O'}$, a is overwritten with the first min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of U$U$ (the left singular vectors, stored column-wise).
If jobvt = 'O'${\mathbf{jobvt}}=\text{'O'}$, a is overwritten with the first min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of VH${V}^{\mathrm{H}}$ (the right singular vectors, stored row-wise).
If jobu'O'${\mathbf{jobu}}\ne \text{'O'}$ and jobvt'O'${\mathbf{jobvt}}\ne \text{'O'}$, the contents of a are destroyed.
2:     s( : $:$) – double array
Note: the dimension of the array s 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)$.
The singular values of A$A$, sorted so that s(i)s(i + 1)${\mathbf{s}}\left(i\right)\ge {\mathbf{s}}\left(i+1\right)$.
3:     u(ldu, : $:$) – complex array
The first dimension, ldu, of the array u will be
• if jobu = 'A'${\mathbf{jobu}}=\text{'A'}$ or 'S'$\text{'S'}$, ldu max (1,m) $\mathit{ldu}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• otherwise ldu1$\mathit{ldu}\ge 1$.
The second dimension of the array will be max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ if jobu = 'A'${\mathbf{jobu}}=\text{'A'}$, 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)$ if jobu = 'S'${\mathbf{jobu}}=\text{'S'}$, and at least 1$1$ otherwise
If jobu = 'A'${\mathbf{jobu}}=\text{'A'}$, u contains the m$m$ by m$m$ unitary matrix U$U$.
If jobu = 'S'${\mathbf{jobu}}=\text{'S'}$, u contains the first min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of U$U$ (the left singular vectors, stored column-wise).
If jobu = 'N'${\mathbf{jobu}}=\text{'N'}$ or 'O'$\text{'O'}$, u is not referenced.
4:     vt(ldvt, : $:$) – complex array
The first dimension, ldvt, of the array vt will be
• if jobvt = 'A'${\mathbf{jobvt}}=\text{'A'}$, ldvt max (1,n) $\mathit{ldvt}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if jobvt = 'S'${\mathbf{jobvt}}=\text{'S'}$, ldvt max (1,min (m,n)) $\mathit{ldvt}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{n}}\right)\right)$;
• otherwise ldvt1$\mathit{ldvt}\ge 1$.
The second dimension of the array will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if jobvt = 'A'${\mathbf{jobvt}}=\text{'A'}$ or 'S'$\text{'S'}$, and at least 1$1$ otherwise
If jobvt = 'A'${\mathbf{jobvt}}=\text{'A'}$, vt contains the n$n$ by n$n$ unitary matrix VH${V}^{\mathrm{H}}$.
If jobvt = 'S'${\mathbf{jobvt}}=\text{'S'}$, vt contains the first min (m,n)$\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of VH${V}^{\mathrm{H}}$ (the right singular vectors, stored row-wise).
If jobvt = 'N'${\mathbf{jobvt}}=\text{'N'}$ or 'O'$\text{'O'}$, vt is not referenced.
5:     rwork( : $:$) – double array
Note: the dimension of the array rwork must be at least max (1, 5 × min (m,n) ) $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,5×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{n}}\right)\right)$.
If ${\mathbf{INFO}}>{\mathbf{0}}$, rwork(1 : min (m,n)1)${\mathbf{rwork}}\left(1:\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},{\mathbf{n}}\right)-1\right)$ contains the unconverged superdiagonal elements of an upper bidiagonal matrix B$B$ whose diagonal is in S$S$ (not necessarily sorted). B$B$ satisfies A = UBVH$A=UB{V}^{\mathrm{H}}$, so it has the same singular values as A$A$, and singular vectors related by U$U$ and VH${V}^{\mathrm{H}}$.
6:     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: jobu, 2: jobvt, 3: m, 4: n, 5: a, 6: lda, 7: s, 8: u, 9: ldu, 10: vt, 11: ldvt, 12: work, 13: lwork, 14: rwork, 15: 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.
INFO > 0${\mathbf{INFO}}>0$
If nag_lapack_zgesvd (f08kp) did not converge, info specifies how many superdiagonals of an intermediate bidiagonal form did not converge to zero. See the description of rwork above for details.

## Accuracy

The computed singular value decomposition is nearly the exact singular value decomposition for 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. In addition, the computed singular vectors are nearly orthogonal to working precision. See Section 4.9 of Anderson et al. (1999) for further details.

The total number of floating point operations is approximately proportional to mn2 $m{n}^{2}$ when m > n$m>n$ and m2n ${m}^{2}n$ otherwise.
The singular values are returned in descending order.
The real analogue of this function is nag_lapack_dgesvd (f08kb).

## Example

```function nag_lapack_zgesvd_example
jobu = 'Overwrite A by U';
jobvt = 'Singular vectors (V)';
a = [ 0.96 - 0.81i,  -0.03 + 0.96i,  -0.91 + 2.06i,  -0.05 + 0.41i;
-0.98 + 1.98i,  -1.2 + 0.19i,  -0.66 + 0.42i, ...
-0.81 + 0.56i;
0.62 - 0.46i,  1.01 + 0.02i,  0.63 - 0.17i,  -1.11 + 0.6i;
-0.37 + 0.38i,  0.19 - 0.54i,  -0.98 - 0.36i,  0.22 - 0.2i;
0.83 + 0.51i,  0.2 + 0.01i,  -0.17 - 0.46i,  1.47 + 1.59i;
1.08 - 0.28i,  0.2 - 0.12i,  -0.07 + 1.23i,  0.26 + 0.26i];
[aOut, s, u, vt, rwork, info] = nag_lapack_zgesvd(jobu, jobvt, a)
```
```

aOut =

-0.5634 + 0.0016i   0.2687 + 0.2749i  -0.2451 - 0.4657i  -0.3787 - 0.2987i
0.1205 - 0.6108i   0.2909 - 0.1085i  -0.4329 + 0.1758i   0.0182 + 0.0437i
-0.0816 + 0.1613i   0.1660 - 0.3885i   0.4667 - 0.3821i   0.0800 + 0.2276i
0.1441 - 0.1532i  -0.1984 + 0.1737i   0.0034 - 0.1555i  -0.2608 + 0.5382i
-0.2487 - 0.0926i  -0.6253 - 0.3304i  -0.2643 + 0.0194i  -0.1002 - 0.0140i
-0.3758 + 0.0793i   0.0307 + 0.0816i  -0.1266 - 0.1747i   0.4175 + 0.4058i

s =

3.9994
3.0003
1.9944
0.9995

u =

0.0000 + 0.0000i

vt =

-0.6971 + 0.0000i  -0.0867 - 0.3548i   0.0560 - 0.5400i  -0.1878 - 0.2253i
-0.2403 + 0.0000i  -0.0725 + 0.2336i   0.2477 + 0.5291i  -0.7026 - 0.2177i
0.5123 + 0.0000i   0.3030 + 0.1735i  -0.0678 - 0.5162i  -0.4418 - 0.3864i
0.4403 + 0.0000i  -0.5294 - 0.6361i   0.3027 + 0.0346i  -0.1667 - 0.0258i

rwork =

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

info =

0

```
```function f08kp_example
jobu = 'Overwrite A by U';
jobvt = 'Singular vectors (V)';
a = [ 0.96 - 0.81i,  -0.03 + 0.96i,  -0.91 + 2.06i,  -0.05 + 0.41i;
-0.98 + 1.98i,  -1.2 + 0.19i,  -0.66 + 0.42i, ...
-0.81 + 0.56i;
0.62 - 0.46i,  1.01 + 0.02i,  0.63 - 0.17i,  -1.11 + 0.6i;
-0.37 + 0.38i,  0.19 - 0.54i,  -0.98 - 0.36i,  0.22 - 0.2i;
0.83 + 0.51i,  0.2 + 0.01i,  -0.17 - 0.46i,  1.47 + 1.59i;
1.08 - 0.28i,  0.2 - 0.12i,  -0.07 + 1.23i,  0.26 + 0.26i];
[aOut, s, u, vt, rwork, info] = f08kp(jobu, jobvt, a)
```
```

aOut =

-0.5634 + 0.0016i   0.2687 + 0.2749i  -0.2451 - 0.4657i  -0.3787 - 0.2987i
0.1205 - 0.6108i   0.2909 - 0.1085i  -0.4329 + 0.1758i   0.0182 + 0.0437i
-0.0816 + 0.1613i   0.1660 - 0.3885i   0.4667 - 0.3821i   0.0800 + 0.2276i
0.1441 - 0.1532i  -0.1984 + 0.1737i   0.0034 - 0.1555i  -0.2608 + 0.5382i
-0.2487 - 0.0926i  -0.6253 - 0.3304i  -0.2643 + 0.0194i  -0.1002 - 0.0140i
-0.3758 + 0.0793i   0.0307 + 0.0816i  -0.1266 - 0.1747i   0.4175 + 0.4058i

s =

3.9994
3.0003
1.9944
0.9995

u =

0.0000 + 0.0000i

vt =

-0.6971 + 0.0000i  -0.0867 - 0.3548i   0.0560 - 0.5400i  -0.1878 - 0.2253i
-0.2403 + 0.0000i  -0.0725 + 0.2336i   0.2477 + 0.5291i  -0.7026 - 0.2177i
0.5123 + 0.0000i   0.3030 + 0.1735i  -0.0678 - 0.5162i  -0.4418 - 0.3864i
0.4403 + 0.0000i  -0.5294 - 0.6361i   0.3027 + 0.0346i  -0.1667 - 0.0258i

rwork =

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

info =

0

```