Demonstration of the Singular Value Decomposition
is a C program which
demonstrates the computation of the singular value decomposition
and a few of its properties.
The singular value decomposition has uses in solving
overdetermined or underdetermined linear systems,
linear least squares problems, data compression,
the pseudoinverse matrix,
reduced order modeling, and
the accurate computation of matrix rank and null space.
The singular value decomposition of an M by N rectangular matrix A has
A(mxn) = U(mxm) * S(mxn) * V'(nxn)
Note that the transpose of V is used in the decomposition, and that the diagonal matrix
S is typically stored as a vector.
U is an orthogonal matrix, whose columns are the left singular vectors;
S is a diagonal matrix, whose min(m,n) diagonal entries are the singular values;
V is an orthogonal matrix, whose columns are the right singular vectors;
svd_demo m n seed
m is the number of rows in the random matrix;
n is the number of columns in the random matrix;
seed is an optional seed for the random number generator.
The computer code and data files described and made available on this web page
are distributed under
the GNU LGPL license.
SVD_DEMO is available in
a C version and
a C++ version and
a FORTRAN77 version and
a FORTRAN90 version and
a MATLAB version.
Related Data and Programs:
a C library which
contains basic linear algebra subprograms (BLAS) for vector-vector operations,
using double precision real arithmetic;
a dataset directory which
contains a few images of fingerprints.
a C library which
solves linear systems using double precision real arithmetic;
a C++ program which
computes a reduced basis for a collection of data vectors using the SVD.
a C program which
reads a file containing historical snowfall data and
analyzes the data with the Singular Value Decomposition (SVD),
and plots created by GNUPLOT.
a C++ program which
demonstrates the computation of the reduced or truncated
Singular Value Decomposition (SVD) that is useful for cases when
one dimension of the matrix is much smaller than the other.
a FORTRAN77 routine which
computes the singular value decomposition for a complex matrix.
Edward Anderson, Zhaojun Bai, Christian Bischof, Susan Blackford,
James Demmel, Jack Dongarra, Jeremy Du Croz, Anne Greenbaum,
Sven Hammarling, Alan McKenney, Danny Sorensen,
LAPACK User's Guide,
Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,
LINPACK User's Guide,
Gene Golub, Charles VanLoan,
Johns Hopkins, 1996,
David Kahaner, Cleve Moler, Steven Nash,
Numerical Methods and Software,
Prentice Hall, 1989,
Lloyd Trefethen, David Bau,
Numerical Linear Algebra,
Examples and Tests:
List of Routines:
MAIN is the main program for SVD_DEMO.
GET_SEED returns a random seed for the random number generator.
GET_SVD_LINPACK gets the SVD of a matrix using a call to LINPACK.
PSEUDO_INVERSE computes the pseudoinverse.
PSEUDO_LINEAR_SOLVE_TEST uses the pseudoinverse for linear systems.
PSEUDO_PRODUCT_TEST examines pseudoinverse products.
R8_NINT returns the nearest integer to a double precision value.
R8MAT_DIF_FRO returns the Frobenius norm of the difference of R8MAT's.
R8MAT_NORM_FRO returns the Frobenius norm of a R8MAT.
R8MAT_PRINT prints an R8MAT.
R8MAT_PRINT_SOME prints some of an R8MAT.
R8VEC_NORM_L2 returns the L2 norm of an R8VEC.
R8MAT_UNIFORM_01 returns a unit pseudorandom R8MAT.
R8VEC_UNIFORM_01 returns a unit pseudorandom R8VEC.
RANK_ONE_PRINT_TEST prints the sums of rank one matrices.
RANK_ONE_TEST compares A to the sum of rank one matrices.
S_LEN_TRIM returns the length of a string to the last nonblank.
SVD_PRODUCT_TEST tests that A = U * S * V'.
TIMESTAMP prints the current YMDHMS date as a time stamp.
You can go up one level to
the C source codes.
Last revised on 19 June 2012.