nag_dbdsqr (f08mec) (PDF version)
f08 Chapter Contents
f08 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_dbdsqr (f08mec)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_dbdsqr (f08mec) 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

#include <nag.h>
#include <nagf08.h>
void  nag_dbdsqr (Nag_OrderType order, Nag_UploType uplo, Integer n, Integer ncvt, Integer nru, Integer ncc, double d[], double e[], double vt[], Integer pdvt, double u[], Integer pdu, double c[], Integer pdc, NagError *fail)

3  Description

nag_dbdsqr (f08mec) 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 Σ is a diagonal matrix with real diagonal elements σi (the singular values of B), such that
σ1 σ2 σn 0 ;  
U is an orthogonal matrix whose columns are the left singular vectors ui; V is an orthogonal matrix whose rows are the right singular vectors vi. Thus
Bui = σi vi   and   BT vi = σi ui ,   i = 1,2,,n .  
To compute U and/or VT, the arrays u and/or vt must be initialized to the unit matrix before nag_dbdsqr (f08mec) is called.
The function 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=QBPT. If A is m by n with mn, then Q is m by n and PT is n by n; if A is n by p with n<p, then Q is n by n and PT is n by p. In this case, the matrices Q and/or PT must be formed explicitly by nag_dorgbr (f08kfc) and passed to nag_dbdsqr (f08mec) in the arrays u and/or vt respectively.
nag_dbdsqr (f08mec) also has the capability of forming UTC, where C is an arbitrary real matrix; this is needed when using the SVD to solve linear least squares problems.
nag_dbdsqr (f08mec) uses two different algorithms. If any singular vectors are required (i.e., if ncvt>0 or nru>0 or 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 ncvt=nru=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, 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  Arguments

1:     order Nag_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 order=Nag_RowMajor. See Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     uplo Nag_UploTypeInput
On entry: indicates whether B is an upper or lower bidiagonal matrix.
uplo=Nag_Upper
B is an upper bidiagonal matrix.
uplo=Nag_Lower
B is a lower bidiagonal matrix.
Constraint: uplo=Nag_Upper or Nag_Lower.
3:     n IntegerInput
On entry: n, the order of the matrix B.
Constraint: n0.
4:     ncvt IntegerInput
On entry: ncvt, the number of columns of the matrix VT of right singular vectors. Set ncvt=0 if no right singular vectors are required.
Constraint: ncvt0.
5:     nru IntegerInput
On entry: nru, the number of rows of the matrix U of left singular vectors. Set nru=0 if no left singular vectors are required.
Constraint: nru0.
6:     ncc IntegerInput
On entry: ncc, the number of columns of the matrix C. Set ncc=0 if no matrix C is supplied.
Constraint: ncc0.
7:     d[dim] doubleInput/Output
Note: the dimension, dim, of the array d must be at least max1,n.
On entry: the diagonal elements of the bidiagonal matrix B.
On exit: the singular values in decreasing order of magnitude, unless fail.code= NE_CONVERGENCE (in which case see Section 6).
8:     e[dim] doubleInput/Output
Note: the dimension, dim, of the array e must be at least max1,n-1.
On entry: the off-diagonal elements of the bidiagonal matrix B.
On exit: e is overwritten, but if fail.code= NE_CONVERGENCE see Section 6.
9:     vt[dim] doubleInput/Output
Note: the dimension, dim, of the array vt must be at least max1,pdvt×ncvt when order=Nag_ColMajor and at least max1,pdvt×n when order=Nag_RowMajor.
The i,jth element of the matrix is stored in
  • vt[j-1×pdvt+i-1] when order=Nag_ColMajor;
  • vt[i-1×pdvt+j-1] when order=Nag_RowMajor.
On entry: if ncvt>0, vt must contain an n by ncvt matrix. If the right singular vectors of B are required, ncvt=n and vt must contain the unit matrix; if the right singular vectors of A are required, vt must contain the orthogonal matrix PT returned by nag_dorgbr (f08kfc) with vect=Nag_FormP .
On exit: the n by ncvt matrix VT  or VTPT  of right singular vectors, stored by rows.
If ncvt=0, vt is not referenced.
10:   pdvt IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array vt.
Constraints:
  • if order=Nag_ColMajor,
    • if ncvt>0, pdvt max1,n ;
    • otherwise pdvt1;
  • if order=Nag_RowMajor,
    • if ncvt>0, pdvtncvt;
    • otherwise pdvt1.
11:   u[dim] doubleInput/Output
Note: the dimension, dim, of the array u must be at least
  • max1,pdu×n when order=Nag_ColMajor;
  • max1,nru×pdu when order=Nag_RowMajor.
The i,jth element of the matrix U is stored in
  • u[j-1×pdu+i-1] when order=Nag_ColMajor;
  • u[i-1×pdu+j-1] when order=Nag_RowMajor.
On entry: if nru>0, u must contain an nru by n matrix. If the left singular vectors of B are required, 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 nag_dorgbr (f08kfc) with vect=Nag_FormQ .
On exit: the nru by n matrix U or QU of left singular vectors, stored as columns of the matrix.
If nru=0, u is not referenced.
12:   pdu IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array u.
Constraints:
  • if order=Nag_ColMajor, pdu max1,nru ;
  • if order=Nag_RowMajor, pdumax1,n.
13:   c[dim] doubleInput/Output
Note: the dimension, dim, of the array c must be at least max1,pdc×ncc when order=Nag_ColMajor and at least max1,pdc×n when order=Nag_RowMajor.
The i,jth element of the matrix C is stored in
  • c[j-1×pdc+i-1] when order=Nag_ColMajor;
  • c[i-1×pdc+j-1] when order=Nag_RowMajor.
On entry: the n by ncc matrix C if ncc>0.
On exit: c is overwritten by the matrix UTC. If ncc=0, c is not referenced.
14:   pdc IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array c.
Constraints:
  • if order=Nag_ColMajor,
    • if ncc>0, pdc max1,n ;
    • otherwise pdc1;
  • if order=Nag_RowMajor, pdcmax1,ncc.
15:   fail NagError *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.
See Section 3.2.1.2 in the Essential Introduction for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_CONVERGENCE
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, n=value.
Constraint: n0.
On entry, ncc=value.
Constraint: ncc0.
On entry, ncvt=value.
Constraint: ncvt>0.
On entry, ncvt=value.
Constraint: ncvt0.
On entry, nru=value.
Constraint: nru0.
On entry, pdc=value.
Constraint: pdc>0.
On entry, pdu=value.
Constraint: pdu>0.
On entry, pdvt=value.
Constraint: pdvt>0.
NE_INT_2
On entry, pdc=value and ncc=value.
Constraint: pdcmax1,ncc.
On entry, pdu=value and n=value.
Constraint: pdumax1,n.
On entry, pdu=value and nru=value.
Constraint: pdu max1,nru .
On entry, pdvt=value and ncvt=value.
Constraint: if ncvt>0, pdvtncvt;
otherwise pdvt1.
NE_INT_3
On entry, ncc=value, pdc=value and n=value.
Constraint: if ncc>0, pdc max1,n ;
otherwise pdc1.
On entry, pdvt=value, ncvt=value and n=value.
Constraint: if ncvt>0, pdvt max1,n ;
otherwise pdvt1.
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.
An unexpected error has been triggered by this function. Please contact NAG.
See Section 3.6.6 in the Essential Introduction for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 3.6.5 in the Essential Introduction for further information.

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

8  Parallelism and Performance

nag_dbdsqr (f08mec) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_dbdsqr (f08mec) 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.

9  Further Comments

The total number of floating-point operations is roughly proportional to n2 if only the singular values are computed. About 6n2×nru additional operations are required to compute the left singular vectors and about 6n2×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_zbdsqr (f08msc).

10  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 nag_dorgbr (f08kfc), which illustrates the use of the function to compute the singular value decomposition of a general matrix.

10.1  Program Text

Program Text (f08mece.c)

10.2  Program Data

Program Data (f08mece.d)

10.3  Program Results

Program Results (f08mece.r)


nag_dbdsqr (f08mec) (PDF version)
f08 Chapter Contents
f08 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015