# gsvd

Generalized singular value decomposition

## Syntax

## Description

returns the vector of generalized singular values,
`sigma`

= gsvd(`A`

,`B`

)`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

### Generalized Singular Value Decomposition of Matrices

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

### Matrices with Infinite Singular Values

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×110^{16}× 0.0000 0.0000 3.8953 Inf Inf

## Input Arguments

`A`

, `B`

— Input matrices (as separate arguments)

matrices

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

`U`

, `V`

— Unitary matrix factors

matrices

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)`

.

`X`

— Matrix factor

matrix

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]`

.

`C`

, `S`

— Diagonal matrix factors

matrices

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]
```

.

`sigma`

— Generalized singular values

column vector

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.

## Extended Capabilities

### Thread-Based Environment

Run code in the background using MATLAB® `backgroundPool`

or accelerate code with Parallel Computing Toolbox™ `ThreadPool`

.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

## Version History

**Introduced before R2006a**

### R2022b: Output size based on numerical rank

With the function call `[U,V,X,C,S] = gsvd(A,B)`

, where
`A`

is `m`

-by-`p`

and
`B`

is `n`

-by-`p`

, the
`gsvd`

function returns:

`X`

as`p`

-by-`q`

`C`

as`m`

-by-`q`

`S`

as`n`

-by-`q`

Additionally, with one output argument the function call ```
sigma =
gsvd(A,B)
```

returns a vector of the generalized singular values with length
`q`

.

The behavior change is that in all of these cases `q`

is now equal to
the numerical rank of `[A; B]`

. The numerical rank is calculated from the
QR factorization of `[A; B]`

. This change ensures that nonzero elements of
`C`

and `S`

are uniquely determined.

Previously, the value of `q`

was `min(m+n,p)`

, and
`gsvd`

returned extra columns (or elements) in the outputs when
`[A; B]`

was not full rank.

### R2022b: "0" syntax not recommended for economy-size decompositions

The syntax `[U,V,X,C,S] = gsvd(A,B,0)`

will continue to be supported,
but is no longer recommended. Use the `"econ"`

option to perform
economy-size decompositions instead.

### R2022a: Option for economy-size decompositions

Use the `"econ"`

option to calculate economy-size decompositions with
`gsvd`

. The functionality is the same as
`gsvd(A,B,0)`

.

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)