%  MULSS   performs an O(n) matrix vector multiplication
%    
%    B=MULSS(G,d,X) is the vector B=SS*X where SS is the
%    symmetric semiseparable matrix constructed from 
%    the givens vector representation, denoted with G,d
%     
%    B=MULSS(G,d,G1,d1,X) performs the multiplication
%    SS*X where SS is the nonsymmetric semiseparable matrix 
%    where the lower triangular part is constructed with the 
%    Givens vector representation G,d, and the upper triangular 
%    part is constructed from left to right with the Givens
%    vector representation G1,d1
%
%
%    Software of the MaSe - Group
%    mase-at-cs.kuleuven.ac.be
%    Revision Date: 16/12/2003
%


function b=MULSS(G,d,G1,d1,x)
    
  n=length(d);
  if n~=0
    if nargin==3
      x=G1;
      for i=1:n-1
        d1(i)=G(2,i)*d(i);
      end
      G1=G(:,2:n-1);
    end
    
    % performs the multiplication
    % with the lower triangular semiseparable
    % part
    b(1)=x(1)*d(1);
    for i=1:n-1
      wv=b(i);
      b(i)=G(1,i)*wv;
      b(i+1)=G(2,i)*wv+x(i+1)*d(i+1);    
    end
  
    % performs the multiplication with the
    % upper triangular part of the matrix
    if n~=1
      b2(n-1)=x(n); 
      for i=n-2:-1:1
        b2(i)=b2(i+1)*G1(2,i)+G1(1,i)*x(i+1);
        b2(i+1)=b2(i+1)*d1(i+1);
      end
      
      b2(1)=b2(1)*d1(1);
      
      b=(b+[b2,0])';
    end
  else
    b=[];
  end
  
  