当参数 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
posted on 2016-12-17 16:42  未雨愁眸  阅读(1694)  评论(0编辑  收藏  举报