F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08KRF (ZGESDD)

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

F08KRF (ZGESDD) computes the singular value decomposition (SVD) of a complex $m$ by $n$ matrix $A$, optionally computing the left and/or right singular vectors, by using a divide-and-conquer method.

## 2  Specification

 SUBROUTINE F08KRF ( JOBZ, M, N, A, LDA, S, U, LDU, VT, LDVT, WORK, LWORK, RWORK, IWORK, INFO)
 INTEGER M, N, LDA, LDU, LDVT, LWORK, IWORK(8*min(M,N)), INFO REAL (KIND=nag_wp) S(min(M,N)), RWORK(*) COMPLEX (KIND=nag_wp) A(LDA,*), U(LDU,*), VT(LDVT,*), WORK(max(1,LWORK)) CHARACTER(1) JOBZ
The routine may be called by its LAPACK name zgesdd.

## 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$.

## 4  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

## 5  Parameters

1:     JOBZ – CHARACTER(1)Input
On entry: specifies options for computing all or part of the matrix $U$.
${\mathbf{JOBZ}}=\text{'A'}$
All $m$ columns of $U$ and all $n$ rows of ${V}^{\mathrm{H}}$ are returned in the arrays U and VT.
${\mathbf{JOBZ}}=\text{'S'}$
The first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ columns of $U$ and the first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of ${V}^{\mathrm{H}}$ are returned in the arrays U and VT.
${\mathbf{JOBZ}}=\text{'O'}$
If ${\mathbf{M}}\ge {\mathbf{N}}$, the first $n$ columns of $U$ are overwritten on the array A and all rows of ${V}^{\mathrm{H}}$ are returned in the array VT. Otherwise, all columns of $U$ are returned in the array U and the first $m$ rows of ${V}^{\mathrm{H}}$ are overwritten in the array VT.
${\mathbf{JOBZ}}=\text{'N'}$
No columns of $U$ or rows of ${V}^{\mathrm{H}}$ are computed.
Constraint: ${\mathbf{JOBZ}}=\text{'A'}$, $\text{'S'}$, $\text{'O'}$ or $\text{'N'}$.
2:     M – INTEGERInput
On entry: $m$, the number of rows of the matrix $A$.
Constraint: ${\mathbf{M}}\ge 0$.
3:     N – INTEGERInput
On entry: $n$, the number of columns of the matrix $A$.
Constraint: ${\mathbf{N}}\ge 0$.
4:     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{JOBZ}}=\text{'O'}$, A is overwritten with the first $n$ columns of $U$ (the left singular vectors, stored column-wise) if ${\mathbf{M}}\ge {\mathbf{N}}$; A is overwritten with the first $m$ rows of ${V}^{\mathrm{H}}$ (the right singular vectors, stored row-wise) otherwise.
If ${\mathbf{JOBZ}}\ne \text{'O'}$, the contents of A are destroyed.
5:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F08KRF (ZGESDD) is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$.
6:     S($\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)$) – REAL (KIND=nag_wp) arrayOutput
On exit: the singular values of $A$, sorted so that ${\mathbf{S}}\left(i\right)\ge {\mathbf{S}}\left(i+1\right)$.
7:     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{JOBZ}}=\text{'A'}$ or ${\mathbf{JOBZ}}=\text{'O'}$ and ${\mathbf{M}}<{\mathbf{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 ${\mathbf{JOBZ}}=\text{'S'}$, and at least $1$ otherwise.
On exit:
If ${\mathbf{JOBZ}}=\text{'A'}$ or ${\mathbf{JOBZ}}=\text{'O'}$ and ${\mathbf{M}}<{\mathbf{N}}$, U contains the $m$ by $m$ unitary matrix $U$.
If ${\mathbf{JOBZ}}=\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{JOBZ}}=\text{'O'}$ and ${\mathbf{M}}\ge {\mathbf{N}}$, or ${\mathbf{JOBZ}}=\text{'N'}$, U is not referenced.
8:     LDU – INTEGERInput
On entry: the first dimension of the array U as declared in the (sub)program from which F08KRF (ZGESDD) is called.
Constraints:
• if ${\mathbf{JOBZ}}=\text{'S'}$ or $\text{'A'}$ or ${\mathbf{JOBZ}}=\text{'O'}$ and ${\mathbf{M}}<{\mathbf{N}}$, ${\mathbf{LDU}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$;
• otherwise ${\mathbf{LDU}}\ge 1$.
9:     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{JOBZ}}=\text{'A'}$ or $\text{'S'}$ or ${\mathbf{JOBZ}}=\text{'O'}$ and ${\mathbf{M}}\ge {\mathbf{N}}$, and at least $1$ otherwise.
On exit: if ${\mathbf{JOBZ}}=\text{'A'}$ or ${\mathbf{JOBZ}}=\text{'O'}$ and ${\mathbf{M}}\ge {\mathbf{N}}$, VT contains the $n$ by $n$ unitary matrix ${V}^{\mathrm{H}}$.
If ${\mathbf{JOBZ}}=\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{JOBZ}}=\text{'O'}$ and ${\mathbf{M}}<{\mathbf{N}}$, or ${\mathbf{JOBZ}}=\text{'N'}$, VT is not referenced.
10:   LDVT – INTEGERInput
On entry: the first dimension of the array VT as declared in the (sub)program from which F08KRF (ZGESDD) is called.
Constraints:
• if ${\mathbf{JOBZ}}=\text{'A'}$ or ${\mathbf{JOBZ}}=\text{'O'}$ and ${\mathbf{M}}\ge {\mathbf{N}}$, ${\mathbf{LDVT}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• if ${\mathbf{JOBZ}}=\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$.
11:   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.
12:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F08KRF (ZGESDD) 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.
Constraints:
• if ${\mathbf{JOBZ}}=\text{'N'}$, ${\mathbf{LWORK}}\ge 2×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}},{\mathbf{N}}\right)$;
• if ${\mathbf{JOBZ}}=\text{'O'}$, ${\mathbf{LWORK}}\ge 2×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+2×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}},{\mathbf{N}}\right)$;
• if ${\mathbf{JOBZ}}=\text{'S'}$ or $\text{'A'}$, $\phantom{\rule{0ex}{0ex}}{\mathbf{LWORK}}\ge \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+2×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}},{\mathbf{N}}\right)$;
• otherwise ${\mathbf{LWORK}}\ge 1$.
13:   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)$ if ${\mathbf{JOBZ}}=\text{'N'}$, and at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(5×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+7,2×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+2×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+1\right)\right)$ otherwise.
14:   IWORK($8×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)$) – INTEGER arrayWorkspace
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$
F08KRF (ZGESDD) did not converge, the updating process failed.

## 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.

## 8  Further Comments

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 F08KDF (DGESDD).

## 9  Example

This example finds the singular values and left and right singular vectors of the $4$ by $6$ matrix
 $A = 0.96+0.81i -0.98-1.98i 0.62+0.46i -0.37-0.38i 0.83-0.51i 1.08+0.28i -0.03-0.96i -1.20-0.19i 1.01-0.02i 0.19+0.54i 0.20-0.01i 0.20+0.12i -0.91-2.06i -0.66-0.42i 0.63+0.17i -0.98+0.36i -0.17+0.46i -0.07-1.23i -0.05-0.41i -0.81-0.56i -1.11-0.60i 0.22+0.20i 1.47-1.59i 0.26-0.26i ,$
together with approximate error bounds for the computed singular values and vectors.
The example program for F08KPF (ZGESVD) illustrates finding a singular value decomposition for the case $m\ge n$.

### 9.1  Program Text

Program Text (f08krfe.f90)

### 9.2  Program Data

Program Data (f08krfe.d)

### 9.3  Program Results

Program Results (f08krfe.r)