nag_dgesvj (f08kjc) (PDF version)
f08 Chapter Contents
f08 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_dgesvj (f08kjc)

## 1  Purpose

nag_dgesvj (f08kjc) 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 functions nag_dgesvd (f08kbc) or nag_dgesdd (f08kdc) may be used.

## 2  Specification

 #include #include
 void nag_dgesvj (Nag_OrderType order, Nag_MatrixType joba, Nag_LeftVecsType jobu, Nag_RightVecsType jobv, Integer m, Integer n, double a[], Integer pda, double sva[], Integer mv, double v[], Integer pdv, double work[], Integer lwork, NagError *fail)

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

1:     orderNag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2:     jobaNag_MatrixTypeInput
On entry: specifies the structure of matrix $A$.
${\mathbf{joba}}=\mathrm{Nag_LowerMatrix}$
The input matrix $A$ is lower triangular.
${\mathbf{joba}}=\mathrm{Nag_UpperMatrix}$
The input matrix $A$ is upper triangular.
${\mathbf{joba}}=\mathrm{Nag_GeneralMatrix}$
The input matrix $A$ is a general $m$ by $n$ matrix, ${\mathbf{m}}\ge {\mathbf{n}}$.
Constraint: ${\mathbf{joba}}=\mathrm{Nag_LowerMatrix}$, $\mathrm{Nag_UpperMatrix}$ or $\mathrm{Nag_GeneralMatrix}$.
3:     jobuNag_LeftVecsTypeInput
On entry: specifies whether to compute the left singular vectors and if so whether you want to control their numerical orthogonality threshold.
${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$
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}}=\mathrm{Nag_LeftVecsCtol}$
Analogous to ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$, 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[0\right]$. The option ${\mathbf{jobu}}=\mathrm{Nag_LeftVecsCtol}$ 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[0\right]$.
${\mathbf{jobu}}=\mathrm{Nag_NotLeftVecs}$
The matrix $U$ is not computed. However, see the description of a.
Constraint: ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$, $\mathrm{Nag_LeftVecsCtol}$ or $\mathrm{Nag_NotLeftVecs}$.
4:     jobvNag_RightVecsTypeInput
On entry: specifies whether and how to compute the right singular vectors.
${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$
The matrix $V$ is computed and returned in the array v.
${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$
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}}=\mathrm{Nag_NotRightVecs}$
The matrix $V$ is not computed and the array v is not referenced.
Constraint: ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$, $\mathrm{Nag_RightVecsMV}$ or $\mathrm{Nag_NotRightVecs}$.
5:     mIntegerInput
On entry: $m$, the number of rows of the matrix $A$.
Constraint: ${\mathbf{m}}\ge 0$.
6:     nIntegerInput
On entry: $n$, the number of columns of the matrix $A$.
Constraint: ${\mathbf{m}}\ge {\mathbf{n}}\ge 0$.
7:     a[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array a must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pda}}×{\mathbf{n}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}×{\mathbf{pda}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
The $\left(i,j\right)$th element of the matrix $A$ is stored in
• ${\mathbf{a}}\left[\left(j-1\right)×{\mathbf{pda}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{a}}\left[\left(i-1\right)×{\mathbf{pda}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the $m$ by $n$ matrix $A$.
On exit: the matrix $U$ containing the left singular vectors of $A$.
If ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$ or $\mathrm{Nag_LeftVecsCtol}$
if ${\mathbf{fail}}\mathbf{.}\mathbf{errnum}=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 nag_real_safe_small_number (X02AMC). 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[1\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}}=\mathrm{Nag_LeftVecsCtol}$), where $\epsilon$ is the machine precision and $\mathit{ctol}$ is supplied on entry in ${\mathbf{work}}\left[0\right]$, see the description of jobu.
If ${\mathbf{fail}}\mathbf{.}\mathbf{errnum}>0$
nag_dgesvj (f08kjc) 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[0\right]$.
If ${\mathbf{jobu}}=\mathrm{Nag_NotLeftVecs}$
if ${\mathbf{fail}}\mathbf{.}\mathbf{errnum}=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{fail}}\mathbf{.}\mathbf{errnum}>0$
nag_dgesvj (f08kjc) did not converge in $30$ iterations (sweeps).
8:     pdaIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array a.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
9:     sva[n]doubleOutput
On exit: the, possibly scaled, singular values of $A$.
If ${\mathbf{fail}}\mathbf{.}\mathbf{errnum}=0$
The singular values of $A$ are ${\sigma }_{\mathit{i}}=\alpha {\mathbf{sva}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,n$, where $\alpha$ is the scale factor stored in ${\mathbf{work}}\left[0\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{fail}}\mathbf{.}\mathbf{errnum}>0$
nag_dgesvj (f08kjc) did not converge in $30$ iterations and $\alpha ×{\mathbf{sva}}$ may not be accurate.
10:   mvIntegerInput
On entry: if ${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$, the product of Jacobi rotations is applied to the first ${m}_{v}$ rows of v.
If ${\mathbf{jobv}}\ne \mathrm{Nag_RightVecsMV}$, mv is ignored. See the description of jobv.
11:   v[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array v must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdv}}×{\mathbf{n}}\right)$ when ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdv}}×{\mathbf{n}}\right)$ when ${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$ and ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mv}}×{\mathbf{pdv}}\right)$ when ${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$ and ${\mathbf{order}}=\mathrm{Nag_RowMajor}$;
• $1$ otherwise.
The $\left(i,j\right)$th element of the matrix $V$ is stored in
• ${\mathbf{v}}\left[\left(j-1\right)×{\mathbf{pdv}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{v}}\left[\left(i-1\right)×{\mathbf{pdv}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: if ${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$, 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}}=\mathrm{Nag_RightVecs}$, v contains the $n$ by $n$ matrix of the right singular vectors.
If ${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$, v contains the product of the computed right singular vector matrix and the initial matrix in the array v.
If ${\mathbf{jobv}}=\mathrm{Nag_NotRightVecs}$, v is not referenced.
12:   pdvIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array v.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mv}}\right)$;
• otherwise ${\mathbf{pdv}}\ge 1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$,
• if ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ${\mathbf{pdv}}\ge 1$.
13:   work[lwork]doubleCommunication Array
On entry: if ${\mathbf{jobu}}=\mathrm{Nag_LeftVecsCtol}$, ${\mathbf{work}}\left[0\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 function 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[0\right]$
the scaling factor, $\alpha$, such that ${\sigma }_{\mathit{i}}=\alpha {\mathbf{sva}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,n$ are the computed singular values of $A$. (See description of sva.)
${\mathbf{work}}\left[1\right]$
$\mathrm{nint}\left({\mathbf{work}}\left[1\right]\right)$gives the number of the computed nonzero singular values.
${\mathbf{work}}\left[2\right]$
$\mathrm{nint}\left({\mathbf{work}}\left[2\right]\right)$ gives the number of the computed singular values that are larger than the underflow threshold.
${\mathbf{work}}\left[3\right]$
$\mathrm{nint}\left({\mathbf{work}}\left[3\right]\right)$ gives the number of iterations (sweeps of Jacobi rotations) needed for numerical convergence.
${\mathbf{work}}\left[4\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 nag_dgesvj (f08kjc) did not converge, as it can be used to estimate whether the output is still useful and for subsequent analysis.
${\mathbf{work}}\left[5\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}}=\mathrm{Nag_LeftVecsCtol}$, ${\mathbf{work}}\left[0\right]\ge 1.0$.
14:   lworkIntegerInput
On entry: the dimension of the array work.
Constraint: ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(6,{\mathbf{m}}+{\mathbf{n}}\right)$.
15:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BAD_PARAM
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_CONVERGENCE
nag_dgesvj (f08kjc) did not converge in the allowed number of iterations ($30$), but its output might still be useful.
NE_ENUM_INT_3
On entry, ${\mathbf{jobv}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{mv}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{pdv}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
if ${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mv}}\right)$;
otherwise ${\mathbf{pdv}}\ge 1$.
NE_ENUM_INT_4
On entry, ${\mathbf{jobv}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{pdv}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{mv}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{pdv}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
if ${\mathbf{jobv}}=\mathrm{Nag_RightVecsMV}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
otherwise ${\mathbf{pdv}}\ge 1$.
NE_ENUM_REAL_1
On entry, ${\mathbf{jobu}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{work}}\left[0\right]=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{jobu}}=\mathrm{Nag_LeftVecsCtol}$, ${\mathbf{work}}\left[0\right]\ge 1.0$.
NE_INT
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 0$.
On entry, ${\mathbf{pda}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pda}}>0$.
On entry, ${\mathbf{pdv}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdv}}>0$.
NE_INT_2
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge {\mathbf{n}}\ge 0$.
On entry, ${\mathbf{pda}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
On entry, ${\mathbf{pda}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
NE_INT_3
On entry, ${\mathbf{lwork}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(6,{\mathbf{m}}+{\mathbf{n}}\right)$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.

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

## 8  Parallelism and Performance

nag_dgesvj (f08kjc) is not threaded by NAG in any implementation.
nag_dgesvj (f08kjc) 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 Users' Note for your implementation for any additional implementation-specific information.

## 9  Further Comments

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

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

### 10.1  Program Text

Program Text (f08kjce.c)

### 10.2  Program Data

Program Data (f08kjce.d)

### 10.3  Program Results

Program Results (f08kjce.r)

nag_dgesvj (f08kjc) (PDF version)
f08 Chapter Contents
f08 Chapter Introduction
NAG Library Manual