1function varargout=LeftQR(varargin)
4% Computes an orthogonal factorization Q such that Q*A = R
is upper triangular
5% by means of householder transformations
7% when a third output argument
is added a column permutation
is done such that
8% diagonal elements of R are sorted in absolute decreasing values
9% [R,Q,e]=LeftQR(A), Q*A(:,e)=R
11% when a second input arguments
is present, Q
is not computed explicitly.
12% orthogonal transformations are directly applied to B.
13% on output B contains the transformed B.
17% Remark .- Real and complex matrix ar supported
19% Author : Alain Barraud, copyright abc.consultant@wanadoo.fr 2003-2018
21%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23if narg==0,error(
'LeftQR requires at least one argument');end
30if nargout==3, Pivoting=
true;
else, Pivoting=
false;end
31%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32%initialisation and memory allocation
33[m,n] = size(A);%A dimension
34if Pivoting, e=(1:n);end
37 Q=eye(m);%memory allocation
40for k = 1:r%loop on the A columns
41 if Pivoting%
do columns permutation (rank revealing)
42 I=(k:m);%the set of used row indices
for pivoting
43 J=(k:n);%the set of used columns indices
for pivoting
44 tmp=sum(A(I,J).*conj(A(I,J)),1);[tmpx,piv]=max(tmp);
45 piv=k-1+piv;%piv
is the next column to be used
46 if piv~=k, tmp=e(k);e(k)=e(piv);e(piv)=tmp;tmp=A(:,k);A(:,k)=A(:,piv);A(:,piv)=tmp;end
48 [A(:,k),uk,betak]=CHouseholder(A(:,k),(k+1:m),k);%compute the kth Householder transformation
57 %apply
this transformation to the following A(:,J) columns if any
58 if k<n,J=(k+1:n);A(:,J)=ApplyHouseholder(A(:,J),uk,betak,
'L');end
59 if nargin==1%Compute Q explicitly
60 Q=ApplyHouseholder(Q,uk,betak,
'L');
61 elseif ~isempty(B)%apply Q to B
62 B=ApplyHouseholder(B,uk,betak,
'L');
74%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%