SVD Procedure
Performs a singular value decomposition on a matrix.
Usage
SVD, a, W[, u[, v]]
Input Parameters
a—The two-dimensional matrix to be decomposed. It has m rows and n columns, and m must be greater than or equal to n.
Output Parameters
W—An n-element vector of “singular values” equal to the diagonal elements of w: wi, j = Wj, wi, j = 0 for i ≠ j.
u—(optional) The m-by-n column matrix of the decomposition of a.
v—(optional) The n-by-n orthogonal matrix of the decomposition of a.
Keywords
None.
Discussion
SVD performs a singular value decomposition on a matrix a. It is useful for solving linear least-squares equations. SVD is able to deal with matrices that are singular or very close to singular.
The SVD procedure function transforms an m-by-n matrix a to the product of an m-by-n column orthogonal matrix u, an n-by-n diagonal matrix w, and the transpose of an n-by-n orthogonal matrix v. In other words, u, w, and v are matrices that are calculated by SVD.
By definition, the product of these three matrices (u, w, v) is equal to a:
a = uwv t
where the superscript t denotes the matrix transpose.
In a linear system of equations,
Ax = b
where there are at least as many equations as unknowns, the least-squares solution vector x is given by:
x = v . [diag(1/wj)](u t . b)
Example
The following PV‑WAVE function returns x, given A and b. A is an (m, n) matrix, where m ≥ n.
Function SVD_SOLVE, A, b
; Call SVD to decompose A.
SVD, A, w, u, v
; Make the diagonal matrix Wi,i = 1/wi.
n = N_ELEMENTS(w)
wp = FLTARR(n,n)
; Calculate x from equation and return.
FOR i=0L, n-1 DO IF w(i) NE 0 THEN wp(i,i) = 1./w(i)
RETURN, v # wp # (TRANSPOSE(u) # b)
END
See Also
The SVD function is based on the subroutine SVDCMP in Numerical Recipes in C: The Art of Scientific Computing, by Flannery, Press, Teukolsky, and Vetterling, Cambridge University Press, Cambridge, MA, 1988, and is used by permission.
PV‑WAVE’s SVD is a translation of the ALGOL procedure SVD described in Linear Algebra, Vol. II of The Handbook for Automatic Computation, by Wilkinson and Reinsch, Springer-Verlag, New York, NY, 1971.
For more information on SVD, also consult Computer Models for Mathematical Computations, by Forsythe, Malcom, and Moler, Prentice Hall, Englewood Cliffs, NJ, 1977.