Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_lapack_dbdsqr (f08me)

## Purpose

nag_lapack_dbdsqr (f08me) computes the singular value decomposition of a real upper or lower bidiagonal matrix, or of a real general matrix which has been reduced to bidiagonal form.

## Syntax

[d, e, vt, u, c, info] = f08me(uplo, d, e, vt, u, c, 'n', n, 'ncvt', ncvt, 'nru', nru, 'ncc', ncc)
[d, e, vt, u, c, info] = nag_lapack_dbdsqr(uplo, d, e, vt, u, c, 'n', n, 'ncvt', ncvt, 'nru', nru, 'ncc', ncc)

## Description

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

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

## Parameters

### Compulsory Input Parameters

1:     uplo – string (length ≥ 1)
Indicates whether B$B$ is an upper or lower bidiagonal matrix.
uplo = 'U'${\mathbf{uplo}}=\text{'U'}$
B$B$ is an upper bidiagonal matrix.
uplo = 'L'${\mathbf{uplo}}=\text{'L'}$
B$B$ is a lower bidiagonal matrix.
Constraint: uplo = 'U'${\mathbf{uplo}}=\text{'U'}$ or 'L'$\text{'L'}$.
2:     d( : $:$) – double array
Note: the dimension of the array d must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The diagonal elements of the bidiagonal matrix B$B$.
3:     e( : $:$) – double array
Note: the dimension of the array e must be at least max (1,n1)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}-1\right)$.
The off-diagonal elements of the bidiagonal matrix B$B$.
4:     vt(ldvt, : $:$) – double array
The first dimension, ldvt, of the array vt must satisfy
• if ncvt > 0${\mathbf{ncvt}}>0$, ldvt max (1,n) $\mathit{ldvt}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ldvt1$\mathit{ldvt}\ge 1$.
The second dimension of the array must be at least max (1,ncvt)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncvt}}\right)$
If ncvt > 0${\mathbf{ncvt}}>0$, vt must contain an n$n$ by ncvt$\mathit{ncvt}$ matrix. If the right singular vectors of B$B$ are required, ncvt = n$\mathit{ncvt}=n$ and vt must contain the unit matrix; if the right singular vectors of A$A$ are required, vt must contain the orthogonal matrix PT${P}^{\mathrm{T}}$ returned by nag_lapack_dorgbr (f08kf) with vect = 'P'${\mathbf{vect}}=\text{'P'}$ .
5:     u(ldu, : $:$) – double array
The first dimension of the array u must be at least max (1,nru)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nru}}\right)$
The second dimension of the array must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
If nru > 0${\mathbf{nru}}>0$, u must contain an nru$\mathit{nru}$ by n$n$ matrix. If the left singular vectors of B$B$ are required, nru = n$\mathit{nru}=n$ and u must contain the unit matrix; if the left singular vectors of A$A$ are required, u must contain the orthogonal matrix Q$Q$ returned by nag_lapack_dorgbr (f08kf) with vect = 'Q'${\mathbf{vect}}=\text{'Q'}$ .
6:     c(ldc, : $:$) – double array
The first dimension, ldc, of the array c must satisfy
• if ncc > 0${\mathbf{ncc}}>0$, ldc max (1,n) $\mathit{ldc}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ldc1$\mathit{ldc}\ge 1$.
The second dimension of the array must be at least max (1,ncc)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncc}}\right)$
The n$n$ by ncc$\mathit{ncc}$ matrix C$C$ if ncc > 0${\mathbf{ncc}}>0$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays d, u.
n$n$, the order of the matrix B$B$.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     ncvt – int64int32nag_int scalar
Default: The second dimension of the array vt.
ncvt$\mathit{ncvt}$, the number of columns of the matrix VT${V}^{\mathrm{T}}$ of right singular vectors. Set ncvt = 0${\mathbf{ncvt}}=0$ if no right singular vectors are required.
Constraint: ncvt0${\mathbf{ncvt}}\ge 0$.
3:     nru – int64int32nag_int scalar
Default: The first dimension of the array u.
nru$\mathit{nru}$, the number of rows of the matrix U$U$ of left singular vectors. Set nru = 0${\mathbf{nru}}=0$ if no left singular vectors are required.
Constraint: nru0${\mathbf{nru}}\ge 0$.
4:     ncc – int64int32nag_int scalar
Default: The second dimension of the array c.
ncc$\mathit{ncc}$, the number of columns of the matrix C$C$. Set ncc = 0${\mathbf{ncc}}=0$ if no matrix C$C$ is supplied.
Constraint: ncc0${\mathbf{ncc}}\ge 0$.

### Input Parameters Omitted from the MATLAB Interface

ldvt ldu ldc work

### Output Parameters

1:     d( : $:$) – double array
Note: the dimension of the array d must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The singular values in decreasing order of magnitude, unless ${\mathbf{INFO}}>{\mathbf{0}}$ (in which case see Section [Error Indicators and Warnings]).
2:     e( : $:$) – double array
Note: the dimension of the array e must be at least max (1,n1)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}-1\right)$.
e is overwritten, but if ${\mathbf{INFO}}>{\mathbf{0}}$ see Section [Error Indicators and Warnings].
3:     vt(ldvt, : $:$) – double array
The first dimension, ldvt, of the array vt will be
• if ncvt > 0${\mathbf{ncvt}}>0$, ldvt max (1,n) $\mathit{ldvt}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ldvt1$\mathit{ldvt}\ge 1$.
The second dimension of the array will be max (1,ncvt)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncvt}}\right)$
The n$n$ by ncvt$\mathit{ncvt}$ matrix VT ${V}^{\mathrm{T}}$ or VTPT ${V}^{\mathrm{T}}{P}^{\mathrm{T}}$ of right singular vectors, stored by rows.
If ncvt = 0${\mathbf{ncvt}}=0$, vt is not referenced.
4:     u(ldu, : $:$) – double array
The first dimension of the array u will be max (1,nru)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nru}}\right)$
The second dimension of the array will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
ldu max (1,nru) $\mathit{ldu}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nru}}\right)$.
The nru$\mathit{nru}$ by n$n$ matrix U$U$ or QU$QU$ of left singular vectors, stored as columns of the matrix.
If nru = 0${\mathbf{nru}}=0$, u is not referenced.
5:     c(ldc, : $:$) – double array
The first dimension, ldc, of the array c will be
• if ncc > 0${\mathbf{ncc}}>0$, ldc max (1,n) $\mathit{ldc}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ldc1$\mathit{ldc}\ge 1$.
The second dimension of the array will be max (1,ncc)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncc}}\right)$
c stores the matrix UTC${U}^{\mathrm{T}}C$. If ncc = 0${\mathbf{ncc}}=0$, c is not referenced.
6:     info – int64int32nag_int scalar
info = 0${\mathbf{info}}=0$ unless the function detects an error (see Section [Error Indicators and Warnings]).

## Error Indicators and Warnings

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

info = i${\mathbf{info}}=-i$
If info = i${\mathbf{info}}=-i$, parameter i$i$ had an illegal value on entry. The parameters are numbered as follows:
1: uplo, 2: n, 3: ncvt, 4: nru, 5: ncc, 6: d, 7: e, 8: vt, 9: ldvt, 10: u, 11: ldu, 12: c, 13: ldc, 14: work, 15: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.
W INFO > 0${\mathbf{INFO}}>0$
The algorithm failed to converge and info specifies how many off-diagonals did not converge. In this case, d and e contain on exit the diagonal and off-diagonal elements, respectively, of a bidiagonal matrix orthogonally equivalent to B$B$.

## 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 σi${\sigma }_{i}$ is an exact singular value of B$B$ and σ̃i${\stackrel{~}{\sigma }}_{i}$ is the corresponding computed value, then
 |σ̃i − σi| ≤ p (m,n) ε σi $| σ~i - σi | ≤ p (m,n) ε σi$
where p(m,n)$p\left(m,n\right)$ is a modestly increasing function of m$m$ and n$n$, and ε$\epsilon$ is the machine precision. If only singular values are computed, they are computed more accurately (i.e., the function p(m,n)$p\left(m,n\right)$ is smaller), than when some singular vectors are also computed.
If ui${u}_{i}$ is the corresponding exact left singular vector of B$B$, and i${\stackrel{~}{u}}_{i}$ is the corresponding computed left singular vector, then the angle θ(i,ui)$\theta \left({\stackrel{~}{u}}_{i},{u}_{i}\right)$ between them is bounded as follows:
 θ (ũi,ui) ≤ ( p (m,n) ε )/(relgapi) $θ (u~i,ui) ≤ p (m,n) ε relgapi$
where relgapi${\mathit{relgap}}_{i}$ is the relative gap between σi${\sigma }_{i}$ and the other singular values, defined by
 relgapi = min ( |σi − σj| )/((σi + σj)). i ≠ j
$relgapi = min i≠j | σi - σj | ( σi + σj ) .$
A similar error bound holds for the right singular vectors.

The total number of floating point operations is roughly proportional to n2${n}^{2}$ if only the singular values are computed. About 6n2 × nru$6{n}^{2}×\mathit{nru}$ additional operations are required to compute the left singular vectors and about 6n2 × ncvt$6{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.
The complex analogue of this function is nag_lapack_zbdsqr (f08ms).

## Example

function nag_lapack_dbdsqr_example
uplo = 'U';
d = [3.62;
-2.41;
1.92;
-1.43];
e = [1.26;
-1.53;
1.19];
vt = [1, 0, 0, 0;
0, 1, 0, 0;
0, 0, 1, 0;
0, 0, 0, 1];
u = [1, 0, 0, 0;
0, 1, 0, 0;
0, 0, 1, 0;
0, 0, 0, 1];
c = [];
[dOut, eOut, vtOut, uOut, cOut, info] = nag_lapack_dbdsqr(uplo, d, e, vt, u, c)

dOut =

4.0001
3.0006
1.9960
0.9998

eOut =

0
0
0

vtOut =

0.8261    0.5246    0.2024    0.0369
0.4512   -0.4056   -0.7350   -0.3030
0.2823   -0.5644    0.1731    0.7561
0.1852   -0.4916    0.6236   -0.5789

uOut =

0.9129    0.3740    0.1556    0.0512
-0.3935    0.7005    0.5489    0.2307
0.1081   -0.5904    0.6173    0.5086
-0.0132    0.1444   -0.5417    0.8280

cOut =

[]

info =

0

function f08me_example
uplo = 'U';
d = [3.62;
-2.41;
1.92;
-1.43];
e = [1.26;
-1.53;
1.19];
vt = [1, 0, 0, 0;
0, 1, 0, 0;
0, 0, 1, 0;
0, 0, 0, 1];
u = [1, 0, 0, 0;
0, 1, 0, 0;
0, 0, 1, 0;
0, 0, 0, 1];
c = [];
[dOut, eOut, vtOut, uOut, cOut, info] = f08me(uplo, d, e, vt, u, c)

dOut =

4.0001
3.0006
1.9960
0.9998

eOut =

0
0
0

vtOut =

0.8261    0.5246    0.2024    0.0369
0.4512   -0.4056   -0.7350   -0.3030
0.2823   -0.5644    0.1731    0.7561
0.1852   -0.4916    0.6236   -0.5789

uOut =

0.9129    0.3740    0.1556    0.0512
-0.3935    0.7005    0.5489    0.2307
0.1081   -0.5904    0.6173    0.5086
-0.0132    0.1444   -0.5417    0.8280

cOut =

[]

info =

0