Computes the singular value decomposition (SVD) of a matrix. The
svd function has three forms. The first returns only the singular
values of the matrix:
s = svd(A)
The second form returns both the singular values in a diagonal
matrix S, as well as the left and right eigenvectors.
[U,S,V] = svd(A)
The third form returns a more compact decomposition, with the left and right singular vectors corresponding to zero singular values being eliminated. The syntax is
[U,S,V] = svd(A,0)
Recall that sigma_i is a singular value of an M x N
matrix A if there exists two vectors u_i, v_i where u_i is
of length M, and v_i is of length u_i and
and generally
where
K is the rank of A. In matrix form, the left singular
vectors u_i are stored in the matrix U as
The matrix
S is then of size M x N with the singular
values along the diagonal. The SVD is computed using the
LAPACK class of functions GESDD.
Here is an example of a partial and complete singular value decomposition.
--> A = float(randn(2,3))
A =
<float> - size: [2 3]
Columns 1 to 3
-0.036163993 0.69338953 0.59975541
-0.14041515 -0.23818725 0.70864934
--> [U,S,V] = svd(A)
U =
<float> - size: [2 2]
Columns 1 to 2
-0.84994751 -0.52686721
-0.52686727 0.84994757
S =
<float> - size: [2 3]
Columns 1 to 3
1.0030123 0.00000000 0.00000000
0.00000000 0.64374173 0.00000000
V =
<float> - size: [3 3]
Columns 1 to 3
0.10440307 -0.15579510 0.98225647
-0.46245861 -0.88198572 -0.090736881
-0.88047248 0.44477975 0.16413097
--> U*S*V'
ans =
<float> - size: [2 3]
Columns 1 to 3
-0.036163971 0.69338953 0.59975535
-0.14041504 -0.23818734 0.70864934
--> svd(A)
ans =
<float> - size: [2 1]
Columns 1 to 1
1.0030123
0.64374173