Main Content

Singular Value Decomposition

Singular value decomposition expresses an m-by-n matrix A as A = U*S*V'. Here, S is an m-by-n diagonal matrix with singular values of A on its diagonal. The columns of the m-by-m matrix U are the left singular vectors for corresponding singular values. The columns of the n-by-n matrix V are the right singular vectors for corresponding singular values. V' is the Hermitian transpose (the complex conjugate of the transpose) of V.

To compute the singular value decomposition of a matrix, use svd. This function lets you compute singular values of a matrix separately or both singular values and singular vectors in one function call. To compute singular values only, use svd without output arguments

svd(A)

or with one output argument

S = svd(A)

To compute singular values and singular vectors of a matrix, use three output arguments:

[U,S,V] = svd(A)

svd returns two unitary matrices, U and V, the columns of which are singular vectors. It also returns a diagonal matrix, S, containing singular values on its diagonal. The elements of all three matrices are floating-point numbers. The accuracy of computations is determined by the current setting of digits.

Create the n-by-n matrix A with elements defined by A(i,j) = 1/(i - j + 1/2). The most obvious way of generating this matrix is

n = 3;
for i = 1:n
    for j = 1:n
      A(i,j) = sym(1/(i-j+1/2));
   end
end

For n = 3, the matrix is

A
A =
[   2,  -2, -2/3]
[ 2/3,   2,   -2]
[ 2/5, 2/3,    2]

Compute the singular values of this matrix. If you use svd directly, it will return exact symbolic result. For this matrix, the result is very long. If you prefer a shorter numeric result, convert the elements of A to floating-point numbers using vpa. Then use svd to compute singular values of this matrix using variable-precision arithmetic:

S = svd(vpa(A))
S =
 3.1387302525015353960741348953506
 3.0107425975027462353291981598225
 1.6053456783345441725883965978052

Now, compute the singular values and singular vectors of A:

[U,S,V] = svd(A)
U =
[  0.53254331027335338470683368360204,  0.76576895948802052989304092179952,...
                                        0.36054891952096214791189887728353]
[ -0.82525689650849463222502853672224,  0.37514965283965451993171338605042,...
                                        0.42215375485651489522488031917364]
[  0.18801243961043281839917114171742, -0.52236064041897439447429784257224,...
                                        0.83173955292075192178421874331406]
 
S =
[ 3.1387302525015353960741348953506,                                 0,...
                                                                     0]
[                                 0, 3.0107425975027462353291981598225,...
                                                                     0]
[                                 0,                                 0,...
                                     1.6053456783345441725883965978052]
 
V =
[  0.18801243961043281839917114171742,  0.52236064041897439447429784257224,...
                                        0.83173955292075192178421874331406]
[ -0.82525689650849463222502853672224, -0.37514965283965451993171338605042,...
                                        0.42215375485651489522488031917364]
[  0.53254331027335338470683368360204, -0.76576895948802052989304092179952,...
                                        0.36054891952096214791189887728353]