Navigation

Operators and Keywords

Function List:

C++ API

: [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 Q * R = A where 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.63246

The qr factorization has applications in the solution of least squares problems

min 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 R = triu (X) if 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 [Q, R, P] = qr (A) forms the QR factorization such that the diagonal entries of 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  0

The permuted qr factorization [Q, R, P] = qr (A) factorization allows the construction of an orthogonal basis of 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 C = Q' * B. This allows the least squares approximation of A \ B to be calculated as

[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 (A,1) rows. In this case, 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