%   YWSOLVERHSS  Solves a Yule Walker system of equations for a 
%                strongly nonsingular higher order semiseparable matrix
%    
%    X=YWSOLVERSS(u,v) is the solution of the system S X=-v,
%    the matrix S is a higher order semiseparable matrix represented
%    with two vectors u,v
% 
%    For more information concerning the matrix S and the solving of the
%    system, check the corresponding paper.
%    
%
%
%    Software of the MaSe - Group
%    mase-at-cs.kuleuven.ac.be
%    Revision Date: 06/04/2005
%

function y=YWSOLVERHSS(u,v)
  
  % let us start the initialization procedure
  % with n we denote the size of the matrix
  % with p we denote the semiseparability rank
  % of the semiseparable matrix generated by u and v
    
  [n,p]=size(u);
  
  % initializing the loop
  alpha(1,:)=-v(1,:)./(u(1,:)*v(1,:)');
  y=alpha;
  
  % ry stands for the inproduct matrix, this matrix
  % is of dimension p x p
  ry=v(1,:)'*y;
  
  % r is the righthandside, this is also a growing matrix.
  % but because we do not want to reallocate memory everytime,
  % we do not define the matrix because it is in fact the matrix v

  
  % the main loop in which we use always the previous solution
  for k=2:n
    % The product u*ry appears twice
    ury=u(k,:)*ry;
    
    % first we calculate the vector alpha
    denominator=ury*u(k,:)'+u(k,:)*v(k,:)';
    
    % we need to store alpha, because we will need it
    % afterwards for constructing the solution
    alpha(k,:)=(-1)*(v(k,:)+ury)/denominator;
       
    % let us calculate the new inner product matrix ry
    ry=ry+(ry*u(k,:)'+v(k,:)')*alpha(k,:);
    
  end
  
  
  % This part is excluded from the main loop, because in this way, we
  % can dramatically reduce the complexity of the overall algorithm
  
  % initialization
  y=zeros(n,p);
  y(n,:)=alpha(n,:);
  
  % F is the p x p matrix used as the factor 
  F=eye(p);
  
  % starting the construction of y
  for i=n-1:-1:1
    F= F+ u(i+1,:)'* y(i+1,:); 
    y(i,:)=alpha(i,:)*F;   
  end
  
  
  
end
  
  
  