function Mar4()
% Multiple RHS LS using thin QR
clc
format short
m = 8; n = 4; p = 5;
A = randn(m,n); B = randn(m,p);
[Q,R] = qr(A,0);
% The single rhs LS problem min(Ax-b) is solved by x= R\(Q'*b);
% Now we do the same thing for each B column..
X1 = zeros(n,p);
for k=1:p
    X1(:,k) = R\(Q'*B(:,k));
end
X1 = X1
% Or in vectorized form...
X= R\(Q'*B)
