# Mathematica Complains about Non Symmetric Covariance matrix, when it's not the case

I was doing some fitting with Mathematica7 using NonlinearModelFit. It's quite long the program to do the fit and that's why I am not displaying here ...

It goes ok, and I can get the fit parameters as well as the covariance matrix

In[81]:= {Subscript[a, 0], Subscript[a, 1]}/.fitCCBA34["BestFitParameters"]

In[78]:= fitCCBA34["CovarianceMatrix"]


When testing it is Symmetric, it goes ok, as should be by construction of the matrix:

In[80]:= SymmetricMatrixQ[b]
Out[80]= True


However, it turns out, that, when trying to get some Multinormal distribution of the parameters, it complains about the matrix which is non-symmetric ...

In[84]:= MultinormalDistribution[{Subscript[a, 0], Subscript[a,
1]} /. fitCCBA34[
"BestFitParameters"], {{fitCCBA34["CovarianceMatrix"][[1, 1]],
fitCCBA34["CovarianceMatrix"][[1, 2]]}, {fitCCBA34[
"CovarianceMatrix"][[2, 1]],
fitCCBA34["CovarianceMatrix"][[2, 2]]}}]

During evaluation of In[84]:= MultinormalDistribution::cmsym: The covariance matrix must be symmetric. >>

Out[84]= MultinormalDistribution[{0.275723,
0.246948}, {{0.00001521, -0.0000535383}, {-0.0000535383, 11.6061}}]


Of course, if now you do copy paste, it works perfectly, so I guess it's some numerical issue, any clue about how to fix this? I need to encode this inside a function rather than copy paste each time ...

It's hard to know without some data. But, wouldn't fitCCBA34["CovarianceMatrix" already return the matrix? I mean, why all the indexing? – Rojo Oct 29 '12 at 18:41
@J.M. Thanks for your suggestion, I freaked out doing some similar things not working, but finaly just taking (fitCCBA34["CovarianceMatrix"] + Transpose[fitCCBA34["CovarianceMatrix"]])/2 solved the problem without spoiling precission Thanks a lot! – pablo Oct 30 '12 at 14:25