# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# svd

Singular value decomposition of symbolic matrix

## Syntax

``sigma = svd(X)``
``````[U,S,V] = svd(X)``````
``````[U,S,V] = svd(X,0)``````
``````[U,S,V] = svd(X,'econ')``````

## Description

example

````sigma = svd(X)` returns a vector `sigma` containing the singular values of a symbolic matrix `A`.```

example

``````[U,S,V] = svd(X)``` returns numeric unitary matrices `U` and `V` with the columns containing the singular vectors, and a diagonal matrix `S` containing the singular values. The matrices satisfy the condition ```A = U*S*V'```, where `V'` is the Hermitian transpose (the complex conjugate of the transpose) of `V`. The singular vector computation uses variable-precision arithmetic. `svd` does not compute symbolic singular vectors. Therefore, the input matrix `X` must be convertible to floating-point numbers. For example, it can be a matrix of symbolic numbers.```

example

``````[U,S,V] = svd(X,0)``` returns the thin, or economy, SVD. If `X` is an `m`-by-`n` matrix with `m > n`, then `svd` computes only the first `n` columns of `U`. In this case, `S` is an `n`-by-`n` matrix. For `m <= n`, this syntax is equivalent to `svd(X)`.```

example

``````[U,S,V] = svd(X,'econ')``` also returns the thin, or economy, SVD. If `X` is an `m`-by-`n` matrix with `m >= n`, then this syntax is equivalent to `svd(X,0)`. For `m < n`, `svd` computes only the first `m` columns of `V`. In this case, `S` is an `m`-by-`m` matrix.```

## Examples

### Symbolic Singular Values

Compute the singular values of the symbolic `4`-by-`4` magic square:

```A = sym(magic(4)); sigma = svd(A)```
```sigma = 34 8*5^(1/2) 2*5^(1/2) 0```

Now, compute singular values of the matrix whose elements are symbolic expressions:

```syms t real A = [0 1; -1 0]; E = expm(t*A) sigma = svd(E)```
```E = [ cos(t), sin(t)] [ -sin(t), cos(t)] sigma = (cos(t)^2 + sin(t)^2)^(1/2) (cos(t)^2 + sin(t)^2)^(1/2)```

Simplify the result:

`sigma = simplify(sigma)`
```sigma = 1 1```

For further computations, remove the assumption:

`syms t clear`

### Floating-Point Singular Values

Convert the elements of the symbolic `4`-by-`4` magic square to floating-point numbers, and compute the singular values of the matrix:

```A = sym(magic(4)); sigma = svd(vpa(A))```
```sigma = 34.0 17.88854381999831757127338934985 4.4721359549995793928183473374626 0.0000000000000000000042127245515076439434819165724023i```

### Singular Values and Singular Vectors

Compute the singular values and singular vectors of the `4`-by-`4` magic square:

```old = digits(10); A = sym(magic(4)) [U, S, V] = svd(A) digits(old)```
```A = [ 16, 2, 3, 13] [ 5, 11, 10, 8] [ 9, 7, 6, 12] [ 4, 14, 15, 1] U = [ 0.5, 0.6708203932, 0.5, -0.2236067977] [ 0.5, -0.2236067977, -0.5, -0.6708203932] [ 0.5, 0.2236067977, -0.5, 0.6708203932] [ 0.5, -0.6708203932, 0.5, 0.2236067977] S = [ 34.0, 0, 0, 0] [ 0, 17.88854382, 0, 0] [ 0, 0, 4.472135955, 0] [ 0, 0, 0, 1.108401846e-15] V = [ 0.5, 0.5, 0.6708203932, 0.2236067977] [ 0.5, -0.5, -0.2236067977, 0.6708203932] [ 0.5, -0.5, 0.2236067977, -0.6708203932] [ 0.5, 0.5, -0.6708203932, -0.2236067977]```

Compute the product of `U`, `S`, and the Hermitian transpose of `V` with the 10-digit accuracy. The result is the original matrix `A` with all its elements converted to floating-point numbers:

`vpa(U*S*V',10)`
```ans = [ 16.0, 2.0, 3.0, 13.0] [ 5.0, 11.0, 10.0, 8.0] [ 9.0, 7.0, 6.0, 12.0] [ 4.0, 14.0, 15.0, 1.0]```

### Thin or Economy SVD

Use the second input argument `0` to compute the thin, or economy, SVD of this `2`-by-`3` matrix:

```old = digits(10); A = sym([1 1;2 2; 2 2]); [U, S, V] = svd(A, 0)```
```U = [ 0.3333333333, -0.6666666667] [ 0.6666666667, 0.6666666667] [ 0.6666666667, -0.3333333333] S = [ 4.242640687, 0] [ 0, 0] V = [ 0.7071067812, 0.7071067812] [ 0.7071067812, -0.7071067812]```

Now, use the second input argument `'econ'` to compute the thin, or economy, of matrix `B`. Here, the `3`-by-`2` matrix `B` is the transpose of `A`.

```B = A'; [U, S, V] = svd(B, 'econ') digits(old)```
```U = [ 0.7071067812, -0.7071067812] [ 0.7071067812, 0.7071067812] S = [ 4.242640687, 0] [ 0, 0] V = [ 0.3333333333, 0.6666666667] [ 0.6666666667, -0.6666666667] [ 0.6666666667, 0.3333333333]```

## Input Arguments

collapse all

Input matrix specified as a symbolic matrix. For syntaxes with one output argument, the elements of `X` can be symbolic numbers, variables, expressions, or functions. For syntaxes with three output arguments, the elements of `X` must be convertible to floating-point numbers.

## Output Arguments

collapse all

Singular values of a matrix, returned as a vector. If `sigma` is a vector of numbers, then its elements are sorted in descending order.

Singular vectors, returned as a unitary matrix. Each column of this matrix is a singular vector.

Singular values, returned as a diagonal matrix. Diagonal elements of this matrix appear in descending order.

Singular vectors, returned as a unitary matrix. Each column of this matrix is a singular vector.

## Tips

• The second arguments `0` and `'econ'` only affect the shape of the returned matrices. These arguments do not affect the performance of the computations.

• Calling `svd` for numeric matrices that are not symbolic objects invokes the MATLAB® `svd` function.