In QR factorization of an m-by-n matrix A where n > m, only the first m columns of A are needed to compute Q. Therefore, you can obtain Q from the smaller m-by-m matrix formed from the first m columns of A. The following small example demonstrates this idea:
m = 40;
n = 100;
A = rand(m,n);
[Q, ~] = qr(A);
Asmall = A(:,1:m);
[Q2, ~] = qr(Asmall);
err = norm(Q - Q2)
Note that this approach will work even if A is full rank but 'Asmall' is not full rank. In general, the QR decomposition is not unique. Even in the case of 'Asmall' not being full rank, Q will still be unitary, and there will still exist an R such that Q*R = A for the given Q matrix. The first m columns of such an R are computed (although we are not interested in them). The m+1:n columns of R will not be computed, but there is no doubt about their existence. They will be whatever they need to be so that Q*R=A.
Best Answer