F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08KJF (DGESVJ)

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

F08KJF (DGESVJ) computes the one-sided Jacobi singular value decomposition (SVD) of a real $m$ by $n$ matrix $A$, $m\ge n$, with fast scaled rotations and de Rijk’s pivoting, optionally computing the left and/or right singular vectors. For $m, the routines F08KBF (DGESVD) or F08KDF (DGESDD) may be used.

## 2  Specification

 SUBROUTINE F08KJF ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V, LDV, WORK, LWORK, INFO)
 INTEGER M, N, LDA, MV, LDV, LWORK, INFO REAL (KIND=nag_wp) A(LDA,*), SVA(N), V(LDV,*), WORK(LWORK) CHARACTER(1) JOBA, JOBU, JOBV
The routine may be called by its LAPACK name dgesvj.

## 3  Description

The SVD is written as
 $A = UΣVT ,$
where $\Sigma$ is an $n$ by $n$ diagonal matrix, $U$ is an $m$ by $n$ orthonormal matrix, and $V$ is an $n$ by $n$ orthogonal matrix. The diagonal elements of $\Sigma$ are the singular values of $A$ in descending order of magnitude. The columns of $U$ and $V$ are the left and the right singular vectors of $A$.

## 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
Drmac Z and Veselic K (2008a) New fast and accurate Jacobi SVD algorithm I SIAM J. Matrix Anal. Appl. 29 4
Drmac Z and Veselic K (2008b) New fast and accurate Jacobi SVD algorithm II SIAM J. Matrix Anal. Appl. 29 4
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5  Parameters

1:     JOBA – CHARACTER(1)Input
On entry: specifies the structure of matrix $A$.
${\mathbf{JOBA}}=\text{'L'}$
The input matrix $A$ is lower triangular.
${\mathbf{JOBA}}=\text{'U'}$
The input matrix $A$ is upper triangular.
${\mathbf{JOBA}}=\text{'G'}$
The input matrix $A$ is a general $m$ by $n$ matrix, ${\mathbf{M}}\ge {\mathbf{N}}$.
Constraint: ${\mathbf{JOBA}}=\text{'L'}$, $\text{'U'}$ or $\text{'G'}$.
2:     JOBU – CHARACTER(1)Input
On entry: specifies whether to compute the left singular vectors and if so whether you want to control their numerical orthogonality threshold.
${\mathbf{JOBU}}=\text{'U'}$
The left singular vectors corresponding to the nonzero singular values are computed and returned in the leading columns of A. See more details in the description of A. The numerical orthogonality threshold is set to approximately $\mathit{tol}=\mathit{ctol}×\epsilon$, where $\epsilon$ is the machine precision and $\mathit{ctol}=\sqrt{m}$.
${\mathbf{JOBU}}=\text{'C'}$
Analogous to ${\mathbf{JOBU}}=\text{'U'}$, except that you can control the level of numerical orthogonality of the computed left singular vectors. The orthogonality threshold is set to $\mathit{tol}=\mathit{ctol}×\epsilon$, where $\mathit{ctol}$ is given on input in ${\mathbf{WORK}}\left(1\right)$. The option ${\mathbf{JOBU}}=\text{'C'}$ can be used if $m×\epsilon$ is a satisfactory orthogonality of the computed left singular vectors, so $\mathit{ctol}={\mathbf{M}}$ could save a few sweeps of Jacobi rotations. See the descriptions of A and ${\mathbf{WORK}}\left(1\right)$.
${\mathbf{JOBU}}=\text{'N'}$
The matrix $U$ is not computed. However, see the description of A.
Constraint: ${\mathbf{JOBU}}=\text{'U'}$, $\text{'C'}$ or $\text{'N'}$.
3:     JOBV – CHARACTER(1)Input
On entry: specifies whether and how to compute the right singular vectors.
${\mathbf{JOBV}}=\text{'V'}$
The matrix $V$ is computed and returned in the array V.
${\mathbf{JOBV}}=\text{'A'}$
The Jacobi rotations are applied to the leading ${m}_{v}$ by $n$ part of the array V. In other words, the right singular vector matrix $V$ is not computed explicitly, instead it is applied to an ${m}_{v}$ by $n$ matrix initially stored in the first MV rows of V.
${\mathbf{JOBV}}=\text{'N'}$
The matrix $V$ is not computed and the array V is not referenced.
Constraint: ${\mathbf{JOBV}}=\text{'V'}$, $\text{'A'}$ or $\text{'N'}$.
4:     M – INTEGERInput
On entry: $m$, the number of rows of the matrix $A$.
Constraint: ${\mathbf{M}}\ge 0$.
5:     N – INTEGERInput
On entry: $n$, the number of columns of the matrix $A$.
Constraint: ${\mathbf{M}}\ge {\mathbf{N}}\ge 0$.
6:     A(LDA,$*$) – 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: the matrix $U$ containing the left singular vectors of $A$.
If ${\mathbf{JOBU}}=\text{'U'}$ or $\text{'C'}$
if ${\mathbf{INFO}}=0$
$\mathrm{rank}\left(A\right)$ orthonormal columns of $U$ are returned in the leading $\mathrm{rank}\left(A\right)$ columns of the array A. Here $\mathrm{rank}\left(A\right)\le {\mathbf{N}}$ is the number of computed singular values of $A$ that are above the safe range parameter, as returned by X02AMF. The singular vectors corresponding to underflowed or zero singular values are not computed. The value of $\mathrm{rank}\left(A\right)$ is returned by rounding ${\mathbf{WORK}}\left(2\right)$ to the nearest whole number. Also see the descriptions of SVA and WORK. The computed columns of $U$ are mutually numerically orthogonal up to approximately $\mathit{tol}=\sqrt{m}×\epsilon$; or $\mathit{tol}=\mathit{ctol}×\epsilon$ (${\mathbf{JOBU}}=\text{'C'}$), where $\epsilon$ is the machine precision and $\mathit{ctol}$ is supplied on entry in ${\mathbf{WORK}}\left(1\right)$, see the description of JOBU.
If ${\mathbf{INFO}}>0$
F08KJF (DGESVJ) did not converge in $30$ iterations (sweeps). In this case, the computed columns of $U$ may not be orthogonal up to $\mathit{tol}$. The output $U$ (stored in A), $\Sigma$ (given by the computed singular values in SVA) and $V$ is still a decomposition of the input matrix $A$ in the sense that the residual ${‖A-\alpha ×U×\Sigma ×{V}^{\mathrm{T}}‖}_{2}/{‖A‖}_{2}$ is small, where $\alpha$ is the value returned in ${\mathbf{WORK}}\left(1\right)$.
If ${\mathbf{JOBU}}=\text{'N'}$
if ${\mathbf{INFO}}=0$
Note that the left singular vectors are ‘for free’ in the one-sided Jacobi SVD algorithm. However, if only the singular values are needed, the level of numerical orthogonality of $U$ is not an issue and iterations are stopped when the columns of the iterated matrix are numerically orthogonal up to approximately $m×\epsilon$. Thus, on exit, A contains the columns of $U$ scaled with the corresponding singular values.
If ${\mathbf{INFO}}>0$
F08KJF (DGESVJ) did not converge in $30$ iterations (sweeps).
7:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F08KJF (DGESVJ) is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$.
8:     SVA(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the, possibly scaled, singular values of $A$.
If ${\mathbf{INFO}}=0$
The singular values of $A$ are ${\sigma }_{\mathit{i}}=\alpha {\mathbf{SVA}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,n$, where $\alpha$ is the scale factor stored in ${\mathbf{WORK}}\left(1\right)$. Normally $\alpha =1$, however, if some of the singular values of $A$ might underflow or overflow, then $\alpha \ne 1$ and the scale factor needs to be applied to obtain the singular values.
If ${\mathbf{INFO}}>0$
F08KJF (DGESVJ) did not converge in $30$ iterations and $\alpha ×{\mathbf{SVA}}$ may not be accurate.
9:     MV – INTEGERInput
On entry: if ${\mathbf{JOBV}}=\text{'A'}$, the product of Jacobi rotations is applied to the first ${m}_{v}$ rows of V.
If ${\mathbf{JOBV}}\ne \text{'A'}$, MV is ignored. See the description of JOBV.
10:   V(LDV,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array V must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$ if ${\mathbf{JOBV}}=\text{'V'}$ or $\text{'A'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{JOBV}}=\text{'A'}$, V must contain an ${m}_{v}$ by $n$ matrix to be premultiplied by the matrix $V$ of right singular vectors.
On exit: the right singular vectors of $A$.
If ${\mathbf{JOBV}}=\text{'V'}$, V contains the $n$ by $n$ matrix of the right singular vectors.
If ${\mathbf{JOBV}}=\text{'A'}$, V contains the product of the computed right singular vector matrix and the initial matrix in the array V.
If ${\mathbf{JOBV}}=\text{'N'}$, V is not referenced.
11:   LDV – INTEGERInput
On entry: the first dimension of the array V as declared in the (sub)program from which F08KJF (DGESVJ) is called.
Constraints:
• if ${\mathbf{JOBV}}=\text{'V'}$, ${\mathbf{LDV}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• if ${\mathbf{JOBV}}=\text{'A'}$, ${\mathbf{LDV}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{MV}}\right)$;
• otherwise ${\mathbf{LDV}}\ge 1$.
12:   WORK(LWORK) – REAL (KIND=nag_wp) arrayCommunication Array
On entry: if ${\mathbf{JOBU}}=\text{'C'}$, ${\mathbf{WORK}}\left(1\right)=\mathit{ctol}$, where $\mathit{ctol}$ defines the threshold for convergence. The process stops if all columns of $A$ are mutually orthogonal up to $\mathit{ctol}×\epsilon$. It is required that $\mathit{ctol}\ge 1$, i.e., it is not possible to force the routine to obtain orthogonality below $\epsilon$. $\mathit{ctol}$ greater than $1/\epsilon$ is meaningless, where $\epsilon$ is the machine precision.
On exit: contains information about the completed job.
${\mathbf{WORK}}\left(1\right)$
the scaling factor, $\alpha$, such that ${\sigma }_{\mathit{i}}=\alpha {\mathbf{SVA}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,n$ are the computed singular values of $A$. (See description of SVA.)
${\mathbf{WORK}}\left(2\right)$
$\mathrm{nint}\left({\mathbf{WORK}}\left(2\right)\right)$gives the number of the computed nonzero singular values.
${\mathbf{WORK}}\left(3\right)$
$\mathrm{nint}\left({\mathbf{WORK}}\left(3\right)\right)$ gives the number of the computed singular values that are larger than the underflow threshold.
${\mathbf{WORK}}\left(4\right)$
$\mathrm{nint}\left({\mathbf{WORK}}\left(4\right)\right)$ gives the number of iterations (sweeps of Jacobi rotations) needed for numerical convergence.
${\mathbf{WORK}}\left(5\right)$
${\mathrm{max}}_{i\ne j}\left|\mathrm{cos}\left(A\left(:,i\right),A\left(:,j\right)\right)\right|$ in the last iteration (sweep). This is useful information in cases when F08KJF (DGESVJ) did not converge, as it can be used to estimate whether the output is still useful and for subsequent analysis.
${\mathbf{WORK}}\left(6\right)$
The largest absolute value over all sines of the Jacobi rotation angles in the last sweep. It can be useful for subsequent analysis.
Constraint: if ${\mathbf{JOBU}}=\text{'C'}$, ${\mathbf{WORK}}\left(1\right)\ge 1.0$.
13:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which F08KJF (DGESVJ) is called.
Constraint: ${\mathbf{LWORK}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(6,{\mathbf{M}}+{\mathbf{N}}\right)$.
14:   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$
F08KJF (DGESVJ) did not converge in $30$ iterations (sweeps), but its output might still be useful.

## 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.
See Section 6 of Drmac and Veselic (2008a) for a detailed discussion of the accuracy of the computed SVD.

This SVD algorithm is numerically superior to the bidiagonalization based $QR$ algorithm implemented by F08KBF (DGESVD) and the divide and conquer algorithm implemented by F08KDF (DGESDD) algorithms and is considerably faster than previous implementations of the (equally accurate) Jacobi SVD method. Moreover, this algorithm can compute the SVD faster than F08KBF (DGESVD) and not much slower than F08KDF (DGESDD). See Section 3.3 of Drmac and Veselic (2008b) for the details.

## 9  Example

This example finds the singular values and left and right singular vectors of the $6$ by $4$ matrix
 $A = 2.27 -1.54 1.15 -1.94 0.28 -1.67 0.94 -0.78 -0.48 -3.09 0.99 -0.21 1.07 1.22 0.79 0.63 -2.35 2.93 -1.45 2.30 0.62 -7.39 1.03 -2.57 ,$
together with approximate error bounds for the computed singular values and vectors.

### 9.1  Program Text

Program Text (f08kjfe.f90)

### 9.2  Program Data

Program Data (f08kjfe.d)

### 9.3  Program Results

Program Results (f08kjfe.r)