svd

Singular value decomposition of a matrix.

Category: Mathematics > Linear Algebra

Syntax

s = svd(A)

Returns the singular values as a column vector in descending order.

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

Returns orthogonal U, V and a diagonal S with A = U*S*V'.

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

Economy size: drops the columns of U or V that multiply zero rows or columns of S.

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

Like 'econ' for m > n; for m <= n it is equivalent to the full form.

Description

Every matrix factors as a rotation, a scaling along orthogonal axes, and another rotation. The singular values are the scaling factors: the largest equals norm(A), the ratio of largest to smallest is cond(A), and the number above a tolerance is rank(A).

Truncating the decomposition to the k largest singular values gives the best rank-k approximation of A, which underlies data compression and principal component analysis.

Input arguments

A
Numeric matrix of any shape. NaN or Inf entries cause an error.
'econ' or 0
Request the economy-size decomposition.

Output arguments

s
Vector with min(size(A)) nonnegative singular values.
U, S, V
U is m-by-m, S is m-by-n with the singular values on its diagonal, V is n-by-n.

Example

Values and economy factors

A = [4 1; 2 3; 0 5];
s = svd(A)
[U, S, V] = svd(A, 'econ');
size(U)
norm(U*S*V' - A) < 1e-12
Output
s = 2×1

    6.3246
    3.8730
ans = 1×2

     3     2
ans = logical
   1

See also

svds pinv rank norm cond pagesvd