F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08KDF (DGESDD)

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

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

## 2  Specification

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

## 3  Description

The SVD is written as
 $A = UΣVT ,$
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$ orthogonal matrix, and $V$ is an $n$ by $n$ orthogonal 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{T}}$, 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  Arguments

1:     $\mathrm{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{T}}$ 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{T}}$ 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{T}}$ 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{T}}$ are overwritten in the array VT.
${\mathbf{JOBZ}}=\text{'N'}$
No columns of $U$ or rows of ${V}^{\mathrm{T}}$ are computed.
Constraint: ${\mathbf{JOBZ}}=\text{'A'}$, $\text{'S'}$, $\text{'O'}$ or $\text{'N'}$.
2:     $\mathrm{M}$ – INTEGERInput
On entry: $m$, the number of rows of the matrix $A$.
Constraint: ${\mathbf{M}}\ge 0$.
3:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of columns of the matrix $A$.
Constraint: ${\mathbf{N}}\ge 0$.
4:     $\mathrm{A}\left({\mathbf{LDA}},*\right)$ – REAL (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{T}}$ (the right singular vectors, stored row-wise) otherwise.
If ${\mathbf{JOBZ}}\ne \text{'O'}$, the contents of A are destroyed.
5:     $\mathrm{LDA}$ – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F08KDF (DGESDD) is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$.
6:     $\mathrm{S}\left(\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)\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:     $\mathrm{U}\left({\mathbf{LDU}},*\right)$ – REAL (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$ orthogonal 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:     $\mathrm{LDU}$ – INTEGERInput
On entry: the first dimension of the array U as declared in the (sub)program from which F08KDF (DGESDD) 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:     $\mathrm{VT}\left({\mathbf{LDVT}},*\right)$ – REAL (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$ orthogonal matrix ${V}^{\mathrm{T}}$.
If ${\mathbf{JOBZ}}=\text{'S'}$, VT contains the first $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ rows of ${V}^{\mathrm{T}}$ (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:   $\mathrm{LDVT}$ – INTEGERInput
On entry: the first dimension of the array VT as declared in the (sub)program from which F08KDF (DGESDD) 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:   $\mathrm{WORK}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{LWORK}}\right)\right)$ – REAL (KIND=nag_wp) arrayWorkspace
12:   $\mathrm{LWORK}$ – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F08KDF (DGESDD) 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 3×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right),7×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)\right)$;
• if ${\mathbf{JOBZ}}=\text{'O'}$, ${\mathbf{LWORK}}\ge 3×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+\phantom{\rule{0ex}{0ex}}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right),5×\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)+4×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)\right)$;
• if ${\mathbf{JOBZ}}=\text{'S'}$ or $\text{'A'}$, ${\mathbf{LWORK}}\ge 3×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)+\phantom{\rule{0ex}{0ex}}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right),4×\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)+4×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)\right)$;
• otherwise ${\mathbf{LWORK}}\ge 1$.
13:   $\mathrm{IWORK}\left(8×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{M}},{\mathbf{N}}\right)\right)$ – INTEGER arrayWorkspace
14:   $\mathrm{INFO}$ – INTEGEROutput
On exit: ${\mathbf{INFO}}=0$ unless the routine detects an error (see Section 6).

## 6  Error Indicators and Warnings

${\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$
F08KDF (DGESDD) 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  Parallelism and Performance

F08KDF (DGESDD) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
F08KDF (DGESDD) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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 complex analogue of this routine is F08KRF (ZGESDD).

## 10  Example

This example finds the singular values and left and right singular vectors of the $4$ by $6$ matrix
 $A = 2.27 0.28 -0.48 1.07 -2.35 0.62 -1.54 -1.67 -3.09 1.22 2.93 -7.39 1.15 0.94 0.99 0.79 -1.45 1.03 -1.94 -0.78 -0.21 0.63 2.30 -2.57 ,$
together with approximate error bounds for the computed singular values and vectors.
The example program for F08KBF (DGESVD) illustrates finding a singular value decomposition for the case $m\ge n$.

### 10.1  Program Text

Program Text (f08kdfe.f90)

### 10.2  Program Data

Program Data (f08kdfe.d)

### 10.3  Program Results

Program Results (f08kdfe.r)