MVNRND in PC vs. MAC

13 views (last 30 days)
Dhari
Dhari on 2 Feb 2017
Commented: Walter Roberson on 2 Feb 2017
Hello,
I'm trying to generate a MVN random draw using mvnrnd(mu,sigma), and I get a valid result when done on mac, but on pc, I get the "Error using mvnrnd (line 112) SIGMA must be a symmetric positive semi-definite matrix."
Both computers are using the Matlab 2016a version, and both use the same parameters, which are:
mu = [
0.0026
-0.0035
0.0018
0.0022
-0.0060
-0.0046
-0.0002]
and
sigma = [
0.0044 0.0000 -0.0000 -0.0002 -0.0010 0.0005 -0.0020
0.0000 0.0001 0.0000 -0.0000 -0.0001 0.0000 0.0000
-0.0000 0.0000 0.0001 0.0000 -0.0000 -0.0001 -0.0000
-0.0002 -0.0000 0.0000 0.0002 0.0001 -0.0001 -0.0000
-0.0010 -0.0001 -0.0000 0.0001 0.0552 0.0047 0.0009
0.0005 0.0000 -0.0001 -0.0001 0.0047 0.0542 -0.0003
-0.0020 0.0000 -0.0000 -0.0000 0.0009 -0.0003 0.0020]
Here are the positive eigenvalues calculated on the pc:
>> eig(sigma)
ans =
0.0595
0.0500
0.0055
0.0009
0.0001
0.0001
0.0001
My feeling is that there is a discrepancy between the two computers related to the numerical precision setting, but I'm not sure how to verify that or change it. Any help would be appreciated. Thank you.

Answers (2)

Walter Roberson
Walter Roberson on 2 Feb 2017
A few weeks ago I tracked a related issue, only in reverse, where a positive-definite matrix computation now failed where it had worked in earlier releases; see http://www.mathworks.com/matlabcentral/answers/319225-hac-results-vary-bewteen-matlab-r2015b-and-matlab-r2016b
Determination of positive definiteness is done by using the two-output form of chol() and seeing if the second output is 0, in which case it is positive definite.
I found that the output of eig and qr and chol differs on Mac between R2015b and R2016a. Mathworks indicated that their had been an update to the Intel MKL between those releases. It is not out of the question that the Windows version did not get the changed version. (I am booting up to test that.)
One thing I wonder is if it is possible that the PC is AMD instead of Intel? If it is then I think it would get an AMD library rather than MKL.
  1 Comment
Walter Roberson
Walter Roberson on 2 Feb 2017
It worked when I tried it on R2016a on Windows 10 using an intel CPU.

Sign in to comment.


Roger Stafford
Roger Stafford on 2 Feb 2017
It is likely that very small differences in the computations that produced your ‘sigma’ matrix are the cause of the differences between the two computers. If you are convinced that the matrix that is failing the symmetry test is very close to being symmetric and only fails due to tiny rounding differences, you can do the following to ensure symmetry:
sigma = (sigma+sigma.)/2;
That should allow you to pass the symmetry test.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!