# orth

Orthonormal basis for range of matrix

## Syntax

``Q = orth(A)``
``Q = orth(A,tol)``

## Description

example

````Q = orth(A)` returns an orthonormal basis for the range of `A`. The columns of matrix `Q` are vectors that span the range of `A`. The number of columns in `Q` is equal to the rank of `A`.```
````Q = orth(A,tol)` also specifies a tolerance. Singular values of `A` less than `tol` are treated as zero, which can affect the number of columns in `Q`.```

## Examples

collapse all

Calculate and verify the orthonormal basis vectors for the range of a full rank matrix.

Define a matrix and find the rank.

```A = [1 0 1;-1 -2 0; 0 1 -1]; r = rank(A)```
```r = 3 ```

Because `A` is a square matrix of full rank, the orthonormal basis calculated by `orth(A)` matches the matrix `U` calculated in the singular value decomposition `[U,S] = svd(A,"econ")`. The reason is that the singular values of `A` are all nonzero.

Calculate the orthonormal basis for the range of `A` using `orth`.

`Q = orth(A)`
```Q = 3×3 -0.1200 -0.8097 0.5744 0.9018 0.1531 0.4042 -0.4153 0.5665 0.7118 ```

The number of columns in `Q` is equal to `rank(A)`. Because `A` is full rank, `Q` and `A` are the same size.

Verify that the basis, `Q`, is orthogonal and normalized within a reasonable error range.

`E = norm(eye(r)-Q'*Q,"fro")`
```E = 9.2306e-16 ```

The error is on the order of `eps`.

Calculate and verify the orthonormal basis vectors for the range of a rank deficient matrix.

Define a singular matrix and find the rank.

```A = [1 0 1; 0 1 0; 1 0 1]; r = rank(A)```
```r = 2 ```

Because `A` is rank deficient, the orthonormal basis calculated by `orth(A)` matches only the first `r = 2` columns of matrix `U` calculated in the singular value decomposition `[U,S] = svd(A,"econ")`. The reason is that the singular values of `A` are not all nonzero.

Calculate the orthonormal basis for the range of `A` using `orth`.

`Q = orth(A)`
```Q = 3×2 -0.7071 -0.0000 0 1.0000 -0.7071 0.0000 ```

Because `A` is rank deficient, `Q` contains one fewer column than `A`.

When a matrix has small singular values, specify a tolerance to change which singular values are treated as zero.

Create a 7-by-7 Hilbert matrix. This matrix is full rank but has some small singular values.

`H = hilb(7)`
```H = 7×7 1.0000 0.5000 0.3333 0.2500 0.2000 0.1667 0.1429 0.5000 0.3333 0.2500 0.2000 0.1667 0.1429 0.1250 0.3333 0.2500 0.2000 0.1667 0.1429 0.1250 0.1111 0.2500 0.2000 0.1667 0.1429 0.1250 0.1111 0.1000 0.2000 0.1667 0.1429 0.1250 0.1111 0.1000 0.0909 0.1667 0.1429 0.1250 0.1111 0.1000 0.0909 0.0833 0.1429 0.1250 0.1111 0.1000 0.0909 0.0833 0.0769 ```

Calculate an orthonormal basis for the range of `H`. Because `H` is full rank, `Q` and `H` are the same size.

`Q = orth(H)`
```Q = 7×7 -0.7332 0.6232 0.2608 -0.0752 0.0160 -0.0025 0.0002 -0.4364 -0.1631 -0.6706 0.5268 -0.2279 0.0618 -0.0098 -0.3198 -0.3215 -0.2953 -0.4257 0.6288 -0.3487 0.0952 -0.2549 -0.3574 0.0230 -0.4617 -0.2004 0.6447 -0.3713 -0.2128 -0.3571 0.2337 -0.1712 -0.4970 -0.1744 0.6825 -0.1831 -0.3446 0.3679 0.1827 -0.1849 -0.5436 -0.5910 -0.1609 -0.3281 0.4523 0.5098 0.4808 0.3647 0.1944 ```

Now, calculate the orthonormal basis vectors again, but specify a tolerance of `1e-4`. This tolerance leads to `orth` treating three of the singular values as zeros, so the orthonormal basis has only four columns.

`Qtol = orth(H,1e-4)`
```Qtol = 7×4 -0.7332 0.6232 0.2608 -0.0752 -0.4364 -0.1631 -0.6706 0.5268 -0.3198 -0.3215 -0.2953 -0.4257 -0.2549 -0.3574 0.0230 -0.4617 -0.2128 -0.3571 0.2337 -0.1712 -0.1831 -0.3446 0.3679 0.1827 -0.1609 -0.3281 0.4523 0.5098 ```

## Input Arguments

collapse all

Input matrix.

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

Singular value tolerance, specified as a real numeric scalar. Singular values of `A` less than the tolerance are treated as zero, which affects the number of column space vectors returned by `orth`. The default tolerance is `max(size(A)) * eps(norm(A))`.

collapse all

### Range

The column space, or range, of a matrix `A` is the collection of all linear combinations of the columns of `A`. Any vector, `b`, that is a solution to the linear equation `A*x = b` is included in the range of `A` because you can also write it as a linear combination of the columns of `A`.

### Rank

The `rank` of a matrix is equal to the dimension of the range, and is equal to the number of nonzero singular values.

## Algorithms

The orthonormal basis for the range of `A` is obtained from `U` in the singular value decomposition ```[U,S] = svd(A,"econ")```. If `r = rank(A,tol)`, then the first `r` columns of `U` form an orthonormal basis for the range of `A`.

## Version History

Introduced before R2006a

expand all