F02XUF (PDF version)
F02 Chapter Contents
F02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

F02XUF

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.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

F02XUF returns all, or part, of the singular value decomposition of a complex upper triangular matrix.

2  Specification

SUBROUTINE F02XUF ( N, A, LDA, NCOLB, B, LDB, WANTQ, Q, LDQ, SV, WANTP, RWORK, CWORK, IFAIL)
INTEGER  N, LDA, NCOLB, LDB, LDQ, IFAIL
REAL (KIND=nag_wp)  SV(N), RWORK(*)
COMPLEX (KIND=nag_wp)  A(LDA,*), B(LDB,*), Q(LDQ,*), CWORK(max(1,N-1))
LOGICAL  WANTQ, WANTP

3  Description

The n by n upper triangular matrix R is factorized as
R=QSPH,  
where Q and P are n by n unitary matrices and S is an n by n diagonal matrix with real non-negative diagonal elements, sv1,sv2,,svn, ordered such that
sv1sv2svn0.  
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 PH may be requested and the matrix C given by
C=QHB,  
where B is an n by ncolb given matrix, may also be requested.
F02XUF 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 Dongarra et al. (1979), Hammarling (1985) and Wilkinson (1978).
Note that if K is any unitary diagonal matrix so that
KKH=I,  
then
A=QKSPKH  
is also a singular value decomposition of A.

4  References

Dongarra J J, Moler C B, Bunch J R and Stewart G W (1979) LINPACK Users' Guide SIAM, Philadelphia
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  Parameters

1:     N – INTEGERInput
On entry: n, the order of the matrix R.
If N=0, an immediate return is effected.
Constraint: N0.
2:     ALDA* – COMPLEX (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 unitary matrix PH, 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 F02XUF 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* – COMPLEX (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array B must be at least max1,NCOLB.
On entry: if NCOLB>0, the leading n by ncolb part of the array B must contain the matrix to be transformed.
On exit: is overwritten by the n by ncolb matrix QHB.
6:     LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which F02XUF 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. then the array Q is not referenced.
8:     QLDQ* – COMPLEX (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: if WANTQ=.TRUE., the leading n by n part of the array Q will contain the unitary 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 F02XUF is called.
Constraints:
  • if WANTQ=.TRUE., LDQmax1,N;
  • otherwise LDQ1.
10:   SVN – REAL (KIND=nag_wp) arrayOutput
On exit: the n diagonal elements of the matrix S.
11:   WANTP – LOGICALInput
On entry: must be .TRUE. if the matrix PH is required, in which case PH is returned in the array A, otherwise WANTP must be .FALSE..
12:   RWORK* – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array RWORK 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 NCOLB>0 and WANTP=.FALSE. or WANTQ=.TRUE. and WANTP=.FALSE., and at least max1,5×N-1 otherwise.
On exit: RWORK(N) contains the total number of iterations taken by the QR algorithm.
The rest of the array is used as workspace.
13:   CWORKmax1,N-1 – COMPLEX (KIND=nag_wp) arrayWorkspace
14:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction 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 parameter, 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=QEPH, where E is a bidiagonal matrix with SV1,SV2,,SVn as the diagonal elements and RWORK1,RWORK2,,RWORKn-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.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

The computed factors Q, S and P satisfy the relation
QSPH=A+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.

8  Parallelism and Performance

F02XUF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
F02XUF 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, where 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 = 1 1+i 1+i 0 -2i+ -1-i 0 0i+ -3i+  
together with the vector QHb for the vector
b= 1+1i -1i+0 -1+1i .  

10.1  Program Text

Program Text (f02xufe.f90)

10.2  Program Data

Program Data (f02xufe.d)

10.3  Program Results

Program Results (f02xufe.r)


F02XUF (PDF version)
F02 Chapter Contents
F02 Chapter Introduction
NAG Library Manual

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