nag_real_svd (f02wec) (PDF version)
f02 Chapter Contents
f02 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_real_svd (f02wec)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_real_svd (f02wec) returns all, or part, of the singular value decomposition of a general real matrix.

2  Specification

#include <nag.h>
#include <nagf02.h>
void  nag_real_svd (Integer m, Integer n, double a[], Integer tda, Integer ncolb, double b[], Integer tdb, Nag_Boolean wantq, double q[], Integer tdq, double sv[], Nag_Boolean wantp, double pt[], Integer tdpt, Integer *iter, double e[], Integer *failinfo, NagError *fail)

3  Description

The m  by n  matrix A  is factorized as
A = QDPT
where
D = S 0 m > n D = S , m = n D = S 0 m < n .
Q  is an m  by m  orthogonal matrix, P  is an n  by n  orthogonal matrix and S  is a minm,n  by minm,n  diagonal matrix with non-negative diagonal elements, sv 1 , sv 2 , , sv min m,n , ordered such that
sv 1 sv 2 sv min m,n 0 .
The first minm,n  columns of Q  are the left-hand singular vectors of A , the diagonal elements of S  are the singular values of A  and the first minm,n  columns of P  are the right-hand singular vectors of A .
Either or both of the left-hand and right-hand singular vectors of A  may be requested and the matrix C  given by
C = QT B
where B  is an m  by ncolb  given matrix, may also be requested.
The function obtains the singular value decomposition by first reducing A  to upper triangular form by means of Householder transformations, from the left when mn  and from the right when m<n . The upper triangular form is then reduced to bidiagonal form by Givens plane rotations and finally the QR  algorithm is used 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 this function is not based on the LINPACK routine SSVDC.
Note that if K  is any orthogonal diagonal matrix such that
KKT = I ,
so that K  has elements +1  or -1  on the diagonal, then
A = Q K D P K T
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  Arguments

1:     mIntegerInput
On entry: the number of rows, m , of the matrix A .
Constraint: m0 .
When m=0  then an immediate return is effected.
2:     nIntegerInput
On entry: the number of columns, n , of the matrix A .
Constraint: n0 .
When n=0  then an immediate return is effected.
3:     a[m×tda]doubleInput/Output
Note: the i,jth element of the matrix A is stored in a[i-1×tda+j-1].
On entry: the leading m  by n  part of the array a must contain the matrix A  whose singular value decomposition is required.
On exit: if mn  and wantq=Nag_TRUE , then the leading m  by n  part of a will contain the first n  columns of the orthogonal matrix Q .
If m<n  and wantp=Nag_TRUE , then the leading m  by n  part of a will contain the first m  rows of the orthogonal matrix PT .
If mn  and wantq=Nag_FALSE  and wantp=Nag_TRUE , then the leading n  by n  part of a will contain the first n  rows of the orthogonal matrix PT .
Otherwise the contents of the leading m  by n  part of a are indeterminate.
4:     tdaIntegerInput
On entry: the stride separating matrix column elements in the array a.
Constraint: tdan .
5:     ncolbIntegerInput
On entry: ncolb , the number of columns of the matrix B . When ncolb=0  the array b is not referenced and may be NULL.
Constraint: ncolb0 .
6:     b[m×tdb]doubleInput/Output
Note: the i,jth element of the matrix B is stored in b[i-1×tdb+j-1].
On entry: if ncolb>0 , the leading m  by ncolb  part of the array b must contain the matrix to be transformed. If ncolb=0  the array b is not referenced and may be NULL.
On exit: b is overwritten by the m  by ncolb  matrix QT B .
7:     tdbIntegerInput
On entry: the stride separating matrix column elements in the array b.
Constraint: if ncolb>0  then tdbncolb .
8:     wantqNag_BooleanInput
On entry: wantq must be Nag_TRUE, if the left-hand singular vectors are required. If wantq = Nag_FALSE, then the array q is not referenced and may be NULL.
9:     q[m×tdq]doubleOutput
Note: the i,jth element of the matrix Q is stored in q[i-1×tdq+j-1].
On exit: if m<n  and wantq=Nag_TRUE , the leading m  by m  part of the array q will contain the orthogonal matrix Q . Otherwise the array q is not referenced and may be NULL.
10:   tdqIntegerInput
On entry: the stride separating matrix column elements in the array q.
Constraint: if m<n  and wantq=Nag_TRUE , tdqm
11:   sv[minm,n]doubleOutput
On exit: the minm,n  diagonal elements of the matrix S .
12:   wantpNag_BooleanInput
On entry: wantp must be Nag_TRUE if the right-hand singular vectors are required. If wantp=Nag_FALSE, then the array pt is not referenced and may be NULL.
13:   pt[n×tdpt]doubleOutput
Note: the i,jth element of the matrix is stored in pt[i-1×tdpt+j-1].
On exit: if mn  and wantq and wantp are Nag_TRUE, the leading n  by n  part of the array pt will contain the orthogonal matrix PT . Otherwise the array pt is not referenced and may be NULL.
14:   tdptIntegerInput
On entry: the stride separating matrix column elements in the array pt.
Constraint: if mn  and wantq=Nag_TRUE  and wantp=Nag_TRUE , tdptn
15:   iterInteger *Output
On exit: the total number of iterations taken by the QR  algorithm.
16:   e[minm,n]doubleOutput
On exit: if the error NE_QR_NOT_CONV occurs the array e contains the super diagonal elements of matrix E  in the factorization of A  according to A = QEPT . See Section 6 for further details.
17:   failinfoInteger *Output
On exit: if the error NE_QR_NOT_CONV occurs failinfo contains the number of singular values which may not have been found correctly. See Section 6 for details.
18:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, tda=value  while n=value . These arguments must satisfy tdan .
On entry, tdb=value  while ncolb=value . These arguments must satisfy tdbncolb .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT_ARG_LT
On entry, m=value.
Constraint: m0.
On entry, n=value.
Constraint: n0.
On entry, ncolb=value.
Constraint: ncolb0.
NE_QR_NOT_CONV
The QR  algorithm has failed to converge in value iterations. Singular values 1,2, ,failinfo may not have been found correctly and the remaining singular values may not be the smallest. The matrix A  will nevertheless have been factorized as A = QEPT , where the leading minm,n  by minm,n  part of E  is a bidiagonal matrix with sv[0] , sv[1] , , sv[ minm,n-1 ]  as the diagonal elements and e[0] , e[1] , , e[ minm,n-2 ]  as the superdiagonal elements. This failure is not likely to occur.
NE_TDP_LT_N
On entry, tdpt=value  while n=value . When wantq and wantp are Nag_TRUE and mn  then relationship tdptn  must be satisfied.
NE_TDQ_LT_M
On entry, tdq=value  while m=value . When wantq is Nag_TRUE and m<n  then relationship tdqm  must be satisfied.

7  Accuracy

The computed factors Q , D  and P  satisfy the relation
QDPT = A + E
where E c ε A , ε  being the machine precision, c  is a modest function of m  and n  and .  denotes the spectral (two) norm. Note that A = sv 1 .

8  Parallelism and Performance

Not applicable.

9  Further Comments

None.

10  Example

For this function two examples are presented. There is a single example program for nag_real_svd (f02wec), with a main program and the code to solve the two example problems is given in the functions ex1 and ex2.
Example 1 (ex1)
To find the singular value decomposition of the 5 by 3 matrix
A = 2.0 2.5 2.5 2.0 2.5 2.5 1.6 -0.4 2.8 2.0 -0.5 0.5 1.2 -0.3 -2.9
together with the vector QT b  for the vector
b = 1.1 0.9 0.6 0.0 -0.8 .
Example 2 (ex2)
To find the singular value decomposition of the 3 by 5 matrix
A = 2.0 2.0 1.6 2.0 1.2 2.5 2.5 -0.4 -0.5 -0.3 2.5 2.5 -2.8 0.5 -2.9 .

10.1  Program Text

Program Text (f02wece.c)

10.2  Program Data

Program Data (f02wece.d)

10.3  Program Results

Program Results (f02wece.r)


nag_real_svd (f02wec) (PDF version)
f02 Chapter Contents
f02 Chapter Introduction
NAG Library Manual

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