NAG Library Routine Document

f02wuf  (real_triang_svd)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

f02wuf returns all, or part, of the singular value decomposition of a real upper triangular matrix.

2
Specification

Fortran Interface
Subroutine f02wuf ( n, a, lda, ncolb, b, ldb, wantq, q, ldq, sv, wantp, work, ifail)
Integer, Intent (In):: n, lda, ncolb, ldb, ldq
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (Inout):: a(lda,*), b(ldb,*), q(ldq,*), work(*)
Real (Kind=nag_wp), Intent (Out):: sv(n)
Logical, Intent (In):: wantq, wantp
C Header Interface
#include nagmk26.h
void  f02wuf_ ( const Integer *n, double a[], const Integer *lda, const Integer *ncolb, double b[], const Integer *ldb, const logical *wantq, double q[], const Integer *ldq, double sv[], const logical *wantp, double work[], Integer *ifail)

3
Description

The n by n upper triangular matrix R is factorized as
R=QSPT,  
where Q and P are n by n orthogonal matrices and S is an n by n diagonal matrix with non-negative diagonal elements, σ1,σ2,,σn, ordered such that
σ1σ2σn0.  
The columns of Q are the left-hand singular vectors of R, the diagonal elements of S are the singular values of R and the columns of P are the right-hand singular vectors of R.
Either or both of Q and PT may be requested and the matrix C given by
C=QTB,  
where B is an n by ncolb given matrix, may also be requested.
The routine obtains the singular value decomposition by first reducing R to bidiagonal form by means of Givens plane rotations and then using the QR algorithm to obtain the singular value decomposition of the bidiagonal form.
Good background descriptions to the singular value decomposition are given in Chan (1982), Dongarra et al. (1979), Golub and Van Loan (1996), Hammarling (1985) and Wilkinson (1978).
Note that if K is any orthogonal diagonal matrix so that
KKT=I  
(that is the diagonal elements of K are +1 or -1) then
A=QKSPKT  
is also a singular value decomposition of A.

4
References

Chan T F (1982) An improved algorithm for computing the singular value decomposition ACM Trans. Math. Software 8 72–83
Dongarra J J, Moler C B, Bunch J R and Stewart G W (1979) LINPACK Users' Guide SIAM, Philadelphia
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Hammarling S (1985) The singular value decomposition in multivariate statistics SIGNUM Newsl. 20(3) 2–25
Wilkinson J H (1978) Singular Value Decomposition – Basic Aspects Numerical Software – Needs and Availability (ed D A H Jacobs) Academic Press

5
Arguments

1:     n – IntegerInput
On entry: n, the order of the matrix R.
If n=0, an immediate return is effected.
Constraint: n0.
2:     alda* – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array a must be at least max1,n.
On entry: the leading n by n upper triangular part of the array a must contain the upper triangular matrix R.
On exit: if wantp=.TRUE., the n by n part of a will contain the n by n orthogonal matrix PT, otherwise the n by n upper triangular part of a is used as internal workspace, but the strictly lower triangular part of a is not referenced.
3:     lda – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f02wuf is called.
Constraint: ldamax1,n.
4:     ncolb – IntegerInput
On entry: ncolb, the number of columns of the matrix B.
If ncolb=0, the array b is not referenced.
Constraint: ncolb0.
5:     bldb* – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array b must be at least max1,ncolb.
On entry: with ncolb>0, the leading n by ncolb part of the array b must contain the matrix to be transformed.
On exit: the leading n by ncolb part of the array b is overwritten by the matrix QTB.
6:     ldb – IntegerInput
On entry: the first dimension of the array b as declared in the (sub)program from which f02wuf is called.
Constraints:
  • if ncolb>0, ldbmax1,n;
  • otherwise ldb1.
7:     wantq – LogicalInput
On entry: must be .TRUE. if the matrix Q is required.
If wantq=.FALSE., the array q is not referenced.
8:     qldq* – Real (Kind=nag_wp) arrayOutput
Note: the second dimension of the array q must be at least max1,n if wantq=.TRUE., and at least 1 otherwise.
On exit: with wantq=.TRUE., the leading n by n part of the array q will contain the orthogonal matrix Q. Otherwise the array q is not referenced.
9:     ldq – IntegerInput
On entry: the first dimension of the array q as declared in the (sub)program from which f02wuf is called.
Constraints:
  • if wantq=.TRUE., ldqmax1,n;
  • otherwise ldq1.
10:   svn – Real (Kind=nag_wp) arrayOutput
On exit: the array sv will contain the n diagonal elements of the matrix S.
11:   wantp – LogicalInput
On entry: must be .TRUE. if the matrix PT is required, in which case PT is overwritten on the array a, otherwise wantp must be .FALSE..
12:   work* – Real (Kind=nag_wp) arrayOutput
Note: the dimension of the array work must be at least max1,2×n-1 if ncolb=0 and wantq=.FALSE. and wantp=.FALSE., max1,3×n-1 if (ncolb=0 and wantq=.FALSE. and wantp=.TRUE.) or (wantp=.FALSE. and (ncolb>0 or wantq=.TRUE.)), and at least max1,5×n-1 otherwise.
On exit: workn contains the total number of iterations taken by the QR algorithm.
The rest of the array is used as internal workspace.
13:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6
Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=-1
On entry,n<0,
orlda<n,
orncolb<0,
orldb<n and ncolb>0,
orldq<n and wantq=.TRUE..
ifail>0
The QR algorithm has failed to converge in 50×n iterations. In this case sv1,sv2,,svifail may not have been found correctly and the remaining singular values may not be the smallest. The matrix R will nevertheless have been factorized as R=QEPT, where E is a bidiagonal matrix with sv1,sv2,,svn as the diagonal elements and work1,work2,,workn-1 as the superdiagonal elements.
This failure is not likely to occur.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

The computed factors Q, S and P satisfy the relation
QSPT=R+E,  
where
Ecε A ,  
ε is the machine precision, c is a modest function of n and . denotes the spectral (two) norm. Note that A=sv1.
A similar result holds for the computed matrix QTB.
The computed matrix Q satisfies the relation
Q=T+F,  
where T is exactly orthogonal and
Fdε,  
where d is a modest function of n. A similar result holds for P.

8
Parallelism and Performance

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

9
Further Comments

For given values of ncolb, wantq and wantp, the number of floating-point operations required is approximately proportional to n3.
Following the use of this routine the rank of R may be estimated by a call to the INTEGER FUNCTION f06klf. The statement
irank = f06klf(n,sv,1,tol)
returns the value k-1 in IRANK, where k is the smallest integer for which svk<tol×sv1, and tol is the tolerance supplied in tol, so that IRANK is an estimate of the rank of S and thus also of R. If tol is supplied as negative then the machine precision is used in place of tol.

10
Example

This example finds the singular value decomposition of the 3 by 3 upper triangular matrix
A= -4 -2 -3 0 -3 -2 0 0 -4 ,  
together with the vector QTb for the vector
b= -1 -1 -1 .  

10.1
Program Text

Program Text (f02wufe.f90)

10.2
Program Data

Program Data (f02wufe.d)

10.3
Program Results

Program Results (f02wufe.r)

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