Navigation

Operators and Keywords

Function List:

C++ API

Loadable Function: [Q, R, P] = qr (A)
Loadable Function: [Q, R, P] = qr (A, '0')
Loadable Function: [C, R] = qr (A, B)
Loadable Function: [C, R] = qr (A, B, '0')

Compute the QR factorization of A, using standard LAPACK subroutines.

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). The QR factorization is Q * R = A where Q is an orthogonal matrix and R is upper triangular.

If given a second argument of '0', qr returns an economy-sized QR factorization, omitting zero rows of R and the corresponding columns of Q.

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 compute the sparse QR factorization of A, using CSPARSE. As the matrix Q is in general a full matrix, this function returns the Q-less factorization R of A, such that R = chol (A' * A).

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. That is R will have only size (A,1) rows.

If an additional matrix B is supplied, 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

See also: chol, hess, lu, qz, schur, svd, qrupdate, qrinsert, qrdelete, qrshift.

Package: octave