function [invmat] = cholinv(mat)

% R = chol(mat);
% Rtrans = R';
% 
% n = length(mat);

% ident = eye(n,n);
% 
% for i=1:n
%     
%      invmat(:,i) = R\(Rtrans\ident(:,i));
%   
% end

mat = chol(mat);

invmat = mat\eye(size(mat));

invmat = invmat * invmat';

