# gsvd

Generalized singular value decomposition

## Syntax

``[U,V,X,C,S] = gsvd(A,B)``
``[U,V,X,C,S] = gsvd(A,B,"econ")``
``[U,V,X,C,S] = gsvd(A,B,0)``
``sigma = gsvd(A,B)``

## Description

example

````[U,V,X,C,S] = gsvd(A,B)` performs a generalized singular value decomposition of matrices `A` and `B`, and returns unitary matrices `U` and `V`, a matrix `X`, and nonnegative diagonal matrices `C` and `S` such thatA = U*C*X' B = V*S*X' C'*C + S'*S = I ```

example

````[U,V,X,C,S] = gsvd(A,B,"econ")`, where `A` is `m`-by-`p` and `B` is `n`-by-`p`, produces an economy-size decomposition where the resulting `U` and `V` matrices have at most `p` columns, and `C` and `S` have at most `p` rows.```
````[U,V,X,C,S] = gsvd(A,B,0)` is the same as `gsvd(A,B,"econ")`.```

example

````sigma = gsvd(A,B)` returns the vector of generalized singular values, `sqrt(diag(C'*C)./diag(S'*S))`. When `B` is square and nonsingular, the generalized singular values, `gsvd(A,B)`, correspond to the ordinary singular values, `svd(A/B)`, but they are sorted in the opposite order. Their reciprocals are `gsvd(B,A)`.```

## Examples

collapse all

Perform a generalized singular value decomposition on two matrices and also calculate the generalized singular values.

Create a 5-by-3 matrix `A` and a 3-by-3 matrix `B`.

`A = reshape(1:15,5,3)`
```A = 5×3 1 6 11 2 7 12 3 8 13 4 9 14 5 10 15 ```
`B = magic(3)`
```B = 3×3 8 1 6 3 5 7 4 9 2 ```

Perform a generalized singular value decomposition on `A` and `B`. The outputs include orthogonal `U` and `V`, a nonsingular `X`, and diagonal matrices `C` and `S`. Because `A` is rank deficient, the first diagonal element of `C` is zero.

`[U,V,X,C,S] = gsvd(A,B)`
```U = 5×5 0.5618 0.6457 -0.4279 -0.0735 0.2810 -0.8005 0.3296 -0.4375 0.1240 0.2094 -0.0219 0.0135 -0.4470 -0.4343 -0.7816 0.1979 -0.3026 -0.4566 0.7906 -0.1889 0.0626 -0.6187 -0.4661 -0.4068 0.4802 ```
```V = 3×3 -0.7071 -0.6946 0.1325 0.0000 -0.1874 -0.9823 0.7071 -0.6946 0.1325 ```
```X = 3×3 -2.8284 -9.3761 -6.9346 5.6569 -8.3071 -18.3301 -2.8284 -7.2381 -29.7256 ```
```C = 5×3 0.0000 0 0 0 0.3155 0 0 0 0.9807 0 0 0 0 0 0 ```
```S = 3×3 1.0000 0 0 0 0.9489 0 0 0 0.1957 ```

Now, perform an economy-size decomposition of `A` and `B`. The matrices `U` and `C` now have three rows instead of five, but the other output matrices are the same.

`[U,V,X,C,S] = gsvd(A,B,"econ")`
```U = 5×3 -0.4780 0.6457 -0.4279 0.7808 0.3296 -0.4375 -0.3081 0.0135 -0.4470 0.1857 -0.3026 -0.4566 -0.1804 -0.6187 -0.4661 ```
```V = 3×3 0.7071 -0.6946 0.1325 0.0000 -0.1874 -0.9823 -0.7071 -0.6946 0.1325 ```
```X = 3×3 2.8284 -9.3761 -6.9346 -5.6569 -8.3071 -18.3301 2.8284 -7.2381 -29.7256 ```
```C = 3×3 0.0000 0 0 0 0.3155 0 0 0 0.9807 ```
```S = 3×3 1.0000 0 0 0 0.9489 0 0 0 0.1957 ```

Calculate the generalized singular values, which in this case are equal to the ratios `diag(C)./diag(S)`. These values are a reordering of the ordinary singular values returned by `svd(A/B)`.

`sigma = gsvd(A,B)`
```sigma = 3×1 0.0000 0.3325 5.0123 ```
`svals = svd(A/B)`
```svals = 3×1 5.0123 0.3325 0.0000 ```

Examine why generalized singular values can sometimes be `Inf`.

Create a 3-by-5 matrix `A` and a 5-by-5 matrix `B`.

`A = reshape(1:15,3,5)`
```A = 3×5 1 4 7 10 13 2 5 8 11 14 3 6 9 12 15 ```
`B = magic(5)`
```B = 5×5 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 ```

Perform a generalized singular value decomposition on `A` and `B`. The outputs include orthogonal `U` and `V`, a nonsingular `X`, and diagonal matrices `C` and `S`. In this situation, the nonzero diagonal of `C` is `diag(C,2)`.

`[U,V,X,C,S] = gsvd(A,B)`
```U = 3×3 0.4082 0.7178 -0.5639 -0.8165 0.0109 -0.5772 0.4082 -0.6961 -0.5906 ```
```V = 5×5 -0.2725 -0.3116 -0.7838 -0.4552 -0.0843 -0.6610 0.0670 0.5070 -0.5408 0.0956 -0.0078 -0.0833 0.1573 -0.0271 -0.9836 0.6218 -0.4832 0.2797 -0.5408 0.0956 0.3195 0.8111 -0.1602 -0.4552 -0.0843 ```
```X = 5×5 -10.1340 0 0.0000 -30.7287 -4.6958 3.3206 1.1584 -14.8596 -28.5003 -11.6858 14.8016 10.1717 6.1195 -26.2720 -18.6758 2.1067 -11.7464 9.5268 -24.0436 -25.6657 -10.0949 0.4163 -0.7867 -21.8152 -32.6557 ```
```C = 3×5 0 0 0.0000 0 0 0 0 0 0.0439 0 0 0 0 0 0.7432 ```
```S = 5×5 1.0000 0 0 0 0 0 1.0000 0 0 0 0 0 1.0000 0 0 0 0 0 0.9990 0 0 0 0 0 0.6690 ```

Find the generalized singular values, which include zeros.

`sigma = gsvd(A,B)`
```sigma = 5×1 0 0 0.0000 0.0439 1.1109 ```

Reversing the roles of `A` and `B` inverts these values, producing `Inf` values.

`sigma2 = gsvd(B,A)`
```sigma2 = 5×1 1016 × 0.0000 0.0000 3.2092 Inf Inf ```

## Input Arguments

collapse all

Input matrices. `A` and `B` must have the same number of columns but can have different numbers of rows.

Data Types: `single` | `double`
Complex Number Support: Yes

## Output Arguments

collapse all

Unitary matrix factors, returned as matrices. `U` and `V` are matrices with orthogonal columns that provide a basis for the columns of `A` and `B`, respectively.

The sizes of `U` and `V` depend on whether you specify the `"econ"` option. If `A` is `m`-by-`p` and `B` is `n`-by-`p`, then:

• By default, `U` is `m`-by-`m` and `V` is `n`-by-`n`.

• If you specify the `"econ"` option, then `U` is `m`-by-`min(m,p)` and `V` is `n`-by-`min(n,p)`.

Matrix factor, returned as a matrix. If `A` is `m`-by-`p` and `B` is `n`-by-`p`, then `X` is `p`-by-`q`, where ```q = min(m+n,p)```.

A property of `X` is that ```norm([A; B]) == norm(X)``` because `U`, `V`, `C`, and `S` represent only an orthogonal basis for the matrix `[A; B]`.

Diagonal matrix factors, returned as matrices. The nonzero elements of `S` are always on its main diagonal. The nonzero elements of `C` are on the diagonal `diag(C,max(0,size(C,2)-size(C,1)))`. To retrieve the nonzero values, use the commands `sv = max(S,[],1)` and ```cv = max(C,[],1)```. The generalized singular values of `A` and `B` are equal to the ratio `cv./sv`.

The sizes of `C` and `S` depend on whether you specify the `"econ"` option. If `A` is `m`-by-`p` and `B` is `n`-by-`p`, then:

• By default, `C` is `m`-by-`q` and `S` is `n`-by-`q`.

• If you specify the `"econ"` option, then `C` is `min(m,p)`-by-`q` and `V` is `min(n,p)`-by-`q`.

In both cases, `q = min(m+n,p)`.

Generalized singular values, returned as a column vector. If ```sv = max(S,[],1)``` and `cv = max(C,[],1)`, then the generalized singular values of `A` and `B` are equal to the ratio `cv./sv`.

`sigma` has length `min(m+n,p)` and is in nondecreasing order.

## Tips

• In this formulation of the `gsvd`, no assumptions are made about the individual ranks of `A` or `B`. The matrix `X` has full rank if and only if the matrix `[A; B]` has full rank. In fact, `svd(X)` and `cond(X)` are equal to `svd([A; B])` and `cond([A; B])`. Other formulations, such as in G. Golub and C. Van Loan , require that `null(A)` and `null(B)` do not overlap and replace `X` with `inv(X)` or `inv(X')`.

Note, however, that when `null(A)` and `null(B)` do overlap, the nonzero elements of `C` and `S` are not uniquely determined.

## Algorithms

The generalized singular value decomposition performed by the `gsvd` function uses the C-S decomposition described in , as well as the built-in `svd` and `qr` functions.

 Golub, Gene H., and Charles F. Van Loan. Matrix Computations. 3rd ed. Johns Hopkins Studies in the Mathematical Sciences. Baltimore: Johns Hopkins University Press, 1996.