f08 Chapter Contents
f08 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_zbdsqr (f08msc)

## 1  Purpose

nag_zbdsqr (f08msc) computes the singular value decomposition of a complex general matrix which has been reduced to bidiagonal form.

## 2  Specification

 #include #include
 void nag_zbdsqr (Nag_OrderType order, Nag_UploType uplo, Integer n, Integer ncvt, Integer nru, Integer ncc, double d[], double e[], Complex vt[], Integer pdvt, Complex u[], Integer pdu, Complex c[], Integer pdc, NagError *fail)

## 3  Description

nag_zbdsqr (f08msc) computes the singular values and, optionally, the left or right singular vectors of a real upper or lower bidiagonal matrix $B$. In other words, it can compute the singular value decomposition (SVD) of $B$ as
 $B = U Σ VT .$
Here $\Sigma$ is a diagonal matrix with real diagonal elements ${\sigma }_{i}$ (the singular values of $B$), such that
 $σ1 ≥ σ2 ≥ ⋯ ≥ σn ≥ 0 ;$
$U$ is an orthogonal matrix whose columns are the left singular vectors ${u}_{i}$; $V$ is an orthogonal matrix whose rows are the right singular vectors ${v}_{i}$. Thus
 $Bui = σi vi and BT vi = σi ui , i = 1,2,…,n .$
To compute $U$ and/or ${V}^{\mathrm{T}}$, the arrays u and/or vt must be initialized to the unit matrix before nag_zbdsqr (f08msc) is called.
The function stores the real orthogonal matrices $U$ and ${V}^{\mathrm{T}}$ in complex arrays u and vt, so that it may also be used to compute the SVD of a complex general matrix $A$ which has been reduced to bidiagonal form by a unitary transformation: $A=QB{P}^{\mathrm{H}}$. If $A$ is $m$ by $n$ with $m\ge n$, then $Q$ is $m$ by $n$ and ${P}^{\mathrm{H}}$ is $n$ by $n$; if $A$ is $n$ by $p$ with $n, then $Q$ is $n$ by $n$ and ${P}^{\mathrm{H}}$ is $n$ by $p$. In this case, the matrices $Q$ and/or ${P}^{\mathrm{H}}$ must be formed explicitly by nag_zungbr (f08ktc) and passed to nag_zbdsqr (f08msc) in the arrays u and/or vt respectively.
nag_zbdsqr (f08msc) also has the capability of forming ${U}^{\mathrm{H}}C$, where $C$ is an arbitrary complex matrix; this is needed when using the SVD to solve linear least squares problems.
nag_zbdsqr (f08msc) uses two different algorithms. If any singular vectors are required (i.e., if ${\mathbf{ncvt}}>0$ or ${\mathbf{nru}}>0$ or ${\mathbf{ncc}}>0$), the bidiagonal $QR$ algorithm is used, switching between zero-shift and implicitly shifted forms to preserve the accuracy of small singular values, and switching between $QR$ and $QL$ variants in order to handle graded matrices effectively (see Demmel and Kahan (1990)). If only singular values are required (i.e., if ${\mathbf{ncvt}}={\mathbf{nru}}={\mathbf{ncc}}=0$), they are computed by the differential qd algorithm (see Fernando and Parlett (1994)), which is faster and can achieve even greater accuracy.
The singular vectors are normalized so that $‖{u}_{i}‖=‖{v}_{i}‖=1$, but are determined only to within a complex factor of absolute value $1$.

## 4  References

Demmel J W and Kahan W (1990) Accurate singular values of bidiagonal matrices SIAM J. Sci. Statist. Comput. 11 873–912
Fernando K V and Parlett B N (1994) Accurate singular values and differential qd algorithms Numer. Math. 67 191–229
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 Nag_ColMajor.
2:     uploNag_UploTypeInput
On entry: indicates whether $B$ is an upper or lower bidiagonal matrix.
${\mathbf{uplo}}=\mathrm{Nag_Upper}$
$B$ is an upper bidiagonal matrix.
${\mathbf{uplo}}=\mathrm{Nag_Lower}$
$B$ is a lower bidiagonal matrix.
Constraint: ${\mathbf{uplo}}=\mathrm{Nag_Upper}$ or $\mathrm{Nag_Lower}$.
3:     nIntegerInput
On entry: $n$, the order of the matrix $B$.
Constraint: ${\mathbf{n}}\ge 0$.
4:     ncvtIntegerInput
On entry: $\mathit{ncvt}$, the number of columns of the matrix ${V}^{\mathrm{H}}$${\mathbf{ncvt}}=0$ of right singular vectors. Set ${\mathbf{ncvt}}=0$ if no right singular vectors are required.
Constraint: ${\mathbf{ncvt}}\ge 0$.
5:     nruIntegerInput
On entry: $\mathit{nru}$, the number of rows of the matrix $U$ of left singular vectors. Set ${\mathbf{nru}}=0$ if no left singular vectors are required.
Constraint: ${\mathbf{nru}}\ge 0$.
6:     nccIntegerInput
On entry: $\mathit{ncc}$, the number of columns of the matrix $C$. Set ${\mathbf{ncc}}=0$ if no matrix $C$ is supplied.
Constraint: ${\mathbf{ncc}}\ge 0$.
7:     d[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array d must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the diagonal elements of the bidiagonal matrix $B$.
On exit: the singular values in decreasing order of magnitude, unless NE_CONVERGENCE (in which case see Section 6).
8:     e[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array e must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}-1\right)$.
On entry: the off-diagonal elements of the bidiagonal matrix $B$.
On exit: e is overwritten, but if NE_CONVERGENCE see Section 6.
9:     vt[$\mathit{dim}$]ComplexInput/Output
Note: the dimension, dim, of the array vt must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdvt}}×{\mathbf{ncvt}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$ and at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdvt}}×{\mathbf{n}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
The $\left(i,j\right)$th element of the matrix is stored in
• ${\mathbf{vt}}\left[\left(j-1\right)×{\mathbf{pdvt}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{vt}}\left[\left(i-1\right)×{\mathbf{pdvt}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: if ${\mathbf{ncvt}}>0$, vt must contain an $n$ by $\mathit{ncvt}$ matrix. If the right singular vectors of $B$ are required, $\mathit{ncvt}=n$ and vt must contain the unit matrix; if the right singular vectors of $A$ are required, vt must contain the unitary matrix ${P}^{\mathrm{H}}$ returned by nag_zungbr (f08ktc) with ${\mathbf{vect}}=\mathrm{Nag_FormP}$ .
On exit: the $n$ by $\mathit{ncvt}$ matrix ${V}^{\mathrm{H}}$ or ${V}^{\mathrm{H}}$ of right singular vectors, stored by rows.
If ${\mathbf{ncvt}}=0$, vt is not referenced.
10:   pdvtIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array vt.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{ncvt}}>0$, ${\mathbf{pdvt}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ${\mathbf{pdvt}}\ge 1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$,
• if ${\mathbf{ncvt}}>0$, ${\mathbf{pdvt}}\ge {\mathbf{ncvt}}$;
• otherwise ${\mathbf{pdvt}}\ge 1$.
11:   u[$\mathit{dim}$]ComplexInput/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{n}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nru}}×{\mathbf{pdu}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
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 entry: if ${\mathbf{nru}}>0$, u must contain an $\mathit{nru}$ by $n$ matrix. If the left singular vectors of $B$ are required, $\mathit{nru}=n$ and u must contain the unit matrix; if the left singular vectors of $A$ are required, u must contain the unitary matrix $Q$ returned by nag_zungbr (f08ktc) with ${\mathbf{vect}}=\mathrm{Nag_FormQ}$ .
On exit: the $\mathit{nru}$ by $n$ matrix $U$ or $QU$ of left singular vectors, stored as columns of the matrix.
If ${\mathbf{nru}}=0$, u is not referenced.
12:   pduIntegerInput
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}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nru}}\right)$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
13:   c[$\mathit{dim}$]ComplexInput/Output
Note: the dimension, dim, of the array c must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdc}}×{\mathbf{ncc}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$ and at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdc}}×{\mathbf{n}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
The $\left(i,j\right)$th element of the matrix $C$ is stored in
• ${\mathbf{c}}\left[\left(j-1\right)×{\mathbf{pdc}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{c}}\left[\left(i-1\right)×{\mathbf{pdc}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the $n$ by $\mathit{ncc}$ matrix $C$ if ${\mathbf{ncc}}>0$.
On exit: c is overwritten by the matrix ${U}^{\mathrm{H}}C$. If ${\mathbf{ncc}}=0$, c is not referenced.
14:   pdcIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array c.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{ncc}}>0$, ${\mathbf{pdc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ${\mathbf{pdc}}\ge 1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncc}}\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.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_CONVERGENCE
$〈\mathit{\text{value}}〉$ off-diagonals did not converge. The arrays d and e contain the diagonal and off-diagonal elements, respectively, of a bidiagonal matrix orthogonally equivalent to $B$.
NE_INT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{ncc}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ncc}}\ge 0$.
On entry, ${\mathbf{ncvt}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ncvt}}\ge 0$.
On entry, ${\mathbf{nru}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nru}}\ge 0$.
On entry, ${\mathbf{pdc}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdc}}>0$.
On entry, ${\mathbf{pdu}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdu}}>0$.
On entry, ${\mathbf{pdvt}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdvt}}>0$.
NE_INT_2
On entry, ${\mathbf{ncvt}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ncvt}}>0$.
On entry, ${\mathbf{pdc}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ncc}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncc}}\right)$.
On entry, ${\mathbf{pdu}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{pdu}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nru}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nru}}\right)$.
NE_INT_3
On entry, ${\mathbf{ncc}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdc}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{ncc}}>0$, ${\mathbf{pdc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
otherwise ${\mathbf{pdc}}\ge 1$.
On entry, ${\mathbf{pdvt}}=〈\mathit{\text{value}}〉$, ${\mathbf{ncvt}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{ncvt}}>0$, ${\mathbf{pdvt}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
otherwise ${\mathbf{pdvt}}\ge 1$.
On entry, ${\mathbf{pdvt}}=〈\mathit{\text{value}}〉$, ${\mathbf{ncvt}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{ncvt}}>0$, ${\mathbf{pdvt}}\ge {\mathbf{ncvt}}$;
otherwise ${\mathbf{pdvt}}\ge 1$.
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

Each singular value and singular vector is computed to high relative accuracy. However, the reduction to bidiagonal form (prior to calling the function) may exclude the possibility of obtaining high relative accuracy in the small singular values of the original matrix if its singular values vary widely in magnitude.
If ${\sigma }_{i}$ is an exact singular value of $B$ and ${\stackrel{~}{\sigma }}_{i}$ is the corresponding computed value, then
 $σ~i - σi ≤ p m,n ε σi$
where $p\left(m,n\right)$ is a modestly increasing function of $m$ and $n$, and $\epsilon$ is the machine precision. If only singular values are computed, they are computed more accurately (i.e., the function $p\left(m,n\right)$ is smaller), than when some singular vectors are also computed.
If ${u}_{i}$ is an exact left singular vector of $B$, and ${\stackrel{~}{u}}_{i}$ is the corresponding computed left singular vector, then the angle $\theta \left({\stackrel{~}{u}}_{i},{u}_{i}\right)$ between them is bounded as follows:
 $θ u~i,ui ≤ p m,n ε relgapi$
where ${\mathit{relgap}}_{i}$ is the relative gap between ${\sigma }_{i}$ and the other singular values, defined by
 $relgapi = min i≠j σi - σj σi + σj .$
A similar error bound holds for the right singular vectors.

The total number of real floating point operations is roughly proportional to ${n}^{2}$ if only the singular values are computed. About $12{n}^{2}×\mathit{nru}$ additional operations are required to compute the left singular vectors and about $12{n}^{2}×\mathit{ncvt}$ to compute the right singular vectors. The operations to compute the singular values must all be performed in scalar mode; the additional operations to compute the singular vectors can be vectorized and on some machines may be performed much faster.