0

I'm trying to calculate the determinant of a 171x171 covariance matrix in matlab but the determinant is coming out as zero. I know the matrix is not singular because I am able to calculate the inverse of the matrix but because the numbers in the covariance matrix are quite small (between e-02 and e-05), I think matlab rounds to zero at some point because the numbers become so small.

I tried installing the symbolic toolbox and making the covariance matrix symbolic to calculate the determinant but my computer couldn't really handle it and kept crashing. Does anyone have an idea of a workaround/ know of a way of dealing with a determinant that is close to zero, but not actually zero?

  • Why are you calculating the determinant of a 171x171 matrix? This is a bad idea from the start because of reasons you have already discovered. A symbolic 171x171 determinant is an even worse idea because of massive storage requirements and feasibility of working with it even if you could generate the expression. What is your real problem and what are you trying to do downstream in your code with this information? Maybe a function like rank( ) would suit you better. Please give us more details of what you are doing so we know how to advise. – James Tursa Aug 16 '22 at 18:35
  • Well I need to construct a likelihood filter using a multivariate normal distribution in c++. Essentially the matlab function mvnpdf but in c++. The equation for this requires you find the determinant of the covariance matrix you have and due to my inexperience with c++ I thought it might be easier to calculate the covariance matrix and then the determinant and inverse in matlab and then manually copy them into the model code? – climatecode44 Aug 16 '22 at 18:41
  • Can you post the equation you are using that has the determinant? I suspect it may be numerically unreliable for the size matrix you are using. Maybe there is a different approach that can give you the results you need. – James Tursa Aug 16 '22 at 18:46
  • the equation is:f(x,μ,Σ)=(1/(√∣Σ∣(2π)^d))*exp(−1/2(x-μ) Σ-1(x-μ)') – climatecode44 Aug 16 '22 at 18:49
  • I'm using the explanation from the matlab function: https://uk.mathworks.com/help/stats/mvnpdf.html – climatecode44 Aug 16 '22 at 18:53
  • I still have doubts about the numerical stability, but in the interests of getting an answer that you can *maybe* work with, what happens if you move the (2π)^d to inside the determinant? I.e., calculate sqrt(det(2πΣ)) – James Tursa Aug 16 '22 at 21:38

0 Answers0