I've seen this question before. How do you compute the nearest Symmetric, Positive Definite matrix (often abbreviated SPD) to a given matrix? I was unsatisfied with what I found on the MATLAB Central file exchange, so I just posted nearestSPD on the FEX.
Starting from a matrix that is complete crap in terms of being SPD...
U = randn(100);
tic,Uj = nearestSPD(U);toc
Elapsed time is 0.006049 seconds.
The ultimate test of course, is to use chol. If chol returns a second argument that is zero, then MATLAB (and mvnrnd) will be happy!
[R,p] = chol(Uj);
p
p =
0
mvnrnd(zeros(1,100),Uj,1)
ans =
Columns 1 through 13
-2.1788 -1.1002 2.1801 -3.3030 -2.5108 0.1486 -0.7695 -1.6912 3.7952 -1.0618 0.7432 1.8749 1.1410
Columns 14 through 26
-0.0626 -1.2843 1.4384 -3.9369 -0.1819 1.9848 2.7395 2.0121 -0.2007 -0.3842 0.0343 0.4587 0.4310
Columns 27 through 39
-1.2035 -0.3946 -1.5155 -1.8792 -2.4681 0.7230 -1.2775 -0.8252 1.3161 0.4606 -2.0888 -4.0684 -0.5214
Columns 40 through 52
1.5011 -0.5847 -1.7154 0.8114 1.3967 1.2961 -1.4040 1.7476 -0.6991 -0.8323 0.5736 1.8499 -0.0301
Columns 53 through 65
-2.9938 0.6624 -0.0497 -0.5262 1.8294 1.8198 1.6230 -1.1492 0.8652 0.7090 0.1075 1.4513 1.6283
Columns 66 through 78
0.9870 -1.5733 -0.3842 -0.8873 -0.3926 1.1245 1.7367 1.3051 -2.3758 -0.7082 -4.0189 -2.5654 -0.0725
Columns 79 through 91
-2.0292 2.0114 0.0484 -1.7458 0.3135 -0.1224 3.0652 -0.4663 -2.0318 1.4760 0.5025 -0.8270 1.5677
Columns 92 through 100
-0.4954 -1.1622 -1.5471 1.1630 -1.6892 -1.1148 -0.8012 1.0580 -2.1881