1function varargout=RightQR(varargin)
4% Computes an orthogonal factorization Q such that A*Q = R
is lower triangular
5% by means of householder transformations
7% when a third output argument
is added a row permutation
is done such that
8% diagonal elements of R are sorted in absolute decreasing values
9% [R,Q,e]=RightQR(A), A(:,e)*Q = R
11% Remark .- Real and complex matrix ar supported
13% Author : Alain Barraud, copyright abc.consultant@wanadoo.fr 2003-2018
15%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17if narg==0,error(
'RightQR requires at least one argument');end
19if nargout==3, Pivoting=
true;
else, Pivoting=
false;end
20%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21%initialisation and memory allocation
22[m,n] = size(A);%A dimension
23if Pivoting, e=(1:m);end
25Q=eye(n);%memory allocation
27for k = 1:r%loop on the A rows
29 J=(k:n);%the set of used columns indices
for pivoting
30 I=(k:m);%the set of used rows indices
for pivoting
31 tmp=sum(A(I,J).*conj(A(I,J)),2);[tmpx,piv]=max(tmp);
32 piv=k-1+piv;%piv
is the next row to be used
33 if piv~=k, tmp=e(k);e(k)=e(piv);e(piv)=tmp;tmp=A(k,:);A(k,:)=A(piv,:);A(piv,:)=tmp;end
35 [A(k,:),uk,betak]=CHouseholder(A(k,:),k+1:n,k);%compute the kth Householder transformation
44 %apply
this transformation to rows A(I,:) if any
45 if k<m, I=(k+1:m);A(I,:)=ApplyHouseholder(A(I,:),uk(:),betak,
'R');end
46 Q=ApplyHouseholder(Q,uk(:),betak,
'R');
48varargout{1}=A(1:r,:);varargout{2}=Q;
49if nargout==3, varargout{3}=e;end
50%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%