The algorithm

The function below solves a symmetric band system of equations. The input consists of the right-hand side $ b$ and the matrix $ A$ representing the band matrix $ B$. The output of the algorithm is the vector $ x=B^{-1}b$. The number of operations in each step is given at the end of the line.


[fontsize=\footnotesize,numbers=left,frame=single,commandchars=\\\{\},label=\verbtitle{Levinson
  solver for band matrices},
codes={\catcode`$=3\catcode`^=7}]

FUNCTION x=LEVSOLVERBAND(A,b)
   
  %--------PART 1: SOLVE THE SYSTEM----------------------------
  % Initialisation:n=size,2l+1=bandwidth
  [n,l]=size(A);l=l-1;
  
  % Initialisation of alpha and mu
  mu(1)=b(1)/B(1,l+1);alpha(1,l)=-1/B(1,l+1);                      \flop{2}
  
  % Initialisation of the matrix T'*Y and the vector T'*x  
  ty(l,l)=alpha(1,l);tx(l,1)=mu(1);
   
  % The main loop in which we use always the previous solution
  for k=2:n
    % Because the products A(k,1:l)*ty and ty(2:l,:)*A(k,1:l)' appear twice
    bty=A(k,1:l)*ty;                                               \flop{2l^2-l}
    tyb=ty(2:l,:)*A(k,1:l)';                                       \flop{(l-1)(2l-1)}
    
    % Calculate alpha and mu
    denominator=(bty*A(k,1:l)'+A(k,l+1));                          \flop{3l-1}
    alpha(k,:)=[-bty(:,2:l),-1]/denominator;                       \flop{l}
    mu(k)=(b(k)-A(k,1:l)*tx)/denominator;                          \flop{2l+1}
    
    % Updating ty and tx
    tx=[tx(2:l)+mu(k)*tyb;mu(k)];                                  \flop{2(l-1)}
    ty(1:l-1,1:l)=[ty(2:l,2:l)+tyb*alpha(k,1:l-1),tyb*alpha(k,l)]; \flop{2(l-1)^2+l-1}
    ty(l,:)=alpha(k,:);
    
  end
  
  %--------PART 2: CALCULATE THE SOLUTION -----------------------
  % Initialisation of x and M
  M=zeros(l,1);
  x(n)=mu(n);
  
  % Constructing of x
  for i=n-1:-1:1
    M=[A(i+1,1)'*x(i+1);A(i+1,2:l)'*x(i+1)+M(1:l-1)];              \flop{2(l-1)+1}
    x(i)=mu(i)+alpha(i,:)*M;                                       \flop{2l}  
  end
end
The total number of operations for the first part of the algorithm is $ 6nl^2+nl-6l^2-l+2$, the number of operations for calculating the solution vector $ x$ is $ 4nl-n-4l+1$. This means that the overall complexity of the algorithm is $ O(l^2n)$, more precisely $ 6nl^2+5nl-n-6l^2-5l+3$ flops are needed.



Raf Vandebril 2005-04-26