%  YULEWALKERSOLVER  Solves a system of equations for a 
%                  positive definite semiseparable plus diagonal
%    
%    X=LEVINSONSOLVER(u,v,d) is the solution of the system (S+D)X=-v,
%    the matrix S+D is a semiseparable plus diagonal matrix represented
%    with two vectors u,v, and the vector d contains the diagonal
%    elements of the matrix D.
%    S+D=tril(u*v')+triu(v*u',1)+diag(d);
%
%    The matrix S+D should be positive definite and symmetric.
%    The complexity of the solver is 15n-4
%
%
%    Software of the MaSe - Group
%    mase-at-cs.kuleuven.ac.be
%    Revision Date: 24/02/2005
%


function y=YuleWalkerSolver(u,v,d)
    
% initialization of the size
n=length(d);


% initialization, in fact we solve the system for i=1
a(1)=-v(1)/(d(1)+u(1)*v(1));
f(1)=1;

% we calculate the innerproduct for the next loop
ip=a(1)*v(1);


% The main loop
for i=2:n
  
  % Store the new calculated alpha
  a(i)=(-v(i)-u(i)*ip)/(u(i)*v(i)+d(i)+u(i)^2*ip);
 
  % Store the new factor f
  f(i)=1+u(i)*a(i);
  
  
  % calculation of the innerproduct for the next loop
  ip=f(i)*ip+v(i)*a(i);  
end


% we have now the vector f and a
% we construct now the solution with these vectors.

y(n)=a(n);
factor=f(n);

for i=n-1:-1:1  
  y(i)=factor*a(i);
  factor=factor*f(i);
end

y=y';

