- :
*[*`Q`,`R`] =**qr***(*`A`) - :
*[*`Q`,`R`,`P`] =**qr***(*`A`) # non-sparse A - :
`X`=**qr***(*`A`) - :
`R`=**qr***(*`A`) # sparse A - :
*[*`C`,`R`] =**qr***(*`A`,`B`) - :
*[…] =***qr***(…, 0)* - :
*[…] =***qr***(…, 'vector')* - :
*[…] =***qr***(…, 'matrix')* -
Compute the QR factorization of

`A`, using standard LAPACK subroutines. The QR factorization is

where`Q`*`R`=`A``Q`is an orthogonal matrix and`R`is upper triangular.For example, given the matrix

,`A`= [1, 2; 3, 4][

`Q`,`R`] = qr (`A`)returns

`Q`= -0.31623 -0.94868 -0.94868 0.31623`R`= -3.16228 -4.42719 0.00000 -0.63246The

`qr`

factorization has applications in the solution of least squares problemsmin norm(A x - b)

for overdetermined systems of equations (i.e.,

`A`is a tall, thin matrix).If only a single return value is requested, then it is either

`R`if`A`is sparse, or`X`such that

if`R`= triu (`X`)`A`is full. (Note: Unlike most commands, the single return value is not the first return value when multiple are requested.)If the matrix

`A`is full, the permuted QR factorization`[`

forms the QR factorization such that the diagonal entries of`Q`,`R`,`P`] = qr (`A`)`R`are decreasing in magnitude order. For example, given the matrix`a = [1, 2; 3, 4]`

,[

`Q`,`R`,`P`] = qr (`A`)returns

`Q`= -0.44721 -0.89443 -0.89443 0.44721`R`= -4.47214 -3.13050 0.00000 0.44721`P`= 0 1 1 0The permuted

`qr`

factorization`[`

factorization allows the construction of an orthogonal basis of`Q`,`R`,`P`] = qr (`A`)`span (A)`

.If the matrix

`A`is sparse, then the sparse QR factorization of`A`is computed using CSPARSE. As the matrix`Q`is in general a full matrix, it is recommended to request only one return value, which is the`Q`-less factorization`R`of`A`, such that

.`R`= chol (`A`' *`A`)If an additional matrix

`B`is supplied and two return values are requested, then`qr`

returns`C`, where

. This allows the least squares approximation of`C`=`Q`' *`B`

to be calculated as`A`\`B`[

`C`,`R`] = qr (`A`,`B`) x =`R`\`C`If the final argument is the scalar 0 and the number of rows is larger than the number of columns, then an

`"economy"`

factorization is returned, omitting zeroes of`R`and the corresponding columns of`Q`. That is,`R`will have only`size (`

rows. In this case,`A`,1)`P`is a vector rather than a matrix.If the final argument is the string

`"vector"`

then`P`is a permutation vector instead of a permutation matrix.**See also:**chol, hess, lu, qz, schur, svd, qrupdate, qrinsert, qrdelete, qrshift.

Package: octave