## Copyright (C) 2008   Sentil @ BeeJay   <coolbbeejay@gmail.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see .
function [K,P]=cholinc(A,droptol)
% -Loadable Function cholinc(A,droptol)
% Purpose: Incomplete Cholesky Factorization of a Matrix
% Input:
% A- Input Matrix
% droptol- Threshold , if '0' the storage pattern of 'A'  is 
%applied.Otherwise, the values below 'droptol' threshold are made zero
% Output:
% K- Incomplete Cholesky Factorization of 'A'
% P- '0' if matrix is Positive Definite, positive integer otherwise.
% Error:
% If you get 'matrix not positive definite', either matrix is asymmetric
% or not positive definite or BOTH.
% Author: coolbbeejay@gmail.com Date: 16th Oct 2008
% Published under GNU License for GNU Octave
[R,P]=chol(A);
[m n]=size(A);
if(droptol==0)
  for i=1:m
      for j=1:n
         if(A(i,j)==0.0)
          R(i,j)=0.0;
         end
       end
  end
else
   for i=1:m
      for j=1:n
         if(R(i,j)<droptol)
          R(i,j)=0.0;
         end
       end
  end
end
K=R;
 
