LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
RightQR.m
1function varargout=RightQR(varargin)
2%
3% [R,Q]=RightQR(A)
4% Computes an orthogonal factorization Q such that A*Q = R is lower triangular
5% by means of householder transformations
6%
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
10%
11% Remark .- Real and complex matrix ar supported
12%
13% Author : Alain Barraud, copyright abc.consultant@wanadoo.fr 2003-2018
14%
15%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16narg=nargin;
17if narg==0,error('RightQR requires at least one argument');end
18A=varargin{1};
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
24r=min(m,n);
25Q=eye(n);%memory allocation
26%begin factorization
27for k = 1:r%loop on the A rows
28 if Pivoting
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
34 end
35 [A(k,:),uk,betak]=CHouseholder(A(k,:),k+1:n,k);%compute the kth Householder transformation
36 if Pivoting
37 if k==1
38 Ref=abs(A(1,1));
39 elseif tmpx<n*eps*Ref
40 A(k:m,:)=0;
41 break
42 end
43 end
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');
47end
48varargout{1}=A(1:r,:);varargout{2}=Q;
49if nargout==3, varargout{3}=e;end
50%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%