F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08MEF (DBDSQR)

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.
Warning. The specification of the parameter WORK changed at Mark 20: the length of WORK needs to be increased.

## 1  Purpose

F08MEF (DBDSQR) 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.

## 2  Specification

 SUBROUTINE F08MEF ( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U, LDU, C, LDC, WORK, INFO)
 INTEGER N, NCVT, NRU, NCC, LDVT, LDU, LDC, INFO REAL (KIND=nag_wp) D(*), E(*), VT(LDVT,*), U(LDU,*), C(LDC,*), WORK(*) CHARACTER(1) UPLO
The routine may be called by its LAPACK name dbdsqr.

## 3  Description

F08MEF (DBDSQR) 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 F08MEF (DBDSQR) is called.
The routine may also be used to compute the SVD of a real general matrix $A$ which has been reduced to bidiagonal form by an orthogonal transformation: $A=QB{P}^{\mathrm{T}}$. If $A$ is $m$ by $n$ with $m\ge n$, then $Q$ is $m$ by $n$ and ${P}^{\mathrm{T}}$ is $n$ by $n$; if $A$ is $n$ by $p$ with $n, then $Q$ is $n$ by $n$ and ${P}^{\mathrm{T}}$ is $n$ by $p$. In this case, the matrices $Q$ and/or ${P}^{\mathrm{T}}$ must be formed explicitly by F08KFF (DORGBR) and passed to F08MEF (DBDSQR) in the arrays U and/or VT respectively.
F08MEF (DBDSQR) also has the capability of forming ${U}^{\mathrm{T}}C$, where $C$ is an arbitrary real matrix; this is needed when using the SVD to solve linear least squares problems.
F08MEF (DBDSQR) 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 factor $±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  Parameters

1:     UPLO – CHARACTER(1)Input
On entry: indicates whether $B$ is an upper or lower bidiagonal matrix.
${\mathbf{UPLO}}=\text{'U'}$
$B$ is an upper bidiagonal matrix.
${\mathbf{UPLO}}=\text{'L'}$
$B$ is a lower bidiagonal matrix.
Constraint: ${\mathbf{UPLO}}=\text{'U'}$ or $\text{'L'}$.
2:     N – INTEGERInput
On entry: $n$, the order of the matrix $B$.
Constraint: ${\mathbf{N}}\ge 0$.
3:     NCVT – INTEGERInput
On entry: $\mathit{ncvt}$, the number of columns of the matrix ${V}^{\mathrm{T}}$ of right singular vectors. Set ${\mathbf{NCVT}}=0$ if no right singular vectors are required.
Constraint: ${\mathbf{NCVT}}\ge 0$.
4:     NRU – INTEGERInput
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$.
5:     NCC – INTEGERInput
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$.
6:     D($*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the dimension 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 ${\mathbf{INFO}}>{\mathbf{0}}$ (in which case see Section 6).
7:     E($*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the dimension 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 ${\mathbf{INFO}}>{\mathbf{0}}$ see Section 6.
8:     VT(LDVT,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array VT must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{NCVT}}\right)$.
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 orthogonal matrix ${P}^{\mathrm{T}}$ returned by F08KFF (DORGBR) with ${\mathbf{VECT}}=\text{'P'}$ .
On exit: the $n$ by $\mathit{ncvt}$ matrix ${V}^{\mathrm{T}}$ or ${V}^{\mathrm{T}}{P}^{\mathrm{T}}$ of right singular vectors, stored by rows.
If ${\mathbf{NCVT}}=0$, VT is not referenced.
9:     LDVT – INTEGERInput
On entry: the first dimension of the array VT as declared in the (sub)program from which F08MEF (DBDSQR) is called.
Constraints:
• if ${\mathbf{NCVT}}>0$, ${\mathbf{LDVT}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• otherwise ${\mathbf{LDVT}}\ge 1$.
10:   U(LDU,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array U must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
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 orthogonal matrix $Q$ returned by F08KFF (DORGBR) with ${\mathbf{VECT}}=\text{'Q'}$ .
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.
11:   LDU – INTEGERInput
On entry: the first dimension of the array U as declared in the (sub)program from which F08MEF (DBDSQR) is called.
Constraint: ${\mathbf{LDU}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{NRU}}\right)$.
12:   C(LDC,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array C must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{NCC}}\right)$.
On entry: the $n$ by $\mathit{ncc}$ matrix $C$ if ${\mathbf{NCC}}>0$.
On exit: C is overwritten by the matrix ${U}^{\mathrm{T}}C$. If ${\mathbf{NCC}}=0$, C is not referenced.
13:   LDC – INTEGERInput
On entry: the first dimension of the array C as declared in the (sub)program from which F08MEF (DBDSQR) is called.
Constraints:
• if ${\mathbf{NCC}}>0$, ${\mathbf{LDC}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$;
• otherwise ${\mathbf{LDC}}\ge 1$.
14:   WORK($*$) – REAL (KIND=nag_wp) arrayWorkspace
Note: the dimension of the array WORK must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,2×{\mathbf{N}}\right)$ if ${\mathbf{NCVT}}=0$ and ${\mathbf{NRU}}=0$ and ${\mathbf{NCC}}=0$, and at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,4×{\mathbf{N}}\right)$ otherwise.
15:   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$
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$.

## 7  Accuracy

Each singular value and singular vector is computed to high relative accuracy. However, the reduction to bidiagonal form (prior to calling the routine) 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 the corresponding 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 floating point operations is roughly proportional to ${n}^{2}$ if only the singular values are computed. About $6{n}^{2}×\mathit{nru}$ additional operations are required to compute the left singular vectors and about $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 routine is F08MSF (ZBDSQR).

## 9  Example

This example computes the singular value decomposition of the upper bidiagonal matrix $B$, where
 $B = 3.62 1.26 0.00 0.00 0.00 -2.41 -1.53 0.00 0.00 0.00 1.92 1.19 0.00 0.00 0.00 -1.43 .$
See also the example for F08KFF (DORGBR), which illustrates the use of the routine to compute the singular value decomposition of a general matrix.

### 9.1  Program Text

Program Text (f08mefe.f90)

### 9.2  Program Data

Program Data (f08mefe.d)

### 9.3  Program Results

Program Results (f08mefe.r)