# 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")`. The use of this syntax is not recommended. Use the `"econ"` option instead.```

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.1882 0.6457 -0.4279 -0.4268 -0.4271 0.6897 0.3296 -0.4375 0.2067 0.4261 -0.6849 0.0135 -0.4470 0.2542 0.5160 0.0534 -0.3026 -0.4566 0.5787 -0.6019 0.1300 -0.6187 -0.4661 -0.6128 0.0869 ```
```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` have different sizes, but the other output matrices are the same.

`[U,V,X,C,S] = gsvd(A,B,"econ")`
```U = 5×3 -0.3736 -0.6457 0.4279 -0.0076 -0.3296 0.4375 0.8617 -0.0135 0.4470 -0.2063 0.3026 0.4566 -0.2743 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 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.4998 -0.6586 0.3195 -0.4552 -0.0843 0.1754 0.5301 0.6218 -0.5408 0.0956 -0.0423 0.1729 -0.0078 -0.0271 -0.9836 -0.3869 0.3344 -0.6610 -0.5408 0.0956 0.7536 -0.3788 -0.2725 -0.4552 -0.0843 ```
```X = 5×5 -0.2115 0.8645 10.0949 -30.7287 -4.6958 -2.4503 -14.9242 -2.1067 -28.5003 -11.6858 11.6680 2.1838 -14.8016 -26.2720 -18.6758 -9.0062 11.8759 -3.3206 -24.0436 -25.6657 0 0 10.1340 -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.8953 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` is the numerical rank of `[A; B]`.

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` is the numerical rank of ```[A; B]```.

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 equal to the numerical rank of ```[A; B]``` and is in nondecreasing order.

## Algorithms

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

## Version History

Introduced before R2006a

expand all