SVD Singular Value Decomposition of a Matrix

Section: Transforms/Decompositions

Usage

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)

Function Internals

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.

Examples

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.971533418  -1.286623120   0.015444173  
  0.956780076   0.470457107   0.953972280  
--> [U,S,V] = svd(A)
U = 
  <float>  - size: [2 2]
 
Columns 1 to 2
 -0.76774424   0.64075643  
  0.64075649   0.76774424  
S = 
  <float>  - size: [2 3]
 
Columns 1 to 3
 1.96677256  0.00000000  0.00000000  
 0.00000000  0.88212335  0.00000000  
V = 
  <float>  - size: [3 3]
 
Columns 1 to 3
  0.69095540   0.12701853  -0.71165085  
  0.65551353  -0.52512085   0.54272467  
  0.30476663   0.84149528   0.44609752  
--> U*S*V'
ans = 
  <float>  - size: [2 3]
 
Columns 1 to 3
 -0.971533477  -1.286623240   0.015444186  
  0.956780076   0.470457226   0.953972280  
--> svd(A)
ans = 
  <float>  - size: [2 1]
 
Columns 1 to 1
 1.96677256  
 0.88212335