hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_eigen_real_triang_svd (f02wu)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_eigen_real_triang_svd (f02wu) returns all, or part, of the singular value decomposition of a real upper triangular matrix.

Syntax

[a, b, q, sv, work, ifail] = f02wu(a, b, wantq, wantp, 'n', n, 'ncolb', ncolb)
[a, b, q, sv, work, ifail] = nag_eigen_real_triang_svd(a, b, wantq, wantp, 'n', n, 'ncolb', ncolb)

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 function 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.

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

Parameters

Compulsory Input Parameters

1:     alda: – double array
The first dimension of the array a must be at least max1,n.
The second dimension of the array a must be at least max1,n.
The leading n by n upper triangular part of the array a must contain the upper triangular matrix R.
2:     bldb: – double array
The first dimension, ldb, of the array b must satisfy
  • if ncolb>0, ldbmax1,n;
  • otherwise ldb1.
The second dimension of the array b must be at least max1,ncolb.
With ncolb>0, the leading n by ncolb part of the array b must contain the matrix to be transformed.
3:     wantq – logical scalar
Must be true if the matrix Q is required.
If wantq=false, the array q is not referenced.
4:     wantp – logical scalar
Must be true if the matrix PT is required, in which case PT is overwritten on the array a, otherwise wantp must be false.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the first dimension of the array a and the second dimension of the array a.
n, the order of the matrix R.
If n=0, an immediate return is effected.
Constraint: n0.
2:     ncolb int64int32nag_int scalar
Default: the second dimension of the array b.
ncolb, the number of columns of the matrix B.
If ncolb=0, the array b is not referenced.
Constraint: ncolb0.

Output Parameters

1:     alda: – double array
The first dimension of the array a will be max1,n.
The second dimension of the array a will be max1,n.
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.
2:     bldb: – double array
The first dimension, ldb, of the array b will be
  • if ncolb>0, ldb=max1,n;
  • otherwise ldb=1.
The second dimension of the array b will be max1,ncolb.
The leading n by ncolb part of the array b stores the matrix QTB.
3:     qldq: – double array
The first dimension, ldq, of the array q will be
  • if wantq=true, ldq=max1,n;
  • otherwise ldq=1.
The second dimension of the array q will be max1,n if wantq=true and 1 otherwise.
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.
4:     svn – double array
The array sv will contain the n diagonal elements of the matrix S.
5:     work: – double array
The dimension of the array work will be 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 max1,5×n-1 otherwise
workn contains the total number of iterations taken by the QR algorithm.
The rest of the array is used as internal workspace.
6:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

   ifail=-1
On entry,n<0,
orlda<n,
orncolb<0,
orldb<n and ncolb>0,
orldq<n and wantq=true.
W  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.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

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.

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 nag_eigen_real_triang_svd (f02wu) the rank of R may be estimated as follows:
tol = eps;
irank = 1;
while (irank <= numel(sv) && sv(irank) >= tol*sv(1) )
  irank = irank + 1;
end
returns the value k in irank, where k is the smallest integer for which svk<tol×sv1, where tol is typically the machine precision, so that irank is an estimate of the rank of S and thus also of R.

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 .  
function f02wu_example


fprintf('f02wu example results\n\n');

% SVD of upper triangular A
a = [-4, -2, -3;
      0, -3, -2;
      0,  0, -4];

b = [-1; -1; -1];
wantq = true;
wantp = true;
[a, b, q, sv, work, ifail] = f02wu( ...
                                    a, b, wantq, wantp);

fprintf('Singular value decomposition of A\n\n');

disp('Singular values');
disp(sv');
disp('Left-hand singular vectors, by column');
disp(q);
disp('Right-hand singular vectors, by column');
disp(a');
disp('Vector Q''*B');
disp(b');


f02wu example results

Singular value decomposition of A

Singular values
    6.5616    3.0000    2.4384

Left-hand singular vectors, by column
   -0.7699    0.5883   -0.2471
   -0.4324   -0.1961    0.8801
   -0.4694   -0.7845   -0.4054

Right-hand singular vectors, by column
    0.4694   -0.7845    0.4054
    0.4324   -0.1961   -0.8801
    0.7699    0.5883    0.2471

Vector Q'*B
    1.6716    0.3922   -0.2276


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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