LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ApplyHouseholder.m
1function M=ApplyHouseholder(M,u,b,side)
2% M=ApplyHouseholder(M,u,b,side)
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4%
5% Apply an elementary Householder transformation Q from the RIGHT or from
6% the LEFT, according to side, to a set of vectors packed as a matrix M
7% u and b are previously computed by CHouseholder
8%
9% INPUT
10% M : the input matrix, size mxn, considered as n columns ('Left') or m rows ('Right')
11% u : such that Q = I - 2*u*u'/(u'*u), mx1 ('Left') or size nx1 ('Right')
12% b : a pre computed value used to speed up Q*w(:) product
13% side : specifies the side upon which Q is applied, recognised values :
14% 'L' stands for 'Left' multiplication, default value
15% 'R' stands for 'Right' multiplication
16%
17% OUTPUT
18% M : the transformed matrix Q*M ('Left') or M*Q ('Right')
19%
20% Author : Alain Barraud, copyright abc.consultant@wanadoo.fr 2003-2015
21%
22%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23%force upper case
24if nargin==3, side='L';else, side=upper(side(1));end
25I = find(u~=0);
26if b==0||isempty(I); return;end
27v=u(I);%only non trivial part of u is used
28switch side
29 case 'R'
30 tau=v*b;
31 tau=M(:,I)*tau;%intermediate row vector
32 M(:,I) =M(:,I) + tau*v';%transformed M
33 case 'L'
34 tau=v'*b;tau=tau*M(I,:);%intermediate row vector
35 M(I,:) =M(I,:) + v*tau;%transformed M
36end
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%