# Singular value decomposition: svd

### 5.49.8 Singular value decomposition: svd

The singular value decomposition of a matrix A is a factorization A=USQT, where U and Q are orthogonal and S is a diagonal matrix. The svd command finds the singular value decomposition of a matrix.

- svd takes one argument:
  A, a numeric square matrix.
- svd(A) returns a list [U,s,Q] where U and Q are the orthogonal matrices of the singular value decomposition and s is the diagonal of the matrix S.

You can get the diagonal matrix S from s with S=diag(s) (see Section 5.44.2).

#### Examples.

- Input:
  svd([[1,2],[3,4]])
  Output:

  ⎡
  ⎢
  ⎣

  −0.404553584834 | −0.914514295677
  −0.914514295677 | 0.404553584834

  ⎤
  ⎥
  ⎦

  ,

  ⎡
  ⎣

  5.46498570422,0.365966190626

  ⎤
  ⎦

  ,

  ⎡
  ⎢
  ⎣

  −0.576048436766 | 0.81741556047
  −0.81741556047 | −0.576048436766

  ⎤
  ⎥
  ⎦

- Input:
  (U,s,Q):=svd([[3,5],[4,5]])
  Output:

  ⎡
  ⎢
  ⎣

  −0.672988041811 | −0.739653361771
  −0.739653361771 | 0.672988041811

  ⎤
  ⎥
  ⎦

  ,

  ⎡
  ⎣

  8.6409011028,0.578643354497

  ⎤
  ⎦

  ,

  ⎡
  ⎢
  ⎣

  −0.576048436766 | 0.81741556047
  −0.81741556047 | −0.576048436766

  ⎤
  ⎥
  ⎦

  Verification:
  Input:
  U*diag(s)*tran(Q)
  Output:

  ⎛
  ⎜
  ⎝

  3.0 | 5.0
  4.0 | 5.0

  ⎞
  ⎟
  ⎠