function y = makePD(A)
% make matrix positive definite
temp = A;

[~,fl] = chol(temp,'lower');
while ~fl==0
%      disp('matrix not PD, making adjustment') ;
   [UP, SP, ~] = svd(temp);
   pchol = (UP*sqrt(SP))';
   temp = pchol * pchol';
   [~,fl] = chol(temp,'lower');
end
y = temp;

end