0

我正在尝试使用 对多元高斯进行采样mvnrnd,但是当我运行时,样本是NaN. 例如 (mu是一个 1×50 的向量,Sigma是一个 50×50 的矩阵,并且M等于 50):

Samp = mvnrnd(mu,Sigma,M)

当我运行它并检查Samp工作区中命令和变量的值时,它给了我NaN. 为什么?mvnrnd不适用于更大的尺寸?

* 编辑* 以下是 mu 的值:

mu =

  Columns 1 through 15

   14.3632    8.7442   -3.2029  -16.0259   -8.8725  -10.7675    9.2580   13.2556   -1.4326  -11.5970    1.9023   14.1793    9.9024  -12.7794   -0.2913

  Columns 16 through 30

   -4.3093  -15.2170   23.2225    4.5019   16.8539    0.6878    3.4329    1.9528    5.5965    0.1680    3.3895   15.1409   12.5796   11.8425    5.4299

  Columns 31 through 45

  -20.4517   12.3072   -7.5742  -14.9738   17.6118   -1.0414    3.2530   -0.1278    1.0009    3.2609   10.5319  -19.2158   -1.5661   -8.3426  -12.0159

  Columns 46 through 50

    6.3250   12.1056   11.5938   24.9523  -13.1602

西格玛的值:

 1.0e+003 *

  Columns 1 through 15

    0.6526   -0.2398    0.2117    0.3901   -0.0241    0.1888   -0.2221    0.1173   -0.2380   -0.0327    0.0408    0.1229    0.0616    0.1475   -0.2264
   -0.2398    0.7744    0.0419   -0.4366   -0.1791   -0.0826    0.1756   -0.1534    0.3632   -0.1595    0.3086   -0.3319   -0.3392   -0.0717    0.1952
    0.2117    0.0419    0.7214   -0.2074    0.0711    0.2518   -0.1782   -0.2859   -0.1668   -0.0502   -0.0726    0.3005   -0.0525    0.1660   -0.0541
    0.3901   -0.4366   -0.2074    1.0006   -0.1486    0.0126   -0.0639    0.0847   -0.4875    0.2744   -0.3495    0.0131    0.5273    0.2531   -0.6108
   -0.0241   -0.1791    0.0711   -0.1486    0.5274   -0.1581   -0.1114   -0.1617   -0.1438   -0.0228    0.4721   -0.0968    0.0665    0.0576    0.1959
    0.1888   -0.0826    0.2518    0.0126   -0.1581    1.0361    0.1172    0.2760   -0.5648    0.5519   -0.3184    0.5437   -0.0191   -0.1152    0.0294
   -0.2221    0.1756   -0.1782   -0.0639   -0.1114    0.1172    0.4101    0.0368   -0.0796    0.0443   -0.1558    0.0977    0.1141   -0.0605    0.0048
    0.1173   -0.1534   -0.2859    0.0847   -0.1617    0.2760    0.0368    0.5609   -0.1075    0.2252   -0.1115    0.1774   -0.0141   -0.4447    0.0143
   -0.2380    0.3632   -0.1668   -0.4875   -0.1438   -0.5648   -0.0796   -0.1075    0.9745   -0.5401    0.1096   -0.4135   -0.4675   -0.0067    0.2081
   -0.0327   -0.1595   -0.0502    0.2744   -0.0228    0.5519    0.0443    0.2252   -0.5401    0.8966   -0.0644    0.0352    0.3309   -0.0716   -0.0799
    0.0408    0.3086   -0.0726   -0.3495    0.4721   -0.3184   -0.1558   -0.1115    0.1096   -0.0644    1.2591   -0.6571   -0.3052    0.0561    0.5633
    0.1229   -0.3319    0.3005    0.0131   -0.0968    0.5437    0.0977    0.1774   -0.4135    0.0352   -0.6571    0.7890    0.1215   -0.1922   -0.1545
    0.0616   -0.3392   -0.0525    0.5273    0.0665   -0.0191    0.1141   -0.0141   -0.4675    0.3309   -0.3052    0.1215    0.6406    0.0985   -0.3731
    0.1475   -0.0717    0.1660    0.2531    0.0576   -0.1152   -0.0605   -0.4447   -0.0067   -0.0716    0.0561   -0.1922    0.0985    0.6436   -0.0893
   -0.2264    0.1952   -0.0541   -0.6108    0.1959    0.0294    0.0048    0.0143    0.2081   -0.0799    0.5633   -0.1545   -0.3731   -0.0893    0.8214
   -0.0686    0.2110   -0.3078    0.0558   -0.0122    0.1147    0.1430    0.2891   -0.3322    0.3182    0.4246   -0.1755    0.1220   -0.2959    0.4601
    0.2857   -0.2873   -0.0581    0.2950    0.1501    0.2427    0.0816    0.0113   -0.3478    0.0397    0.0282    0.1461    0.1842    0.2372    0.0343
   -0.0803   -0.2141   -0.1914    0.0538   -0.1175   -0.1082   -0.0395    0.1628    0.1080    0.0010   -0.1534    0.0374   -0.0209   -0.0783    0.0447
   -0.3939    0.2945   -0.0432   -0.0477   -0.2129   -0.3433    0.1706   -0.2475    0.3644   -0.0215   -0.3702   -0.1953    0.1405    0.0665   -0.3338
   -0.0722   -0.0264    0.0008    0.3816   -0.3788    0.0074   -0.1099   -0.1504    0.0746    0.0737   -0.6089    0.0166    0.0902    0.2234   -0.2678
    0.1529   -0.5922   -0.2520    0.6748    0.1484    0.0973   -0.0401    0.0497   -0.3356    0.3686   -0.3625    0.0574    0.4848    0.2182   -0.4968
    0.0500    0.1051   -0.3110    0.1405    0.0029   -0.4277    0.0084    0.0768   -0.0301   -0.2538    0.5848   -0.3300   -0.1102   -0.0272    0.2356
   -0.1218   -0.1016    0.2996   -0.2520    0.2787   -0.2611    0.0569   -0.4067    0.1377   -0.4350   -0.1751    0.2062    0.0636    0.2057   -0.1183
    0.2696    0.1371   -0.1442    0.5029   -0.2059    0.3640    0.1549    0.3234   -0.5336    0.3734   -0.0536    0.0636    0.2701   -0.2389   -0.3367
   -0.1135    0.2516    0.0626   -0.4029    0.2331   -0.4780   -0.0001   -0.2735    0.4003   -0.3002    0.6077   -0.4151   -0.2260    0.1742    0.1648
   -0.0292   -0.4748   -0.3736    0.0169    0.1652    0.1030   -0.0086    0.4718   -0.1408    0.3198    0.1058    0.0903    0.0904   -0.3160    0.1783
    0.2547   -0.3759    0.0127    0.2648    0.0165    0.0835   -0.2337    0.0995   -0.0706    0.0958   -0.1449    0.0840    0.0818    0.0939   -0.0702
   -0.1816    0.0102    0.0898   -0.3345    0.2516   -0.2833   -0.1383   -0.2458    0.3455   -0.2373    0.0986   -0.1230   -0.0862    0.0791    0.2563
   -0.4171    0.4862    0.1516   -0.6891    0.0777    0.1910    0.1572    0.0256    0.0820   -0.2754   -0.0733    0.3196   -0.3359   -0.5783    0.2642
    0.0979   -0.1388    0.0024    0.0188   -0.1463   -0.3960    0.0223    0.0048    0.3365   -0.5037   -0.3112    0.1393   -0.0201    0.0032   -0.2922
    0.0948   -0.2636    0.3152    0.0659    0.2656   -0.0597   -0.2578   -0.1789   -0.2244   -0.0539    0.0389    0.1523    0.0280    0.0666   -0.2162
   -0.1445    0.2316    0.0613    0.0501   -0.0395   -0.2582    0.0113   -0.3707    0.2411   -0.0166   -0.0814   -0.3044    0.1419    0.3170   -0.0964
    0.1256   -0.5610   -0.1839    0.3283    0.0318    0.2282   -0.1754    0.1760   -0.1883    0.3672   -0.0763    0.0445    0.0492    0.1796   -0.0089
    0.1639    0.1968   -0.1370    0.0399   -0.1855   -0.3227   -0.1928    0.1799    0.3764   -0.2362    0.0825   -0.2515   -0.1152   -0.2144    0.0347
   -0.2864    0.3746   -0.2039   -0.2420   -0.3702   -0.1993    0.1265    0.1169    0.5200   -0.2245   -0.2712   -0.0906   -0.2380   -0.2680   -0.0291
    0.1612   -0.1498   -0.1399    0.0687    0.0545   -0.3288   -0.4044    0.1803    0.2788   -0.1633    0.2013   -0.2194   -0.1733   -0.1788    0.0570
    0.0210    0.0132    0.0418   -0.0458    0.3749   -0.8174   -0.3073   -0.2024    0.1391   -0.4363    0.6594   -0.3834   -0.0417   -0.0524    0.0248
   -0.1725   -0.4189   -0.3139    0.1701    0.2373   -0.0647   -0.0170    0.1205   -0.1555    0.4068    0.0057   -0.0915    0.3662   -0.0172    0.1566
   -0.0874   -0.2369    0.2437    0.1705   -0.3743   -0.0117    0.0462   -0.1165   -0.0344   -0.1393   -0.8038    0.4598    0.1061    0.1232   -0.4006
    0.3103   -0.3241   -0.1160    0.0813    0.2223   -0.0290   -0.1899    0.3164   -0.1250   -0.2822    0.1018    0.2295   -0.0279   -0.3269    0.1315
    0.0275   -0.0756   -0.0828   -0.0727    0.0860    0.1942    0.1057    0.1967   -0.0409    0.1347    0.0286    0.0873   -0.0564   -0.1634   -0.2309
   -0.1293    0.0226   -0.1196   -0.0434    0.0879   -0.0832   -0.0431   -0.0599    0.1180    0.1482    0.1804   -0.2526   -0.0167    0.0872    0.1069
    0.0780   -0.4398   -0.0265    0.4988    0.1396    0.1752    0.0595    0.0512   -0.7669    0.4653    0.0083    0.1777    0.4917    0.1050   -0.0940
   -0.0254   -0.0436    0.1248    0.0585   -0.2328    0.1872    0.1750   -0.1469    0.0017   -0.1329   -0.5634    0.3195    0.0734    0.2208   -0.0757
    0.1281   -0.0224    0.2863    0.0723   -0.4067   -0.0308    0.0180    0.0557    0.1420   -0.1877   -0.7327    0.3820    0.1499   -0.1069   -0.3878
   -0.1545   -0.2713   -0.3821    0.1368    0.0131   -0.0251    0.0240   -0.0059    0.0621   -0.1232   -0.1039   -0.0018   -0.1081    0.1816    0.2430
    0.0411   -0.0787    0.3134   -0.0046   -0.1013    0.3395   -0.1217    0.0351   -0.1643    0.2941   -0.3255    0.2577    0.0585   -0.0722   -0.1540
   -0.2357    0.3986   -0.1687   -0.2010   -0.3998    0.2651    0.2607    0.2268    0.1089    0.1718   -0.1816    0.0235   -0.1149   -0.2578    0.2615
    0.2349   -0.1041    0.1657    0.1751   -0.1983    0.3247    0.2915    0.0951   -0.3150    0.0387   -0.3997    0.4270    0.2562    0.0518   -0.2561
    0.0271   -0.3102   -0.0949    0.2027    0.0852    0.4680    0.0069    0.2586   -0.5133    0.6809    0.0700    0.0981    0.2209   -0.0654    0.0935

  Columns 16 through 30

   -0.0686    0.2857   -0.0803   -0.3939   -0.0722    0.1529    0.0500   -0.1218    0.2696   -0.1135   -0.0292    0.2547   -0.1816   -0.4171    0.0979
    0.2110   -0.2873   -0.2141    0.2945   -0.0264   -0.5922    0.1051   -0.1016    0.1371    0.2516   -0.4748   -0.3759    0.0102    0.4862   -0.1388
   -0.3078   -0.0581   -0.1914   -0.0432    0.0008   -0.2520   -0.3110    0.2996   -0.1442    0.0626   -0.3736    0.0127    0.0898    0.1516    0.0024
    0.0558    0.2950    0.0538   -0.0477    0.3816    0.6748    0.1405   -0.2520    0.5029   -0.4029    0.0169    0.2648   -0.3345   -0.6891    0.0188
   -0.0122    0.1501   -0.1175   -0.2129   -0.3788    0.1484    0.0029    0.2787   -0.2059    0.2331    0.1652    0.0165    0.2516    0.0777   -0.1463
    0.1147    0.2427   -0.1082   -0.3433    0.0074    0.0973   -0.4277   -0.2611    0.3640   -0.4780    0.1030    0.0835   -0.2833    0.1910   -0.3960
    0.1430    0.0816   -0.0395    0.1706   -0.1099   -0.0401    0.0084    0.0569    0.1549   -0.0001   -0.0086   -0.2337   -0.1383    0.1572    0.0223
    0.2891    0.0113    0.1628   -0.2475   -0.1504    0.0497    0.0768   -0.4067    0.3234   -0.2735    0.4718    0.0995   -0.2458    0.0256    0.0048
   -0.3322   -0.3478    0.1080    0.3644    0.0746   -0.3356   -0.0301    0.1377   -0.5336    0.4003   -0.1408   -0.0706    0.3455    0.0820    0.3365
    0.3182    0.0397    0.0010   -0.0215    0.0737    0.3686   -0.2538   -0.4350    0.3734   -0.3002    0.3198    0.0958   -0.2373   -0.2754   -0.5037
    0.4246    0.0282   -0.1534   -0.3702   -0.6089   -0.3625    0.5848   -0.1751   -0.0536    0.6077    0.1058   -0.1449    0.0986   -0.0733   -0.3112
   -0.1755    0.1461    0.0374   -0.1953    0.0166    0.0574   -0.3300    0.2062    0.0636   -0.4151    0.0903    0.0840   -0.1230    0.3196    0.1393
    0.1220    0.1842   -0.0209    0.1405    0.0902    0.4848   -0.1102    0.0636    0.2701   -0.2260    0.0904    0.0818   -0.0862   -0.3359   -0.0201
   -0.2959    0.2372   -0.0783    0.0665    0.2234    0.2182   -0.0272    0.2057   -0.2389    0.1742   -0.3160    0.0939    0.0791   -0.5783    0.0032
    0.4601    0.0343    0.0447   -0.3338   -0.2678   -0.4968    0.2356   -0.1183   -0.3367    0.1648    0.1783   -0.0702    0.2563    0.2642   -0.2922
    1.1641    0.1034   -0.0194   -0.3240   -0.0946   -0.3245    0.5362   -0.6197    0.5462   -0.2986    0.1476   -0.1007   -0.1329    0.2094   -0.5151
    0.1034    0.5320   -0.0902   -0.3749   -0.1158    0.3433   -0.0024    0.0443    0.1294   -0.1713    0.0906    0.1497   -0.0375   -0.2545   -0.1116
   -0.0194   -0.0902    0.2886   -0.0147    0.1016    0.0126    0.1733   -0.1194   -0.1837   -0.0298    0.2956    0.1006   -0.0653   -0.2525    0.1807
   -0.3240   -0.3749   -0.0147    0.7760    0.3068    0.0357   -0.2914    0.2226   -0.1225    0.1584   -0.3114   -0.2043    0.0994    0.0522    0.1904
   -0.0946   -0.1158    0.1016    0.3068    0.8276    0.1746   -0.1860   -0.1459    0.0079   -0.4393   -0.3581    0.1573    0.0312   -0.1168   -0.0679
   -0.3245    0.3433    0.0126    0.0357    0.1746    1.0148   -0.4049    0.0829    0.1196   -0.2878    0.2832    0.3084   -0.0141   -0.5111   -0.0565
    0.5362   -0.0024    0.1733   -0.2914   -0.1860   -0.4049    1.0361   -0.3308    0.1590    0.2469    0.1052   -0.1317   -0.2840   -0.2479    0.1052
   -0.6197    0.0443   -0.1194    0.2226   -0.1459    0.0829   -0.3308    0.7831   -0.4849    0.2867   -0.2149   -0.0856    0.3272    0.2165    0.3348
    0.5462    0.1294   -0.1837   -0.1225    0.0079    0.1196    0.1590   -0.4849    0.9412   -0.4123   -0.0770   -0.0688   -0.4534    0.1214   -0.2674
   -0.2986   -0.1713   -0.0298    0.1584   -0.4393   -0.2878    0.2469    0.2867   -0.4123    0.7798   -0.0243   -0.2134    0.0980   -0.2170    0.2545
    0.1476    0.0906    0.2956   -0.3114   -0.3581    0.2832    0.1052   -0.2149   -0.0770   -0.0243    0.8433    0.1766   -0.1008   -0.3012    0.0214
   -0.1007    0.1497    0.1006   -0.2043    0.1573    0.3084   -0.1317   -0.0856   -0.0688   -0.2134    0.1766    0.3139    0.0542   -0.3437   -0.0022
   -0.1329   -0.0375   -0.0653    0.0994    0.0312   -0.0141   -0.2840    0.3272   -0.4534    0.0980   -0.1008    0.0542    0.5184    0.2491   -0.0526
    0.2094   -0.2545   -0.2525    0.0522   -0.1168   -0.5111   -0.2479    0.2165    0.1214   -0.2170   -0.3012   -0.3437    0.2491    1.5153   -0.2274
   -0.5151   -0.1116    0.1807    0.1904   -0.0679   -0.0565    0.1052    0.3348   -0.2674    0.2545    0.0214   -0.0022   -0.0526   -0.2274    0.7070
   -0.3968   -0.0698   -0.0207   -0.0893   -0.0483    0.1385   -0.0376    0.2814   -0.1577    0.1031   -0.0168    0.0721    0.0247    0.0337    0.0821
   -0.0802   -0.0655   -0.1549    0.4400    0.3391    0.0921   -0.2724    0.1484   -0.1043    0.0449   -0.4317   -0.0374    0.2717   -0.0728   -0.1057
   -0.1999    0.1888    0.2938   -0.2767    0.1120    0.4970   -0.0022   -0.2160   -0.2068   -0.1046    0.5284    0.3405   -0.1427   -0.7204   -0.0466
    0.3181   -0.1686    0.0125    0.0108    0.1503   -0.2403    0.1669   -0.2955    0.1893   -0.1297   -0.1263    0.0829    0.1146    0.1083    0.0600
   -0.0343   -0.3779    0.1065    0.3992    0.2066   -0.3149   -0.0089   -0.0916   -0.0222    0.0032   -0.1363   -0.1702    0.0059    0.3385    0.2162
    0.0618   -0.1513    0.1417   -0.1844    0.0846    0.0036    0.1798   -0.2219   -0.0729   -0.0581    0.1733    0.2369    0.1535   -0.0489    0.0491
    0.0544   -0.2557    0.0243   -0.0554   -0.2783   -0.2822    0.6476    0.1633   -0.1530    0.4791   -0.0351   -0.0877    0.1246    0.0150    0.2277
    0.2663    0.1528    0.1494   -0.0407    0.0096    0.4694   -0.1303   -0.0893   -0.1266   -0.1709    0.4969    0.2061    0.2003   -0.3123   -0.2366
   -0.5369   -0.2308    0.2989    0.3189    0.4289   -0.0620   -0.0133    0.2445   -0.2775   -0.0713   -0.1156    0.0129   -0.2250   -0.2450    0.5264
    0.2755    0.2552    0.0031   -0.5586   -0.2286    0.0695    0.1570   -0.0321    0.1618   -0.3076    0.2594    0.2107    0.1243    0.3395    0.0260
   -0.4115   -0.0068   -0.0229    0.0189   -0.4013    0.2605   -0.2028    0.1050    0.0577    0.2234    0.3123   -0.0643   -0.1998   -0.0266    0.1533
    0.0066   -0.0327    0.0130    0.0817    0.0258    0.1196   -0.0610   -0.0605   -0.1290    0.1020    0.0831    0.0257    0.1124   -0.1464   -0.1545
    0.3602    0.2356    0.1184   -0.2522   -0.0306    0.2737    0.3444   -0.1652    0.2510   -0.1763    0.3047    0.0772   -0.3166   -0.4650   -0.1691
   -0.1881    0.1552    0.0119    0.1321    0.3246    0.0352   -0.2550    0.2124   -0.1284   -0.2292   -0.2541    0.0247    0.0387    0.0045    0.1263
   -0.2722   -0.2290    0.0889    0.3339    0.2808   -0.1718   -0.2520    0.1500    0.0115   -0.1775   -0.2271    0.0357   -0.0584    0.0010    0.4739
    0.0275    0.2651    0.2166   -0.2113    0.2603    0.2496    0.1726   -0.0389   -0.2758   -0.1997    0.1897    0.1525    0.0904   -0.1338   -0.0667
   -0.1500   -0.1471   -0.0139    0.0765    0.1940    0.0436   -0.3935   -0.0344    0.0330   -0.2192   -0.0419    0.0964   -0.0170    0.0823   -0.1049
    0.5355   -0.1411    0.0452    0.1215    0.1902   -0.4046    0.0411   -0.4058    0.2525   -0.2668   -0.0716   -0.1605   -0.1132    0.3145   -0.2036
   -0.0885    0.2229   -0.0299   -0.0124   -0.1432    0.0235   -0.0815    0.1245    0.2248   -0.0721   -0.0147   -0.0504   -0.3070   -0.2132    0.2714
    0.3065    0.1538    0.0976   -0.2684   -0.0850    0.2965   -0.0311   -0.3603    0.1956   -0.2121    0.4772    0.1421   -0.2157   -0.3283   -0.3742

  Columns 31 through 45

    0.0948   -0.1445    0.1256    0.1639   -0.2864    0.1612    0.0210   -0.1725   -0.0874    0.3103    0.0275   -0.1293    0.0780   -0.0254    0.1281
   -0.2636    0.2316   -0.5610    0.1968    0.3746   -0.1498    0.0132   -0.4189   -0.2369   -0.3241   -0.0756    0.0226   -0.4398   -0.0436   -0.0224
    0.3152    0.0613   -0.1839   -0.1370   -0.2039   -0.1399    0.0418   -0.3139    0.2437   -0.1160   -0.0828   -0.1196   -0.0265    0.1248    0.2863
    0.0659    0.0501    0.3283    0.0399   -0.2420    0.0687   -0.0458    0.1701    0.1705    0.0813   -0.0727   -0.0434    0.4988    0.0585    0.0723
    0.2656   -0.0395    0.0318   -0.1855   -0.3702    0.0545    0.3749    0.2373   -0.3743    0.2223    0.0860    0.0879    0.1396   -0.2328   -0.4067
   -0.0597   -0.2582    0.2282   -0.3227   -0.1993   -0.3288   -0.8174   -0.0647   -0.0117   -0.0290    0.1942   -0.0832    0.1752    0.1872   -0.0308
   -0.2578    0.0113   -0.1754   -0.1928    0.1265   -0.4044   -0.3073   -0.0170    0.0462   -0.1899    0.1057   -0.0431    0.0595    0.1750    0.0180
   -0.1789   -0.3707    0.1760    0.1799    0.1169    0.1803   -0.2024    0.1205   -0.1165    0.3164    0.1967   -0.0599    0.0512   -0.1469    0.0557
   -0.2244    0.2411   -0.1883    0.3764    0.5200    0.2788    0.1391   -0.1555   -0.0344   -0.1250   -0.0409    0.1180   -0.7669    0.0017    0.1420
   -0.0539   -0.0166    0.3672   -0.2362   -0.2245   -0.1633   -0.4363    0.4068   -0.1393   -0.2822    0.1347    0.1482    0.4653   -0.1329   -0.1877
    0.0389   -0.0814   -0.0763    0.0825   -0.2712    0.2013    0.6594    0.0057   -0.8038    0.1018    0.0286    0.1804    0.0083   -0.5634   -0.7327
    0.1523   -0.3044    0.0445   -0.2515   -0.0906   -0.2194   -0.3834   -0.0915    0.4598    0.2295    0.0873   -0.2526    0.1777    0.3195    0.3820
    0.0280    0.1419    0.0492   -0.1152   -0.2380   -0.1733   -0.0417    0.3662    0.1061   -0.0279   -0.0564   -0.0167    0.4917    0.0734    0.1499
    0.0666    0.3170    0.1796   -0.2144   -0.2680   -0.1788   -0.0524   -0.0172    0.1232   -0.3269   -0.1634    0.0872    0.1050    0.2208   -0.1069
   -0.2162   -0.0964   -0.0089    0.0347   -0.0291    0.0570    0.0248    0.1566   -0.4006    0.1315   -0.2309    0.1069   -0.0940   -0.0757   -0.3878
   -0.3968   -0.0802   -0.1999    0.3181   -0.0343    0.0618    0.0544    0.2663   -0.5369    0.2755   -0.4115    0.0066    0.3602   -0.1881   -0.2722
   -0.0698   -0.0655    0.1888   -0.1686   -0.3779   -0.1513   -0.2557    0.1528   -0.2308    0.2552   -0.0068   -0.0327    0.2356    0.1552   -0.2290
   -0.0207   -0.1549    0.2938    0.0125    0.1065    0.1417    0.0243    0.1494    0.2989    0.0031   -0.0229    0.0130    0.1184    0.0119    0.0889
   -0.0893    0.4400   -0.2767    0.0108    0.3992   -0.1844   -0.0554   -0.0407    0.3189   -0.5586    0.0189    0.0817   -0.2522    0.1321    0.3339
   -0.0483    0.3391    0.1120    0.1503    0.2066    0.0846   -0.2783    0.0096    0.4289   -0.2286   -0.4013    0.0258   -0.0306    0.3246    0.2808
    0.1385    0.0921    0.4970   -0.2403   -0.3149    0.0036   -0.2822    0.4694   -0.0620    0.0695    0.2605    0.1196    0.2737    0.0352   -0.1718
   -0.0376   -0.2724   -0.0022    0.1669   -0.0089    0.1798    0.6476   -0.1303   -0.0133    0.1570   -0.2028   -0.0610    0.3444   -0.2550   -0.2520
    0.2814    0.1484   -0.2160   -0.2955   -0.0916   -0.2219    0.1633   -0.0893    0.2445   -0.0321    0.1050   -0.0605   -0.1652    0.2124    0.1500
   -0.1577   -0.1043   -0.2068    0.1893   -0.0222   -0.0729   -0.1530   -0.1266   -0.2775    0.1618    0.0577   -0.1290    0.2510   -0.1284    0.0115
    0.1031    0.0449   -0.1046   -0.1297    0.0032   -0.0581    0.4791   -0.1709   -0.0713   -0.3076    0.2234    0.1020   -0.1763   -0.2292   -0.1775
   -0.0168   -0.4317    0.5284   -0.1263   -0.1363    0.1733   -0.0351    0.4969   -0.1156    0.2594    0.3123    0.0831    0.3047   -0.2541   -0.2271
    0.0721   -0.0374    0.3405    0.0829   -0.1702    0.2369   -0.0877    0.2061    0.0129    0.2107   -0.0643    0.0257    0.0772    0.0247    0.0357
    0.0247    0.2717   -0.1427    0.1146    0.0059    0.1535    0.1246    0.2003   -0.2250    0.1243   -0.1998    0.1124   -0.3166    0.0387   -0.0584
    0.0337   -0.0728   -0.7204    0.1083    0.3385   -0.0489    0.0150   -0.3123   -0.2450    0.3395   -0.0266   -0.1464   -0.4650    0.0045    0.0010
    0.0821   -0.1057   -0.0466    0.0600    0.2162    0.0491    0.2277   -0.2366    0.5264    0.0260    0.1533   -0.1545   -0.1691    0.1263    0.4739
    0.5618   -0.1389    0.1311   -0.2366   -0.2612    0.1054    0.4214   -0.0968    0.2378    0.0742    0.1362   -0.0443    0.1859   -0.1439   -0.0511
   -0.1389    0.5639   -0.2361    0.1229    0.0935   -0.0847   -0.0760    0.0770   -0.0814   -0.3276   -0.2688    0.1306   -0.2093    0.1579    0.0904
    0.1311   -0.2361    0.8412   -0.3004   -0.2777    0.1211   -0.2301    0.3626    0.1841   -0.0530    0.1751    0.1391    0.3622   -0.0307   -0.2654
   -0.2366    0.1229   -0.3004    0.7172    0.3009    0.4748    0.2397   -0.0594   -0.2792    0.3463   -0.3037   -0.0301   -0.3640   -0.1323    0.2454
   -0.2612    0.0935   -0.2777    0.3009    0.5920    0.0779   -0.0899   -0.2107    0.1831   -0.1457   -0.0197   -0.0219   -0.4566    0.0721    0.3146
    0.1054   -0.0847    0.1211    0.4748    0.0779    0.6433    0.4315    0.0993   -0.2028    0.4349   -0.1294    0.0469   -0.1881   -0.2934   -0.0284
    0.4214   -0.0760   -0.2301    0.2397   -0.0899    0.4315    1.1878   -0.0961   -0.0734    0.2712   -0.1223   -0.0191    0.1098   -0.4717   -0.1285
   -0.0968    0.0770    0.3626   -0.0594   -0.2107    0.0993   -0.0961    0.7490   -0.2378    0.1050   -0.0866    0.1984    0.3329   -0.0800   -0.2338
    0.2378   -0.0814    0.1841   -0.2792    0.1831   -0.2028   -0.0734   -0.2378    1.1624   -0.3832   -0.0479   -0.1837    0.2305    0.3955    0.6359
    0.0742   -0.3276   -0.0530    0.3463   -0.1457    0.4349    0.2712    0.1050   -0.3832    0.9227   -0.0834   -0.1482   -0.0324   -0.1425   -0.0706
    0.1362   -0.2688    0.1751   -0.3037   -0.0197   -0.1294   -0.1223   -0.0866   -0.0479   -0.0834    0.6686    0.0149   -0.0792   -0.1867   -0.1316
   -0.0443    0.1306    0.1391   -0.0301   -0.0219    0.0469   -0.0191    0.1984   -0.1837   -0.1482    0.0149    0.1645   -0.0320   -0.0962   -0.2218
    0.1859   -0.2093    0.3622   -0.3640   -0.4566   -0.1881    0.1098    0.3329    0.2305   -0.0324   -0.0792   -0.0320    0.9048   -0.0456   -0.1577
   -0.1439    0.1579   -0.0307   -0.1323    0.0721   -0.2934   -0.4717   -0.0800    0.3955   -0.1425   -0.1867   -0.0962   -0.0456    0.4988    0.3098
   -0.0511    0.0904   -0.2654    0.2454    0.3146   -0.0284   -0.1285   -0.2338    0.6359   -0.0706   -0.1316   -0.2218   -0.1577    0.3098    0.8820
   -0.0817   -0.0692    0.4338   -0.1519   -0.0458    0.0668   -0.2008    0.2467    0.0650    0.1479   -0.1583    0.0835    0.0988    0.2058   -0.3573
    0.1416    0.0187    0.0680   -0.0562   -0.0146   -0.0171   -0.2208   -0.0073    0.2197   -0.1295    0.0158   -0.0208    0.0281    0.0550    0.2491
   -0.4990    0.0574   -0.2256    0.2206    0.3842   -0.1397   -0.4567   -0.0353   -0.0290   -0.1550   -0.2281   -0.0193   -0.1279    0.1608    0.1671
   -0.1164   -0.1255   -0.0674   -0.2109   -0.0759   -0.4299   -0.3661   -0.1675    0.3490   -0.1026    0.1468   -0.2091    0.2150    0.2954    0.3980
    0.0063   -0.2136    0.4850   -0.2805   -0.3146   -0.0851   -0.2834    0.4075   -0.1096   -0.0682    0.1309    0.1055    0.5218   -0.1392   -0.2866

  Columns 46 through 50

   -0.1545    0.0411   -0.2357    0.2349    0.0271
   -0.2713   -0.0787    0.3986   -0.1041   -0.3102
   -0.3821    0.3134   -0.1687    0.1657   -0.0949
    0.1368   -0.0046   -0.2010    0.1751    0.2027
    0.0131   -0.1013   -0.3998   -0.1983    0.0852
   -0.0251    0.3395    0.2651    0.3247    0.4680
    0.0240   -0.1217    0.2607    0.2915    0.0069
   -0.0059    0.0351    0.2268    0.0951    0.2586
    0.0621   -0.1643    0.1089   -0.3150   -0.5133
   -0.1232    0.2941    0.1718    0.0387    0.6809
   -0.1039   -0.3255   -0.1816   -0.3997    0.0700
   -0.0018    0.2577    0.0235    0.4270    0.0981
   -0.1081    0.0585   -0.1149    0.2562    0.2209
    0.1816   -0.0722   -0.2578    0.0518   -0.0654
    0.2430   -0.1540    0.2615   -0.2561    0.0935
    0.0275   -0.1500    0.5355   -0.0885    0.3065
    0.2651   -0.1471   -0.1411    0.2229    0.1538
    0.2166   -0.0139    0.0452   -0.0299    0.0976
   -0.2113    0.0765    0.1215   -0.0124   -0.2684
    0.2603    0.1940    0.1902   -0.1432   -0.0850
    0.2496    0.0436   -0.4046    0.0235    0.2965
    0.1726   -0.3935    0.0411   -0.0815   -0.0311
   -0.0389   -0.0344   -0.4058    0.1245   -0.3603
   -0.2758    0.0330    0.2525    0.2248    0.1956
   -0.1997   -0.2192   -0.2668   -0.0721   -0.2121
    0.1897   -0.0419   -0.0716   -0.0147    0.4772
    0.1525    0.0964   -0.1605   -0.0504    0.1421
    0.0904   -0.0170   -0.1132   -0.3070   -0.2157
   -0.1338    0.0823    0.3145   -0.2132   -0.3283
   -0.0667   -0.1049   -0.2036    0.2714   -0.3742
   -0.0817    0.1416   -0.4990   -0.1164    0.0063
   -0.0692    0.0187    0.0574   -0.1255   -0.2136
    0.4338    0.0680   -0.2256   -0.0674    0.4850
   -0.1519   -0.0562    0.2206   -0.2109   -0.2805
   -0.0458   -0.0146    0.3842   -0.0759   -0.3146
    0.0668   -0.0171   -0.1397   -0.4299   -0.0851
   -0.2008   -0.2208   -0.4567   -0.3661   -0.2834
    0.2467   -0.0073   -0.0353   -0.1675    0.4075
    0.0650    0.2197   -0.0290    0.3490   -0.1096
    0.1479   -0.1295   -0.1550   -0.1026   -0.0682
   -0.1583    0.0158   -0.2281    0.1468    0.1309
    0.0835   -0.0208   -0.0193   -0.2091    0.1055
    0.0988    0.0281   -0.1279    0.2150    0.5218
    0.2058    0.0550    0.1608    0.2954   -0.1392
   -0.3573    0.2491    0.1671    0.3980   -0.2866
    0.7949   -0.2198   -0.0021   -0.2056    0.0743
   -0.2198    0.3682    0.0427    0.0429    0.1559
   -0.0021    0.0427    0.7153    0.0822    0.0522
   -0.2056    0.0429    0.0822    0.6820    0.0415
    0.0743    0.1559    0.0522    0.0415    0.6538

编辑

这就是我试图解决我的问题的方式:

Sig = cov(x);   % Covariance calculation of a 12x50 matrix
 A = chol(Sig);
 Sigma = A*A';
p = mvnrnd(mu,Sigma,20);

但是当我运行它时,它给了我这个错误:

Matrix must be positive definite.
Error at A = chol(Sig);

我的矩阵仍然不是正定的。知道如何解决这个问题吗?

4

1 回答 1

0

我以前见过这个问题。如何计算给定矩阵最近的对称正定矩阵(通常缩写为 SPD)?我对在 MATLAB Central 文件交换中找到的内容不满意,所以我只是在 FEX 上发布了最近的 SPD 。

从一个在 SPD 方面完全是废话的矩阵开始......

U = randn(100);
tic,Uj = nearestSPD(U);toc
Elapsed time is 0.006049 seconds.

最终的测试当然是使用 chol。如果 chol 返回的第二个参数为零,那么 MATLAB(和 mvnrnd)会很高兴!

[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
于 2013-07-30T12:02:37.827 回答