# NAG FL Interfacef08mdf (dbdsdc)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

f08mdf computes the singular values and, optionally, the left and right singular vectors of a real $n×n$ (upper or lower) bidiagonal matrix $B$.

## 2Specification

Fortran Interface
 Subroutine f08mdf ( uplo, n, d, e, u, ldu, vt, ldvt, q, iq, work, info)
 Integer, Intent (In) :: n, ldu, ldvt Integer, Intent (Inout) :: iq(*) Integer, Intent (Out) :: iwork(8*n), info Real (Kind=nag_wp), Intent (Inout) :: d(*), e(*), u(ldu,*), vt(ldvt,*), q(*), work(*) Character (1), Intent (In) :: uplo, compq
#include <nag.h>
 void f08mdf_ (const char *uplo, const char *compq, const Integer *n, double d[], double e[], double u[], const Integer *ldu, double vt[], const Integer *ldvt, double q[], Integer iq[], double work[], Integer iwork[], Integer *info, const Charlen length_uplo, const Charlen length_compq)
The routine may be called by the names f08mdf, nagf_lapackeig_dbdsdc or its LAPACK name dbdsdc.

## 3Description

f08mdf computes the singular value decomposition (SVD) of the (upper or lower) bidiagonal matrix $B$ as
 $B = USVT ,$
where $S$ is a diagonal matrix with non-negative diagonal elements ${s}_{ii}={s}_{i}$, such that
 $s1 ≥ s2 ≥ ⋯ ≥ sn ≥ 0 ,$
and $U$ and $V$ are orthogonal matrices. The diagonal elements of $S$ are the singular values of $B$ and the columns of $U$ and $V$ are respectively the corresponding left and right singular vectors of $B$.
When only singular values are required the routine uses the $QR$ algorithm, but when singular vectors are required a divide and conquer method is used. The singular values can optionally be returned in compact form, although currently no routine is available to apply $U$ or $V$ when stored in compact form.
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
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5Arguments

1: $\mathbf{uplo}$Character(1) Input
On entry: indicates whether $B$ is upper or lower bidiagonal.
${\mathbf{uplo}}=\text{'U'}$
$B$ is upper bidiagonal.
${\mathbf{uplo}}=\text{'L'}$
$B$ is lower bidiagonal.
Constraint: ${\mathbf{uplo}}=\text{'U'}$ or $\text{'L'}$.
2: $\mathbf{compq}$Character(1) Input
On entry: specifies whether singular vectors are to be computed.
${\mathbf{compq}}=\text{'N'}$
Compute singular values only.
${\mathbf{compq}}=\text{'P'}$
Compute singular values and compute singular vectors in compact form.
${\mathbf{compq}}=\text{'I'}$
Compute singular values and singular vectors.
Constraint: ${\mathbf{compq}}=\text{'N'}$, $\text{'P'}$ or $\text{'I'}$.
3: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrix $B$.
Constraint: ${\mathbf{n}}\ge 0$.
4: $\mathbf{d}\left(*\right)$Real (Kind=nag_wp) array Input/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 $n$ diagonal elements of the bidiagonal matrix $B$.
On exit: if ${\mathbf{info}}={\mathbf{0}}$, the singular values of $B$.
5: $\mathbf{e}\left(*\right)$Real (Kind=nag_wp) array Input/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 $\left(n-1\right)$ off-diagonal elements of the bidiagonal matrix $B$.
On exit: the contents of e are destroyed.
6: $\mathbf{u}\left({\mathbf{ldu}},*\right)$Real (Kind=nag_wp) array 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)$ if ${\mathbf{compq}}=\text{'I'}$.
On exit: if ${\mathbf{compq}}=\text{'I'}$, then if ${\mathbf{info}}={\mathbf{0}}$, u contains the left singular vectors of the bidiagonal matrix $B$.
If ${\mathbf{compq}}\ne \text{'I'}$, u is not referenced.
7: $\mathbf{ldu}$Integer Input
On entry: the first dimension of the array u as declared in the (sub)program from which f08mdf is called.
Constraints:
• if ${\mathbf{compq}}=\text{'I'}$, ${\mathbf{ldu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ${\mathbf{ldu}}\ge 1$.
8: $\mathbf{vt}\left({\mathbf{ldvt}},*\right)$Real (Kind=nag_wp) array Output
Note: the second dimension of the array vt must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{compq}}=\text{'I'}$.
On exit: if ${\mathbf{compq}}=\text{'I'}$, then if ${\mathbf{info}}={\mathbf{0}}$, the rows of vt contain the right singular vectors of the bidiagonal matrix $B$.
If ${\mathbf{compq}}\ne \text{'I'}$, vt is not referenced.
9: $\mathbf{ldvt}$Integer Input
On entry: the first dimension of the array vt as declared in the (sub)program from which f08mdf is called.
Constraints:
• if ${\mathbf{compq}}=\text{'I'}$, ${\mathbf{ldvt}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ${\mathbf{ldvt}}\ge 1$.
10: $\mathbf{q}\left(*\right)$Real (Kind=nag_wp) array Output
Note: the dimension of the array q must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{{\mathbf{n}}}^{2}+5{\mathbf{n}},\mathit{ldq}\right)$.
On exit: if ${\mathbf{compq}}=\text{'P'}$, then if ${\mathbf{info}}={\mathbf{0}}$, q and iq contain the left and right singular vectors in a compact form, requiring $\mathit{O}\left({\mathbf{n}}{\mathrm{log}}_{2}{\mathbf{n}}\right)$ space instead of $2×{{\mathbf{n}}}^{2}$. In particular, q contains all the real data in the first $\mathit{ldq}={\mathbf{n}}×\left(11+2×\mathit{smlsiz}+8×\mathrm{int}\left({\mathrm{log}}_{2}\left({\mathbf{n}}/\left(\mathit{smlsiz}+1\right)\right)\right)\right)$ elements of q, where $\mathit{smlsiz}$ is equal to the maximum size of the subproblems at the bottom of the computation tree (usually about $25$).
If ${\mathbf{compq}}\ne \text{'P'}$, q is not referenced.
11: $\mathbf{iq}\left(*\right)$Integer array Output
Note: the dimension of the array iq must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathit{ldiq}\right)$.
On exit: if ${\mathbf{compq}}=\text{'P'}$, then if ${\mathbf{info}}={\mathbf{0}}$, q and iq contain the left and right singular vectors in a compact form, requiring $\mathit{O}\left({\mathbf{n}}{\mathrm{log}}_{2}{\mathbf{n}}\right)$ space instead of $2×{{\mathbf{n}}}^{2}$. In particular, iq contains all integer data in the first $\mathit{ldiq}={\mathbf{n}}×\left(3+3×\mathrm{int}\left({\mathrm{log}}_{2}\left({\mathbf{n}}/\left(\mathit{smlsiz}+1\right)\right)\right)\right)$ elements of iq, where $\mathit{smlsiz}$ is equal to the maximum size of the subproblems at the bottom of the computation tree (usually about $25$).
If ${\mathbf{compq}}\ne \text{'P'}$, iq is not referenced.
12: $\mathbf{work}\left(*\right)$Real (Kind=nag_wp) array Workspace
Note: the dimension of the array work must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,6×{\mathbf{n}}-2\right)$ if ${\mathbf{compq}}=\text{'N'}$, $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,6×{\mathbf{n}}\right)$ if ${\mathbf{compq}}=\text{'P'}$, $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,3×{{\mathbf{n}}}^{2}+4×{\mathbf{n}}\right)$ if ${\mathbf{compq}}=\text{'I'}$, and at least $1$ otherwise.
13: $\mathbf{iwork}\left(8×{\mathbf{n}}\right)$Integer array Workspace
14: $\mathbf{info}$Integer Output
On exit: ${\mathbf{info}}=0$ unless the routine detects an error (see Section 6).

## 6Error Indicators and Warnings

${\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 compute a singular value. The update process of divide-and-conquer failed.

## 7Accuracy

Each computed singular value of $B$ is accurate to nearly full relative precision, no matter how tiny the singular value. The $i$th computed singular value, ${\stackrel{^}{s}}_{i}$, satisfies the bound
 $|s^i-si| ≤ p(n)εsi$
where $\epsilon$ is the machine precision and $p\left(n\right)$ is a modest function of $n$.
For bounds on the computed singular values, see Section 4.9.1 of Anderson et al. (1999). See also f08flf.

## 8Parallelism and Performance

f08mdf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f08mdf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

If only singular values are required, the total number of floating-point operations is approximately proportional to ${n}^{2}$. When singular vectors are required the number of operations is bounded above by approximately the same number of operations as f08mef, but for large matrices f08mdf is usually much faster.
There is no complex analogue of f08mdf.

## 10Example

This example computes the singular value decomposition of the upper bidiagonal matrix
 $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 ) .$

### 10.1Program Text

Program Text (f08mdfe.f90)

### 10.2Program Data

Program Data (f08mdfe.d)

### 10.3Program Results

Program Results (f08mdfe.r)