QR decomposition
[Q,R]=qr(X [,"e"])
[Q,R,E]=qr(X [,"e"])
[Q,R,rk,E]=qr(X [,tol])
:X real or complex matrix : :tol nonnegative real number : :Q square orthogonal or unitary matrix : :R matrix with same dimensions as X : :E permutation matrix : :rk integer (QR-rank of X) :
:
// QR factorization, generic case
// X is tall (full rank)
X=`rand`_(5,2);[Q,R]=qr(X); [Q'*X R]
//X is fat (full rank)
X=`rand`_(2,3);[Q,R]=qr(X); [Q'*X R]
//Column 4 of X is a linear combination of columns 1 and 2:
X=`rand`_(8,5);X(:,4)=X(:,1)+X(:,2); [Q,R]=qr(X); R, R(:,4)
//X has rank 2, rows 3 to $ of R are zero:
X=`rand`_(8,2)*`rand`_(2,5);[Q,R]=qr(X); R
//Evaluating the rank rk: column pivoting ==> rk first
//diagonal entries of R are non zero :
A=`rand`_(5,2)*`rand`_(2,5);
[Q,R,rk,E] = qr(A,1.d-10);
`norm`_(Q'*A-R)
`svd`_([A,Q(:,1:rk)]) //span(A) =span(Q(:,1:rk))
qr decomposition is based the Lapack routines DGEQRF, DGEQPF, DORGQR for the real matrices and ZGEQRF, ZGEQPF, ZORGQR for the complex case.