F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08KPF (ZGESVD)

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

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

## 2  Specification

 SUBROUTINE F08KPF ( JOBU, JOBVT, M, N, A, LDA, S, U, LDU, VT, LDVT, WORK, LWORK, RWORK, INFO)
 INTEGER M, N, LDA, LDU, LDVT, LWORK, INFO REAL (KIND=nag_wp) S(*), RWORK(*) COMPLEX (KIND=nag_wp) A(LDA,*), U(LDU,*), VT(LDVT,*), WORK(max(1,LWORK)) CHARACTER(1) JOBU, JOBVT
The routine may be called by its LAPACK name zgesvd.

## 3  Description

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

## 5  Parameters

1:     JOBU – CHARACTER(1)Input
On entry: specifies options for computing all or part of the matrix $U$.
${\mathbf{JOBU}}=\text{'A'}$
All $m$ columns of $U$ are returned in array U.
${\mathbf{JOBU}}=\text{'S'}$
The first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of $U$ (the left singular vectors) are returned in the array U.
${\mathbf{JOBU}}=\text{'O'}$
The first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of $U$ (the left singular vectors) are overwritten on the array A.
${\mathbf{JOBU}}=\text{'N'}$
No columns of $U$ (no left singular vectors) are computed.
Constraint: ${\mathbf{JOBU}}=\text{'A'}$, $\text{'S'}$, $\text{'O'}$ or $\text{'N'}$.
2:     JOBVT – CHARACTER(1)Input
On entry: specifies options for computing all or part of the matrix ${V}^{\mathrm{H}}$.
${\mathbf{JOBVT}}=\text{'A'}$
All $n$ rows of ${V}^{\mathrm{H}}$ are returned in the array VT.
${\mathbf{JOBVT}}=\text{'S'}$
The first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of ${V}^{\mathrm{H}}$ (the right singular vectors) are returned in the array VT.
${\mathbf{JOBVT}}=\text{'O'}$
The first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of ${V}^{\mathrm{H}}$ (the right singular vectors) are overwritten on the array A.
${\mathbf{JOBVT}}=\text{'N'}$
No rows of ${V}^{\mathrm{H}}$ (no right singular vectors) are computed.
Constraints:
• ${\mathbf{JOBVT}}=\text{'A'}$, $\text{'S'}$, $\text{'O'}$ or $\text{'N'}$;
• JOBVT and JOBU cannot both be $\text{'O'}$.
3:     M – INTEGERInput
On entry: $m$, the number of rows of the matrix $A$.
Constraint: ${\mathbf{M}}\ge 0$.
4:     N – INTEGERInput
On entry: $n$, the number of columns of the matrix $A$.
Constraint: ${\mathbf{N}}\ge 0$.
5:     A(LDA,$*$) – COMPLEX (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array A must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
On entry: the $m$ by $n$ matrix $A$.
On exit: if ${\mathbf{JOBU}}=\text{'O'}$, A is overwritten with the first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of $U$ (the left singular vectors, stored column-wise).
If ${\mathbf{JOBVT}}=\text{'O'}$, A is overwritten with the first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of ${V}^{\mathrm{H}}$ (the right singular vectors, stored row-wise).
If ${\mathbf{JOBU}}\ne \text{'O'}$ and ${\mathbf{JOBVT}}\ne \text{'O'}$, the contents of A are destroyed.
6:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F08KPF (ZGESVD) is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$.
7:     S($*$) – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array S must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)\right)$.
On exit: the singular values of $A$, sorted so that ${\mathbf{S}}\left(i\right)\ge {\mathbf{S}}\left(i+1\right)$.
8:     U(LDU,$*$) – COMPLEX (KIND=nag_wp) arrayOutput
Note: the second dimension of the array U must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$ if ${\mathbf{JOBU}}=\text{'A'}$, $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)\right)$ if ${\mathbf{JOBU}}=\text{'S'}$, and at least $1$ otherwise.
On exit: if ${\mathbf{JOBU}}=\text{'A'}$, U contains the $m$ by $m$ unitary matrix $U$.
If ${\mathbf{JOBU}}=\text{'S'}$, U contains the first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of $U$ (the left singular vectors, stored column-wise).
If ${\mathbf{JOBU}}=\text{'N'}$ or $\text{'O'}$, U is not referenced.
9:     LDU – INTEGERInput
On entry: the first dimension of the array U as declared in the (sub)program from which F08KPF (ZGESVD) is called.
Constraints:
• if ${\mathbf{JOBU}}=\text{'A'}$ or $\text{'S'}$, ${\mathbf{LDU}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$;
• otherwise ${\mathbf{LDU}}\ge 1$.
10:   VT(LDVT,$*$) – COMPLEX (KIND=nag_wp) arrayOutput
Note: the second dimension of the array VT must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$ if ${\mathbf{JOBVT}}=\text{'A'}$ or $\text{'S'}$, and at least $1$ otherwise.
On exit: if ${\mathbf{JOBVT}}=\text{'A'}$, VT contains the $n$ by $n$ unitary matrix ${V}^{\mathrm{H}}$.
If ${\mathbf{JOBVT}}=\text{'S'}$, VT contains the first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of ${V}^{\mathrm{H}}$ (the right singular vectors, stored row-wise).
If ${\mathbf{JOBVT}}=\text{'N'}$ or $\text{'O'}$, VT is not referenced.
11:   LDVT – INTEGERInput
On entry: the first dimension of the array VT as declared in the (sub)program from which F08KPF (ZGESVD) is called.
Constraints:
• if ${\mathbf{JOBVT}}=\text{'A'}$, ${\mathbf{LDVT}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• if ${\mathbf{JOBVT}}=\text{'S'}$, ${\mathbf{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 ${\mathbf{LDVT}}\ge 1$.
12:   WORK($\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{LWORK}}\right)$) – COMPLEX (KIND=nag_wp) arrayWorkspace
On exit: if ${\mathbf{INFO}}={\mathbf{0}}$, the real part of ${\mathbf{WORK}}\left(1\right)$ contains the minimum value of LWORK required for optimal performance.
13:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F08KPF (ZGESVD) is called.
If ${\mathbf{LWORK}}=-1$, a workspace query is assumed; the routine only calculates the optimal size of the WORK array, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued.
Suggested value: for optimal performance, LWORK should generally be larger. Consider increasing LWORK by at least $\mathit{nb}×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)$, where $\mathit{nb}$ is the optimal block size.
Constraint: ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,2×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)\right)$.
14:   RWORK($*$) – REAL (KIND=nag_wp) arrayWorkspace
Note: the dimension of the array RWORK must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,5×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)\right)$.
On exit: if ${\mathbf{INFO}}>{\mathbf{0}}$, ${\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$ whose diagonal is in $S$ (not necessarily sorted). $B$ satisfies $A=UB{V}^{\mathrm{H}}$, so it has the same singular values as $A$, and singular vectors related by $U$ and ${V}^{\mathrm{H}}$.
15:   INFO – INTEGEROutput
On exit: ${\mathbf{INFO}}=0$ unless the routine detects an error (see Section 6).

## 6  Error Indicators and Warnings

Errors or warnings detected by the routine:
${\mathbf{INFO}}<0$
If ${\mathbf{INFO}}=-i$, argument $i$ had an illegal value. An explanatory message is output, and execution of the program is terminated.
${\mathbf{INFO}}>0$
If F08KPF (ZGESVD) 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.

## 7  Accuracy

The computed singular value decomposition is nearly the exact singular value decomposition for a nearby matrix $\left(A+E\right)$, where
 $E2 = Oε A2 ,$
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 $m{n}^{2}$ when $m>n$ and ${m}^{2}n$ otherwise.
The singular values are returned in descending order.
The real analogue of this routine is F08KBF (DGESVD).

## 9  Example

This example finds the singular values and left and right singular vectors of the $6$ by $4$ matrix
 $A = 0.96-0.81i -0.03+0.96i -0.91+2.06i -0.05+0.41i -0.98+1.98i -1.20+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.60i -0.37+0.38i 0.19-0.54i -0.98-0.36i 0.22-0.20i 0.83+0.51i 0.20+0.01i -0.17-0.46i 1.47+1.59i 1.08-0.28i 0.20-0.12i -0.07+1.23i 0.26+0.26i ,$
together with approximate error bounds for the computed singular values and vectors.
The example program for F08KRF (ZGESDD) illustrates finding a singular value decomposition for the case $m\le n$.

### 9.1  Program Text

Program Text (f08kpfe.f90)

### 9.2  Program Data

Program Data (f08kpfe.d)

### 9.3  Program Results

Program Results (f08kpfe.r)