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
 -1.04076362  -1.61856449   0.55819988  
  0.24222484  -1.26936078  -2.91016126  
--> [U,S,V] = svd(A)
U = 
  <float>  - size: [2 2]
 
Columns 1 to 2
  0.029025711   0.999578655  
  0.999578655  -0.029025711  
S = 
  <float>  - size: [2 3]
 
Columns 1 to 3
 3.1849895  0.0000000  0.0000000  
 0.0000000  2.0023384  0.0000000  
V = 
  <float>  - size: [3 3]
 
Columns 1 to 3
  0.066535234  -0.523066461   0.849690914  
 -0.413127303  -0.789596081  -0.453722239  
 -0.908239424   0.320841968   0.268628925  
--> U*S*V'
ans = 
  <float>  - size: [2 3]
 
Columns 1 to 3
 -1.04076374  -1.61856449   0.55819982  
  0.24222499  -1.26936090  -2.91016126  
--> svd(A)
ans = 
  <float>  - size: [2 1]
 
Columns 1 to 1
 3.1849895  
 2.0023384