In Bayesian data analysis, the log determinant of symmetric positive definite matrices often pops up as a normalizing constant in MAP estimates with multivariate Gaussians (ie, chapter 27 of Mackay). Oftentimes, the determinant of A will evaluate as infinite in Matlab although the log det is finite, so one can’t use log(det(A)). However, we know that:

- (Cholesky decomposition)
- (determinant of a lower triangular matrix)
- (log rule)

Thus to calculate the log determinant of a symmetric positive definite matrix:

L = chol(A);
logdetA = 2*sum(log(diag(L)));

### Like this:

Like Loading...

*Related*

Thank you for this! Was having problems with log(det(K)) for optimizing GP hyperparameters.

Thanks for sharing! Does it work for positive semi-definite matrices too?

no