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_lapack_zgesvd (f08kp)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_lapack_zgesvd (f08kp) computes the singular value decomposition (SVD) of a complex m by n matrix A, optionally computing the left and/or right singular vectors.

Syntax

[a, s, u, vt, rwork, info] = f08kp(jobu, jobvt, a, 'm', m, 'n', n)
[a, s, u, vt, rwork, info] = nag_lapack_zgesvd(jobu, jobvt, a, 'm', m, 'n', n)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: rwork was made an output parameter

Description

The SVD is written as
A = UΣVH ,  
where Σ is an m by n matrix which is zero except for its minm,n diagonal elements, U is an m by m unitary matrix, and V is an n by n unitary matrix. The diagonal elements of Σ are the singular values of A; they are real and non-negative, and are returned in descending order. The first minm,n columns of U and V are the left and right singular vectors of A.
Note that the function returns VH, not V.

References

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 http://www.netlib.org/lapack/lug
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

Parameters

Compulsory Input Parameters

1:     jobu – string (length ≥ 1)
Specifies options for computing all or part of the matrix U.
jobu='A'
All m columns of U are returned in array u.
jobu='S'
The first minm,n columns of U (the left singular vectors) are returned in the array u.
jobu='O'
The first minm,n columns of U (the left singular vectors) are overwritten on the array a.
jobu='N'
No columns of U (no left singular vectors) are computed.
Constraint: jobu='A', 'S', 'O' or 'N'.
2:     jobvt – string (length ≥ 1)
Specifies options for computing all or part of the matrix VH.
jobvt='A'
All n rows of VH are returned in the array vt.
jobvt='S'
The first minm,n rows of VH (the right singular vectors) are returned in the array vt.
jobvt='O'
The first minm,n rows of VH (the right singular vectors) are overwritten on the array a.
jobvt='N'
No rows of VH (no right singular vectors) are computed.
Constraints:
  • jobvt='A', 'S', 'O' or 'N';
  • jobvt and jobu cannot both be 'O'.
3:     alda: – complex array
The first dimension of the array a must be at least max1,m.
The second dimension of the array a must be at least max1,n.
The m by n matrix A.

Optional Input Parameters

1:     m int64int32nag_int scalar
Default: the first dimension of the array a.
m, the number of rows of the matrix A.
Constraint: m0.
2:     n int64int32nag_int scalar
Default: the second dimension of the array a.
n, the number of columns of the matrix A.
Constraint: n0.

Output Parameters

1:     alda: – complex array
The first dimension of the array a will be max1,m.
The second dimension of the array a will be max1,n.
If jobu='O', a is overwritten with the first minm,n columns of U (the left singular vectors, stored column-wise).
If jobvt='O', a is overwritten with the first minm,n rows of VH (the right singular vectors, stored row-wise).
If jobu'O' and jobvt'O', the contents of a are destroyed.
2:     s: – double array
The dimension of the array s will be max1,minm,n
The singular values of A, sorted so that sisi+1.
3:     uldu: – complex array
The first dimension, ldu, of the array u will be
  • if jobu='A' or 'S', ldu= max1,m ;
  • otherwise ldu=1.
The second dimension of the array u will be max1,m if jobu='A', max1,minm,n if jobu='S' and 1 otherwise.
If jobu='A', u contains the m by m unitary matrix U.
If jobu='S', u contains the first minm,n columns of U (the left singular vectors, stored column-wise).
If jobu='N' or 'O', u is not referenced.
4:     vtldvt: – complex array
The first dimension, ldvt, of the array vt will be
  • if jobvt='A', ldvt= max1,n ;
  • if jobvt='S', ldvt= max1,minm,n ;
  • otherwise ldvt=1.
The second dimension of the array vt will be max1,n if jobvt='A' or 'S' and 1 otherwise.
If jobvt='A', vt contains the n by n unitary matrix VH.
If jobvt='S', vt contains the first minm,n rows of VH (the right singular vectors, stored row-wise).
If jobvt='N' or 'O', vt is not referenced.
5:     rwork: – double array
The dimension of the array rwork will be max1, 5×minm,n
If info>0, rwork1:minm,n-1 contains the unconverged superdiagonal elements of an upper bidiagonal matrix B whose diagonal is in S (not necessarily sorted). B satisfies A=UBVH, so it has the same singular values as A, and singular vectors related by U and VH.
6:     info int64int32nag_int scalar
info=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

   info=-i
If info=-i, parameter i had an illegal value on entry. The parameters are numbered as follows:
1: jobu, 2: jobvt, 3: m, 4: n, 5: a, 6: lda, 7: s, 8: u, 9: ldu, 10: vt, 11: ldvt, 12: work, 13: lwork, 14: rwork, 15: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.
   info>0
If nag_lapack_zgesvd (f08kp) did not converge, info specifies how many superdiagonals of an intermediate bidiagonal form did not converge to zero. See the description of rwork above for details.

Accuracy

The computed singular value decomposition is nearly the exact singular value decomposition for a nearby matrix A+E , where
E2 = Oε A2 ,  
and ε  is the machine precision. In addition, the computed singular vectors are nearly orthogonal to working precision. See Section 4.9 of Anderson et al. (1999) for further details.

Further Comments

The total number of floating-point operations is approximately proportional to mn2  when m>n and m2n  otherwise.
The singular values are returned in descending order.
The real analogue of this function is nag_lapack_dgesvd (f08kb).

Example

This example finds the singular values and left and right singular vectors of the 6 by 4 matrix
A = 0.96-0.81i -0.03+0.96i -0.91+2.06i -0.05+0.41i -0.98+1.98i -1.20+0.19i -0.66+0.42i -0.81+0.56i 0.62-0.46i 1.01+0.02i 0.63-0.17i -1.11+0.60i -0.37+0.38i 0.19-0.54i -0.98-0.36i 0.22-0.20i 0.83+0.51i 0.20+0.01i -0.17-0.46i 1.47+1.59i 1.08-0.28i 0.20-0.12i -0.07+1.23i 0.26+0.26i ,  
together with approximate error bounds for the computed singular values and vectors.
The example program for nag_lapack_zgesdd (f08kr) illustrates finding a singular value decomposition for the case mn.
function f08kp_example


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

% SVD of A to obtain Least-sqares solution of Ax=b, where
a = [ 0.96 - 0.81i, -0.03 + 0.96i, -0.91 + 2.06i, -0.05 + 0.41i;
     -0.98 + 1.98i, -1.20 + 0.19i, -0.66 + 0.42i, -0.81 + 0.56i;
      0.62 - 0.46i,  1.01 + 0.02i,  0.63 - 0.17i, -1.11 + 0.60i;
     -0.37 + 0.38i,  0.19 - 0.54i, -0.98 - 0.36i,  0.22 - 0.20i;
      0.83 + 0.51i,  0.20 + 0.01i, -0.17 - 0.46i,  1.47 + 1.59i;
      1.08 - 0.28i,  0.20 - 0.12i, -0.07 + 1.23i,  0.26 + 0.26i];
[m,n] = size(a);
b     = ones(m,1);

% SVD of A
jobu = 'Singular vectors (U)';
jobvt = 'Singular vectors (V)';
[~, s, u, vt, rwork, info] = f08kp( ...
                                    jobu, jobvt, a);

disp('Singular values of A');
disp(s');

% Use SVD to compute least-squares solution: VS^(-1)U'b
y = u'*b;
y = y./s;
x = vt'*y;

disp('Least squares solution:');
disp(x);
disp('Norm of Residual:');
disp(norm(b - a*x));


f08kp example results

Singular values of A
    3.9994    3.0003    1.9944    0.9995

Least squares solution:
  -0.0719 - 0.2761i
   0.6796 + 0.4326i
  -0.3832 - 0.5447i
   0.0096 - 0.3489i

Norm of Residual:
    1.5266


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