# NAG CL Interfacef08khc (dgejsv)

Settings help

CL Name Style:

## 1Purpose

f08khc computes the singular value decomposition (SVD) of a real $m×n$ matrix $A$, where $m\ge n$, and optionally computes the left and/or right singular vectors. f08khc implements the preconditioned Jacobi SVD of Drmač and Veselić (2008a) and Drmač and Veselić (2008b). This is the expert driver function that calls f08kjc after certain preconditioning. In most cases f08kbc or f08kdc, employing fast scaled rotations and de Rijk's pivoting strategy, is sufficient to obtain the SVD of a real matrix. These are much simpler to use and also handle the case $m.

## 2Specification

 #include
 void f08khc (Nag_OrderType order, Nag_Preprocess joba, Nag_LeftVecsType jobu, Nag_RightVecsType jobv, Nag_ZeroCols jobr, Nag_TransType jobt, Nag_Perturb jobp, Integer m, Integer n, double a[], Integer pda, double sva[], double u[], Integer pdu, double v[], Integer pdv, double work[], Integer iwork[], NagError *fail)
The function may be called by the names: f08khc, nag_lapackeig_dgejsv or nag_dgejsv.

## 3Description

The SVD is written as
 $A = UΣVT ,$
where $\Sigma$ is an $m×n$ matrix which is zero except for its $n$ diagonal elements, $U$ is an $m×m$ orthogonal matrix, and $V$ is an $n×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$, respectively.

## 4References

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 https://www.netlib.org/lapack/lug
Drmač Z and Veselić K (2008a) New fast and accurate Jacobi SVD Algorithm I SIAM J. Matrix Anal. Appl. 29 4
Drmač Z and Veselić 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

## 5Arguments

1: $\mathbf{order}$Nag_OrderType Input
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.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2: $\mathbf{joba}$Nag_Preprocess Input
On entry: specifies the form of pivoting for the $QR$ factorization stage; whether an estimate of the condition number of the scaled matrix is required; and the form of rank reduction that is performed.
${\mathbf{joba}}=\mathrm{Nag_ColpivRrank}$
The initial $QR$ factorization of the input matrix is performed with column pivoting; no estimate of condition number is computed; and, the rank is reduced by only the underflowed part of the triangular factor $R$. This option works well (high relative accuracy) if $A$ can be written in the form $A=BD$, with well-conditioned $B$ and arbitrary diagonal matrix $D$. The accuracy cannot be spoiled by column scaling. The accuracy of the computed output depends on the condition of $B$, and the procedure attempts to achieve the best theoretical accuracy.
${\mathbf{joba}}=\mathrm{Nag_ColpivRrankCond}$
Computation as with ${\mathbf{joba}}=\mathrm{Nag_ColpivRrank}$ with an additional estimate of the condition number of $B$. It provides a realistic error bound.
${\mathbf{joba}}=\mathrm{Nag_FullpivRrank}$
The initial $QR$ factorization of the input matrix is performed with full row and column pivoting; no estimate of condition number is computed; and, the rank is reduced by only the underflowed part of the triangular factor $R$. If $A={D}_{1}×C×{D}_{2}$ with ill-conditioned diagonal scalings ${D}_{1}$, ${D}_{2}$, and well-conditioned matrix $C$, this option gives higher accuracy than the ${\mathbf{joba}}=\mathrm{Nag_ColpivRrank}$ option. If the structure of the input matrix is not known, and relative accuracy is desirable, then this option is advisable.
${\mathbf{joba}}=\mathrm{Nag_FullpivRrankCond}$
Computation as with ${\mathbf{joba}}=\mathrm{Nag_FullpivRrank}$ with an additional estimate of the condition number of $B$, where $A=DB$ (i.e., $B=C×{D}_{2}$). If $A$ has heavily weighted rows, then using this condition number gives too pessimistic an error bound.
${\mathbf{joba}}=\mathrm{Nag_ColpivSVrankAbs}$
Computation as with ${\mathbf{joba}}=\mathrm{Nag_ColpivRrank}$ except in the treatment of rank reduction. In this case, small singular values are to be considered as noise and, if found, the matrix is treated as numerically rank deficient. The computed SVD, $A=U\Sigma {V}^{\mathrm{T}}$, is such that the relative residual norm (when comparing against $A$) is of the order $\mathit{O}\left(m\right)×\epsilon$, where $\epsilon$ is machine precision. This gives the procedure licence to discard (set to zero) all singular values below ${\mathbf{n}}×\epsilon ×‖A‖$.
${\mathbf{joba}}=\mathrm{Nag_ColpivSVrankRel}$
Similar to ${\mathbf{joba}}=\mathrm{Nag_ColpivSVrankAbs}$. The rank revealing property of the initial $QR$ factorization is used to reveal (using the upper triangular factor) a gap, ${\sigma }_{r+1}<\epsilon {\sigma }_{r}$, in which case the numerical rank is declared to be $r$. The SVD is computed with absolute error bounds, but more accurately than with ${\mathbf{joba}}=\mathrm{Nag_ColpivSVrankAbs}$.
Constraint: ${\mathbf{joba}}=\mathrm{Nag_ColpivRrank}$, $\mathrm{Nag_ColpivRrankCond}$, $\mathrm{Nag_FullpivRrank}$, $\mathrm{Nag_FullpivRrankCond}$, $\mathrm{Nag_ColpivSVrankAbs}$ or $\mathrm{Nag_ColpivSVrankRel}$.
3: $\mathbf{jobu}$Nag_LeftVecsType Input
On entry: specifies options for computing the left singular vectors $U$.
${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$
The first $n$ left singular vectors (columns of $U$) are computed and returned in the array u.
${\mathbf{jobu}}=\mathrm{Nag_LeftVecs}$
All $m$ left singular vectors are computed and returned in the array u.
${\mathbf{jobu}}=\mathrm{Nag_NotLeftWork}$
No left singular vectors are computed, but the array u (with ${\mathbf{pdu}}\ge {\mathbf{m}}$ and second dimension at least n) is available as workspace for computing right singular values. See the description of u.
${\mathbf{jobu}}=\mathrm{Nag_NotLeftVecs}$
No left singular vectors are computed. ${\mathbf{u}}$ is not referenced when ${\mathbf{jobv}}=\mathrm{Nag_NotRightWork}$ or $\mathrm{Nag_NotRightVecs}$.
Constraint: ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$, $\mathrm{Nag_LeftVecs}$, $\mathrm{Nag_NotLeftWork}$ or $\mathrm{Nag_NotLeftVecs}$.
4: $\mathbf{jobv}$Nag_RightVecsType Input
On entry: specifies options for computing the right singular vectors $V$.
${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$
The $n$ right singular vectors (columns of $V$) are computed and returned in the array v; Jacobi rotations are not explicitly accumulated.
${\mathbf{jobv}}=\mathrm{Nag_RightVecsJRots}$
The $n$ right singular vectors (columns of $V$) are computed and returned in the array v, but they are computed as the product of Jacobi rotations. This option is allowed only if ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$ or $\mathrm{Nag_LeftVecs}$, i.e., in computing the full SVD.
This is equivalent to multiplying the input matrix, on the right, by the matrix $V$.
${\mathbf{jobv}}=\mathrm{Nag_NotRightWork}$
No right singular values are computed, but the array v (with ${\mathbf{pdv}}\ge {\mathbf{n}}$ and second dimension at least n) is available as workspace for computing left singular values. See the description of v.
${\mathbf{jobv}}=\mathrm{Nag_NotRightVecs}$
No right singular vectors are computed. ${\mathbf{v}}$ is not referenced when ${\mathbf{jobu}}=\mathrm{Nag_NotLeftWork}$ or $\mathrm{Nag_NotLeftVecs}$ or ${\mathbf{jobt}}=\mathrm{Nag_NoTrans}$ or ${\mathbf{m}}\ne {\mathbf{n}}$.
Constraints:
• ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$, $\mathrm{Nag_RightVecsJRots}$, $\mathrm{Nag_NotRightWork}$ or $\mathrm{Nag_NotRightVecs}$;
• if ${\mathbf{jobu}}=\mathrm{Nag_NotLeftWork}$ or $\mathrm{Nag_NotLeftVecs}$, ${\mathbf{jobv}}\ne \mathrm{Nag_RightVecsJRots}$.
5: $\mathbf{jobr}$Nag_ZeroCols Input
On entry: specifies the conditions under which columns of $A$ are to be set to zero. This effectively specifies a lower limit on the range of singular values; any singular values below this limit are (through column zeroing) set to zero. If $A\ne 0$ is scaled so that the largest column (in the Euclidean norm) of $cA$ is equal to the square root of the overflow threshold, then jobr allows the function to kill columns of $A$ whose norm in $cA$ is less than $\sqrt{\mathit{sfmin}}$ (for ${\mathbf{jobr}}=\mathrm{Nag_ZeroColsRestrict}$), or less than $\mathit{sfmin}/\epsilon$ (otherwise). $\mathit{sfmin}$ is the safe range parameter, as returned by function X02AMC.
${\mathbf{jobr}}=\mathrm{Nag_ZeroColsNormal}$
Only set to zero those columns of $A$ for which the norm of corresponding column of $cA<\mathit{sfmin}/\epsilon$, that is, those columns that are effectively zero (to machine precision) anyway. If the condition number of $A$ is greater than the overflow threshold $\lambda$, where $\lambda$ is the value returned by X02ALC, you are recommended to use function f08kjc.
${\mathbf{jobr}}=\mathrm{Nag_ZeroColsRestrict}$
Set to zero those columns of $A$ for which the norm of the corresponding column of $cA<\sqrt{\mathit{sfmin}}$. This approximately represents a restricted range for $\sigma \left(cA\right)$ of $\left[\sqrt{\mathit{sfmin}},\sqrt{\lambda }\right]$.
For computing the singular values in the full range from the safe minimum up to the overflow threshold use f08kjc.
Suggested value: ${\mathbf{jobr}}=\mathrm{Nag_ZeroColsRestrict}$.
Constraint: ${\mathbf{jobr}}=\mathrm{Nag_ZeroColsNormal}$ or $\mathrm{Nag_ZeroColsRestrict}$.
6: $\mathbf{jobt}$Nag_TransType Input
On entry: specifies, in the case $n=m$, whether the function is permitted to use the transpose of $A$ for improved efficiency. If the matrix is square, then the procedure may use ${A}^{\mathrm{T}}$ if it seems to be better with respect to convergence. If the matrix is not square, jobt is ignored. The decision is based on two values of entropy over the adjoint orbit of ${A}^{\mathrm{T}}A$. See the descriptions of ${\mathbf{work}}\left[5\right]$ and ${\mathbf{work}}\left[6\right]$.
${\mathbf{jobt}}=\mathrm{Nag_Trans}$
If $n=m$, perform an entropy test and, if the test indicates possibly faster convergence of the Jacobi process when using ${A}^{\mathrm{T}}$, then form the transpose ${A}^{\mathrm{T}}$. If $A$ is replaced with ${A}^{\mathrm{T}}$, then the row pivoting is included automatically.
${\mathbf{jobt}}=\mathrm{Nag_NoTrans}$
No entropy test and no transposition is performed.
The option ${\mathbf{jobt}}=\mathrm{Nag_Trans}$ can be used to compute only the singular values, or the full SVD ($U$, $\Sigma$ and $V$). In the case where only one set of singular vectors ($U$ or $V$) is required, the caller must still provide both u and v, as one of the matrices is used as workspace if the matrix $A$ is transposed. See the descriptions of u and v.
Constraint: ${\mathbf{jobt}}=\mathrm{Nag_Trans}$ or $\mathrm{Nag_NoTrans}$.
7: $\mathbf{jobp}$Nag_Perturb Input
On entry: specifies whether the function should be allowed to introduce structured perturbations to drown denormalized numbers. For details see Drmač and Veselić (2008a) and Drmač and Veselić (2008b). For the sake of simplicity, these perturbations are included only when the full SVD or only the singular values are requested.
${\mathbf{jobp}}=\mathrm{Nag_PerturbOn}$
Introduce perturbation if $A$ is found to be very badly scaled (introducing denormalized numbers).
${\mathbf{jobp}}=\mathrm{Nag_PerturbOff}$
Do not perturb.
Constraint: ${\mathbf{jobp}}=\mathrm{Nag_PerturbOn}$ or $\mathrm{Nag_PerturbOff}$.
8: $\mathbf{m}$Integer Input
On entry: $m$, the number of rows of the matrix $A$.
Constraint: ${\mathbf{m}}\ge 0$.
9: $\mathbf{n}$Integer Input
On entry: $n$, the number of columns of the matrix $A$.
Constraint: ${\mathbf{m}}\ge {\mathbf{n}}\ge 0$.
10: $\mathbf{a}\left[\mathit{dim}\right]$double Input/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×n$ matrix $A$.
On exit: the contents of a are overwritten.
11: $\mathbf{pda}$Integer Input
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)$.
12: $\mathbf{sva}\left[{\mathbf{n}}\right]$double Output
On exit: the, possibly scaled, singular values of $A$.
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 ={\mathbf{work}}\left[0\right]/{\mathbf{work}}\left[1\right]$. Normally $\alpha =1$ and no scaling is required to obtain the singular values. However, if the largest singular value of $A$ overflows or if small singular values have been saved from underflow by scaling the input matrix $A$, then $\alpha \ne 1$.
If ${\mathbf{jobr}}=\mathrm{Nag_ZeroColsRestrict}$, then some of the singular values may be returned as exact zeros because they are below the numerical rank threshold or are denormalized numbers.
13: $\mathbf{u}\left[\mathit{dim}\right]$double Output
Note: the dimension, dim, of the array u must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdu}}×{\mathbf{m}}\right)$ when ${\mathbf{jobu}}=\mathrm{Nag_LeftVecs}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdu}}×{\mathbf{n}}\right)$ when ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$ or $\mathrm{Nag_NotLeftWork}$ and ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}×{\mathbf{pdu}}\right)$ when ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$ or $\mathrm{Nag_NotLeftWork}$ and ${\mathbf{order}}=\mathrm{Nag_RowMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ otherwise.
The $\left(i,j\right)$th element of the matrix $U$ is stored in
• ${\mathbf{u}}\left[\left(j-1\right)×{\mathbf{pdu}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{u}}\left[\left(i-1\right)×{\mathbf{pdu}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On exit: if ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$, u contains the $m×n$ matrix of left singular vectors.
If ${\mathbf{jobu}}=\mathrm{Nag_LeftVecs}$, u contains the $m×m$ matrix of left singular vectors, including an orthonormal basis of the orthogonal complement of Range($A$).
u is not referenced when ${\mathbf{jobu}}=\mathrm{Nag_NotLeftWork}$ or $\mathrm{Nag_NotLeftVecs}$ and one of the following is satisfied:
• ${\mathbf{jobv}}=\mathrm{Nag_NotRightWork}$ or $\mathrm{Nag_NotRightVecs}$, or
• ${\mathbf{n}}=1$, or
• $A$ is the zero matrix.
14: $\mathbf{pdu}$Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array u.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{jobu}}=\mathrm{Nag_LeftVecs}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• if ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$ or $\mathrm{Nag_NotLeftWork}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• otherwise ${\mathbf{pdu}}\ge 1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$,
• if ${\mathbf{jobu}}=\mathrm{Nag_LeftVecs}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• if ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$ or $\mathrm{Nag_NotLeftWork}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ${\mathbf{pdu}}\ge 1$.
15: $\mathbf{v}\left[\mathit{dim}\right]$double 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{Nag_RightVecsJRots}$ or $\mathrm{Nag_NotRightWork}$;
• $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 exit: if ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$ or $\mathrm{Nag_RightVecsJRots}$, v contains the $n×n$ matrix of right singular vectors.
v is not referenced when ${\mathbf{jobv}}=\mathrm{Nag_NotRightWork}$ or $\mathrm{Nag_NotRightVecs}$ and one of the following is satisfied:
• ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$ or $\mathrm{Nag_LeftVecs}$ and ${\mathbf{jobt}}=\mathrm{Nag_Trans}$, or
• ${\mathbf{n}}=1$, or
• $A$ is the zero matrix.
16: $\mathbf{pdv}$Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array v.
Constraints:
• if ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$, $\mathrm{Nag_RightVecsJRots}$ or $\mathrm{Nag_NotRightWork}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ${\mathbf{pdv}}\ge 1$.
17: $\mathbf{work}\left[7\right]$double Output
On exit: contains information about the completed job.
${\mathbf{work}}\left[0\right]$
$\alpha ={\mathbf{work}}\left[0\right]/{\mathbf{work}}\left[1\right]$ is the scaling factor 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 the description of ${\mathbf{sva}}$.)
${\mathbf{work}}\left[1\right]$
See the description of ${\mathbf{work}}\left[0\right]$.
${\mathbf{work}}\left[2\right]$
sconda, an estimate for the condition number of column equilibrated $A$ (if ${\mathbf{joba}}=\mathrm{Nag_ColpivRrankCond}$ or $\mathrm{Nag_FullpivRrankCond}$). sconda is an estimate of $\sqrt{\left({‖{\left({R}^{\mathrm{T}}R\right)}^{-1}‖}_{1}\right)}$. It is computed using f07fgc. It satisfies ${n}^{-\frac{1}{4}}×\mathit{sconda}\le {‖{R}^{-1}‖}_{2}\le {n}^{\frac{1}{4}}×\mathit{sconda}$ where $R$ is the triangular factor from the $QR$ factorization of $A$. However, if $R$ is truncated and the numerical rank is determined to be strictly smaller than $n$, sconda is returned as $-1$, thus indicating that the smallest singular values might be lost.
If full SVD is needed, and you are familiar with the details of the method, the following two condition numbers are useful for the analysis of the algorithm.
${\mathbf{work}}\left[3\right]$
An estimate of the scaled condition number of the triangular factor in the first $QR$ factorization.
${\mathbf{work}}\left[4\right]$
An estimate of the scaled condition number of the triangular factor in the second $QR$ factorization.
The following two parameters are computed if ${\mathbf{jobt}}=\mathrm{Nag_Trans}$.
${\mathbf{work}}\left[5\right]$
The entropy of ${A}^{\mathrm{T}}A$: this is the Shannon entropy of $\mathrm{diag}{A}^{\mathrm{T}}A/\mathrm{trace}{A}^{\mathrm{T}}A$ taken as a point in the probability simplex.
${\mathbf{work}}\left[6\right]$
The entropy of $A{A}^{\mathrm{T}}$.
18: $\mathbf{iwork}\left[\mathit{dim}\right]$Integer Output
On exit: contains information about the completed job.
${\mathbf{iwork}}\left[0\right]$
The numerical rank of $A$ determined after the initial $QR$ factorization with pivoting. See the descriptions of joba and jobr.
${\mathbf{iwork}}\left[1\right]$
The number of computed nonzero singular values.
${\mathbf{iwork}}\left[2\right]$
If nonzero, a warning message. If ${\mathbf{iwork}}\left[2\right]=1$, then some of the column norms of $A$ were denormalized (tiny) numbers. The requested high accuracy is not warranted by the data.
19: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_CONSTRAINT
Constraint: ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$, $\mathrm{Nag_RightVecsJRots}$, $\mathrm{Nag_NotRightWork}$ or $\mathrm{Nag_NotRightVecs}$ and
if ${\mathbf{jobu}}=\mathrm{Nag_NotLeftWork}$ or $\mathrm{Nag_NotLeftVecs}$, ${\mathbf{jobv}}\ne \mathrm{Nag_RightVecsJRots}$.
NE_CONVERGENCE
f08khc did not converge in the allowed number of iterations ($30$). The computed values might be inaccurate.
NE_ENUM_INT_2
On entry, ${\mathbf{jobu}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{pdu}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{jobu}}=\mathrm{Nag_LeftVecs}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
if ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$ or $\mathrm{Nag_NotLeftWork}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
otherwise ${\mathbf{pdu}}\ge 1$.
On entry, ${\mathbf{jobv}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{pdv}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{jobv}}=\mathrm{Nag_RightVecs}$, $\mathrm{Nag_RightVecsJRots}$ or $\mathrm{Nag_NotRightWork}$, ${\mathbf{pdv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
otherwise ${\mathbf{pdv}}\ge 1$.
NE_ENUM_INT_3
On entry, ${\mathbf{jobu}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{pdu}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{jobu}}=\mathrm{Nag_LeftVecs}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
if ${\mathbf{jobu}}=\mathrm{Nag_LeftSpan}$ or $\mathrm{Nag_NotLeftWork}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
otherwise ${\mathbf{pdu}}\ge 1$.
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{pdu}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdu}}>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_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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.

## 7Accuracy

The computed SVD is nearly the exact SVD for a nearby matrix $\left(A+E\right)$, where
 $‖E‖2 = O(ε) ‖A‖2 ,$
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.

## 8Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
f08khc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f08khc 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

## 9Further Comments

f08khc implements a preconditioned Jacobi SVD algorithm. It uses f08aec, f08ahc and f08bfc as preprocessors and preconditioners. Optionally, an additional row pivoting can be used as a preprocessor, which in some cases results in much higher accuracy. An example is a matrix $A$ with the structure $A={D}_{1}C{D}_{2}$, where ${D}_{1}$, ${D}_{2}$ are arbitrarily ill-conditioned diagonal matrices and $C$ is a well-conditioned matrix. In that case, complete pivoting in the first $QR$ factorizations provides accuracy dependent on the condition number of $C$, and independent of ${D}_{1}$, ${D}_{2}$. Such higher accuracy is not completely understood theoretically, but it works well in practice. Further, if $A$ can be written as $A=BD$, with well-conditioned $B$ and some diagonal $D$, then the high accuracy is guaranteed, both theoretically and in software, independent of $D$.

## 10Example

This example finds the singular values and left and right singular vectors of the $6×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 the condition number of $A$ and approximate error bounds for the computed singular values and vectors.

### 10.1Program Text

Program Text (f08khce.c)

### 10.2Program Data

Program Data (f08khce.d)

### 10.3Program Results

Program Results (f08khce.r)