matlab 工具函数 —— logdet,A

当参数 是正定矩阵(positive definite)时,logdet 利用相关矩阵分解的性质,将比 log(det(A)) 获得更快的效率:

function y = logdet(A)

try
    U = chol(A);
    y = 2*sum(log(diag(U))) ;
catch 
    y = 0;
    warning('logdet:postdef', 'Matrix is not positive definite');
end

end