function L = cholesky(A)
n = size(A)*[1,0]';
L = eye(n);
L(1,1) = sqrt(A(1,1));
for k = 2 : n
    L(k, 1:k-1) = L(k-1,k-1)\A(1:k-1,k);
    L(k,k) = sqrt(A(k,k) - L(k, 1:k-1) * L(k, 1:k-1)');
end
end
