% MULBAND   multiply a vector with a symmetric band matrix
%       
%       x=MULBAND(B,b)
%       Given a matrix B which contains the rows of the Band matrix up to
%       the diagonal, this function returns the multiplication of this
%       band matrix with the vector b
%       
%       Input format of B with bandwidth 2l+1
%
%       [0...................................b(1,1)]
%       [0............................b(2,1),b(2,2)]
%       [0.....................b(3,1),b(3,2),b(3,3)]
%       [..........................................]
%       [b(l+1,1),b(l+1,2),b(l+1,3)......b(l+1,l+1)]
%       [b(l+2,2),b(l+2,3),b(l+3,4)......b(l+2,l+2)]
%       [..........................................]
%
%       b should be an arbitrary column vector of corresponding dimension.
%       the output vector x contains the solution
%       
%
%
%       Software of the MaSe - Group
%       mase-at-cs.kuleuven.ac.be
%       Revision Date: 08/04/2005



function b=MULBAND(B,x)
  
  % initialization of the size and bandwidth of B
    [n,l]=size(B);
    l=l-1; % the bandwidth of B
    
  % for easiness of operations we have to define fliplr for extracting
  % the anti diagonals
  Bf=fliplr(B);
  

  if l==0
    % this means B is a diagonal matrix
    b=B.*x;
  else
     
  % start the main loop
  for i=1:n-1
    % the lower triangular part
    lowbx=max(1,i-l);
    b(i)=B(i,l-i+lowbx+1:l+1)*x(lowbx:i);
    
    % the upper triangular part
    upbx=min(n,i+l);
    dbf=diag(Bf,-i+1);
    dbf=dbf(2:length(dbf));
    b(i)=b(i)+dbf'*x(i+1:upbx);
  end
  
   b(n)=B(n,:)*x(n-l:n);
  
   
  b=b';
  end