# qr

QR decomposition

## Syntax

## Description

`[___] = qr(`

produces an
economy-size decomposition using any of the previous output argument combinations. The
size of the outputs depends on the size of `A`

,"econ")`m`

-by-`n`

matrix `A`

:

If

`m > n`

, then`qr`

computes only the first`n`

columns of`Q`

and the first`n`

rows of`R`

.If

`m <= n`

, then the economy-size decomposition is the same as the regular decomposition.

`[`

specifies whether to return the permutation information `Q`

,`R`

,`P`

] = qr(`A`

,`outputForm`

)`P`

as a matrix
or a vector. For example, if `outputForm`

is `"vector"`

,
then `A(:,P) = Q*R`

. The default value of `outputForm`

is `"matrix"`

such that `A*P = Q*R`

.

`[___] = qr(`

is equivalent to
`A`

,0)`qr(A,"econ","vector")`

. The use of this syntax is not recommended. Use
the `"econ"`

option instead.

`[___] = qr(`

produces an economy-size decomposition using any of the previous output argument
combinations. The size of the outputs depends on the size of
`S`

,`B`

,"econ")`m`

-by-`n`

sparse matrix `S`

:

If

`m > n`

, then`qr`

computes only the first`n`

rows of`C`

and`R`

.If

`m <= n`

, then the economy-size decomposition is the same as the regular decomposition.

`[`

specifies whether to return the permutation information `C`

,`R`

,`P`

] = qr(`S`

,`B`

,`outputForm`

)`P`

as a matrix
or vector. For example, if `outputForm`

is `"vector"`

,
then the least-squares solution to `S*X = B`

is ```
X(P,:) =
R\C
```

. The default value of `outputForm`

is
`"matrix"`

such that the least-squares solution to ```
S*X =
B
```

is `X = P*(R\C)`

.

## Examples

## Input Arguments

## Output Arguments

## Tips

To solve multiple linear systems involving the same coefficient matrix, use

`decomposition`

objects.For the syntax

`[C,R] = qr(S,B)`

, the value of`X = R\C`

is a least-squares solution to`S*X = B`

only when`S`

does not have low rank.

## References

[1] Anderson, E., ed. *LAPACK Users’ Guide*. 3rd ed. Software, Environments, Tools.
Philadelphia: Society for Industrial and Applied Mathematics, 1999. https://doi.org/10.1137/1.9780898719604.

[2] Davis, Timothy A. “Algorithm 915,
SuiteSparseQR: Multifrontal Multithreaded Rank-Revealing Sparse QR Factorization.”
*ACM Transactions on Mathematical Software* 38, no. 1 (November 2011):
1–22. https://doi.org/10.1145/2049662.2049670.

## Extended Capabilities

## Version History

**Introduced before R2006a**

## See Also

`lu`

| `chol`

| `null`

| `orth`

| `qrdelete`

| `qrinsert`

| `qrupdate`

| `decomposition`

| `lsqminnorm`

| `rank`