CALL SVD (u, q, v, a);
The SVD subroutine computes the singular value decomposition for a numerical matrix.
The input to the SVD subroutine is as follows:
is the input matrix that is factored as described in the following discussion.
The SVD subroutine returns the following output arguments:
is an orthonormal matrix
is an vector that contains the singular values
is an orthonormal matrix
If , the SVD subroutine factors a real matrix into the form
where
and contains the singular values of . The columns of contains of the orthonormal eigenvectors of , and contains the orthonormal eigenvectors of . contains the square roots of the eigenvalues of and , except for some zeros.
If , a corresponding decomposition is done where and switch roles:
where
The singular values are sorted in descending order.
For information about the method used in the SVD subroutine, see Wilkinson and Reinsch (1971).
The following example is taken from Wilkinson and Reinsch (1971):
a = {22 10 2 3 7, 14 7 10 0 8, -1 13 -1 -11 3, -3 -2 13 -2 4, 9 8 1 -2 4, 9 1 -7 5 -1, 2 -6 6 5 1, 4 5 0 -2 2}; call svd(u, q, v, a); print u, q, v; /* check correctness of factors */ zero = ssq(a - u*diag(q)*v`); reset fuzz; /* print small numbers as zero */ print zero;
The matrix is rank-3 with exact singular values , 20, , 0, and 0. Because of the repeated singular values, the last two columns of the matrix are not uniquely determined. A valid result is shown in FigureĀ 25.408:
Figure 25.408: Singular Value Decomposition
u | ||||
---|---|---|---|---|
0.7071068 | 0.1581139 | -0.176777 | -0.328209 | -0.328056 |
0.5303301 | 0.1581139 | 0.3535534 | 0.5309976 | 0.0489362 |
0.1767767 | -0.790569 | 0.1767767 | -0.413567 | 0.1307398 |
0 | 0.1581139 | 0.7071068 | -0.266418 | 0.0321656 |
0.3535534 | -0.158114 | 0 | 0.0253566 | -0.041441 |
0.1767767 | 0.1581139 | -0.53033 | -0.19666 | 0.3666144 |
0 | 0.4743416 | 0.1767767 | -0.500944 | 0.4145131 |
0.1767767 | -0.158114 | 0 | 0.2793571 | 0.7509412 |
The SVD routine performs most of its computations in the memory allocated for returning the singular value decomposition.