MATLAB Function Reference
  Go to function:
    Search    Help Desk 
qr    Examples   See Also

Orthogonal-triangular decomposition

Syntax

Description

The qr function performs the orthogonal-triangular decomposition of a matrix. This factorization is useful for both square and rectangular matrices. It expresses the matrix as the product of a real orthonormal or complex unitary matrix and an upper triangular matrix.

[Q,R] = qr(X) produces an upper triangular matrix R of the same dimension as X and a unitary matrix Q so that X = Q*R.

[Q,R,E] = qr(X) produces a permutation matrix E, an upper triangular matrix R with decreasing diagonal elements, and a unitary matrix Q so that X*E = Q*R. The column permutation E is chosen so that abs(diag(R)) is decreasing.

[Q,R] = qr(X,0) and [Q,R,E] = qr(X,0) produce "economy-size" decompositions in which E is a permutation vector, so that Q*R = X(:,E). The column permutation E is chosen so that abs(diag(R)) is decreasing.

A = qr(X) returns the output of the LINPACK subroutine ZQRDC. triu(qr(X)) is R.

Examples

Start with

This is a rank-deficient matrix; the middle column is the average of the other two columns. The rank deficiency is revealed by the factorization:

The triangular structure of R gives it zeros below the diagonal; the zero on the diagonal in R(3,3) implies that R, and consequently A, does not have full rank.

The QR factorization is used to solve linear systems with more equations than unknowns. For example

The linear system Ax = b represents four equations in only three unknowns. The best solution in a least squares sense is computed by

which produces

The quantity tol is a tolerance used to decide if a diagonal element of R is negligible. If [Q,R,E] = qr(A), then

The solution x was computed using the factorization and the two steps

The computed solution can be checked by forming Ax. This equals b to within roundoff error, which indicates that even though the simultaneous equations Ax = b are overdetermined and rank deficient, they happen to be consistent. There are infinitely many solution vectors x; the QR factorization has found just one of them.

Algorithm

The qr function uses the LINPACK routines ZQRDC and ZQRSL. ZQRDC computes the QR decomposition, while ZQRSL applies the decomposition.

See Also

\       Matrix left division (backslash)

/           Matrix right division (slash)

lu          LU matrix factorization

null        Null space of a matrix

orth        Range space of a matrix

qrdelete    Delete column from QR factorization

qrinsert    Insert column in QR factorization

References

Dongarra, J.J., J.R. Bunch, C.B. Moler, and G.W. Stewart, LINPACK Users' Guide, SIAM, Philadelphia, 1979.



[ Previous | Help Desk | Next ]