Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

qr - Orthogonal-triangular decomposition

Syntax

[Q,R] = qr(A)
[Q,R] = qr(A,0)
[Q,R,E] = qr(A)
[Q,R,E] = qr(A,0)
X = qr(A)
X = qr(A,0)
R = qr(A)

Description

[Q,R] = qr(A), where A is m-by-n, produces an m-by-n upper triangular matrix R and an m-by-m unitary matrix Q so that A = Q*R.

[Q,R] = qr(A,0) produces the economy-size decomposition. If m > n, only the first n columns of Q and the first n rows of R are computed. If m<=n, this is the same as [Q,R] = qr(A).

If A is full:

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

[Q,R,E] = qr(A,0) produces an economy-size decomposition in which E is a permutation vector, so that A(:,E) = Q*R.

X = qr(A) and X = qr(A,0) return a matrix X such that triu(X) is the upper triangular factor R.

If A is sparse:

R = qr(A) computes a Q-less QR decomposition and returns the upper triangular factor R. Note that R = CHOL(A'*A). Since Q is often nearly full, this is preferred to [Q,R] = QR(A).

R = qr(A,0) produces economy-size R. If m>n, R has only n rows. If m<=n, this is the same as R = qr(A).

[Q,R,E] = qr(A) produces unitary Q, upper triangular R and a permutation matrix E so that A*E = Q*R. The column permutation E is chosen to reduce fill-in in R.

[Q,R,E] = qr(A,0) produces an economy-size decomposition in which E is a permutation vector, so that A(:,E) = Q*R.

[C,R] = qr(A,B), where B has as many rows as A, returns C = Q'*B. The least-squares solution to A*X = B is X = R\C.

[C,R,E] = qr(A,B), also returns a fill-reducing ordering. The least-squares solution to A*X = B is X = E*(R\C).

[C,R] = qr(A,B,0) produces economy-size results. If m>n, C and R have only n rows. If m<=n, this is the same as [C,R] = qr(A,B).

[C,R,E] = qr(A,B,0) additionally produces a fill-reducing permutation vector E. In this case, the least-squares solution to A*X = B is X(E,:) = R\C.

Examples

Find the least squares approximate solution to A*x = b with the Q-less QR decomposition and one step of iterative refinement:

if issparse(A), R = qr(A); 
else R = triu(qr(A)); end
x = R\(R'\(A'*b));
r = b - A*x;
e = R\(R'\(A'*r));
x = x + e;

See Also

ldl | lu

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS