## 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 =

        0.8958    0.6486   -1.7291
       -0.4528   -0.4949   -1.3478

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

       -0.8714   -0.4906
       -0.4906    0.8714

    S =

        2.2618         0         0
             0    1.1678         0

    V =

       -0.2469   -0.7142    0.6550
       -0.1425   -0.6418   -0.7535
        0.9585   -0.2794    0.0567

    --> U*S*V'

    ans =

        0.8958    0.6486   -1.7291
       -0.4528   -0.4949   -1.3478

    --> svd(A)

    ans =

        2.2618
        1.1678

    -->
    quit