function T = compactWY(V,beta)
% Computes the compact WY representation of a product of k Householder % reflectors.
%
%
%
%Input: V - m-by-k matrix containing the vectors v_j
%beta - vector of length k containing the scalar factors beta_j
%Output: T - upper triangular factor of the compact WY representation
[m,k] = size(V); 
T = zeros(k); 
for j = 1:k
T(1:j-1,j) = -beta * T(1:j-1,1:j-1) * ( V(:,1:j-1)'*V(:,j) );
T(j,j) = beta; %beta(j)
end
end