1

I'm trying to construct a multivariate likelihood function in c++ code with the aim of comparing multiple temperature simulations for consistency with observations but taking into account autocorrelation between the time steps. I am inexperienced in c++ and so have been struggling to understand how to write the equation in c++ form. I have the covariance matrix, the simulations I wish to judge and the observations to compare to. The equation is as follows:

f(x,μ,Σ) = (1/√(∣Σ∣(2π)^d))*exp(−1/2(x-μ)Σ^(-1)(x-μ)')

So I need to find the determinant and the inverse of the covariance matrix. Does anyone know how to do that in c++ if x,μ and Σ are all specified?

  • 2
    I guess you can implement some algorithm for calculating the determinant of a matrix and its inversion. Or you could use some linear algebra libraries like Eigen. – Quimby Aug 16 '22 at 20:05
  • I'm afraid I'm still very new with c++. Could you point me in the direction of any good example code? – climatecode44 Aug 16 '22 at 20:08
  • 1
    I am afraid not, neither algorithm is trivial to implement in any language. As I said, I would recommend a dedicated library. – Quimby Aug 16 '22 at 20:30
  • Welcome to Stack Overflow. You'll find questions tend to be better received when they are focused by a credible and visible attempt at researching or solving the problem. – user4581301 Aug 16 '22 at 20:30