qr
QR factorization: an orthogonal factor Q and an upper-triangular factor R.
Category: Mathematics > Linear Algebra
Syntax
R = qr(A)
Returns only the triangular factor.
[Q, R] = qr(A)
Returns Q and R with A = Q*R; for an m-by-n matrix Q is m-by-m.
[Q, R] = qr(A, 0)
Economy size: for m > n, Q is m-by-n and R is n-by-n.
[Q, R, P] = qr(A)
Adds column pivoting, so that A*P = Q*R and the diagonal of R is non-increasing in magnitude.
Description
The factorization is computed with Householder reflections, which is numerically stable. The signs of the columns of Q and the rows of R are a convention, so they may differ from other software even though the product is the same.
QR is the standard route to least-squares problems: for an overdetermined system, solve the triangular system R*x = Q'*b. Column pivoting additionally reveals the numerical rank.
Input arguments
A- Numeric matrix of any shape.
0 or 'econ'- Requests the economy-size factorization.
Output arguments
Q- Orthogonal (unitary, if
Ais complex) matrix. R- Upper-triangular (trapezoidal) matrix.
P- Permutation matrix of the column pivoting.
Example
Factor and rebuild
A = [1 2; 3 4];
[Q, R] = qr(A)
norm(Q*R - A) < 1e-12
Q = 2×2
-0.3162 -0.9487
-0.9487 0.3162
R = 2×2
-3.1623 -4.4272
0 -0.6325
ans = logical
1