function L=chol6_6(A);
%% function L=chol6_6(A);
%%
%%  Choleski's algorithm-- LL^t factorization for symmetric positive 
%%  definite matrices
%%
%%  INPUT:
%%    A - a (suspected) positive definite symmetric matrix
%%
%%  OUTPUT:
%%    L - a lower triangular matrix so that L*L'=A  (L'=L^t, L transposed)
%%    Message that no decomposition exists if A is NOT positive definite

%%Determine the size of the system
n=length(A(:,1));
L=eye(n);
flag=0;

if flag==0;
  if A(1,1)<=0  
     flag=1;
  else
     L(1,1)=sqrt(A(1,1));
     L(2:n,1)=A(2:n,1)/L(1,1);
     for i=2:n-1
        if A(i,i)-sum((L(i,1:i-1).^2)')<=0
            flag=1;i=n;
        else
            L(i,i)=sqrt(A(i,i)-sum((L(i,1:i-1).^2)'));
            for j=i+1:n
                L(j,i)=(A(j,i)-sum((L(j,1:i-1).*L(i,1:i-1))'))/L(i,i);
            end;    
        end;
      end;
      if A(n,n)-sum((L(n,1:n-1).^2)')<=0
          flag=1;
      elseif flag==0
           L(n,n)=sqrt(A(n,n)-sum((L(n,1:n-1).^2)'));
      end;
   end;
end;
if flag==1;
   L='no decomposition exists';
end;
