Professional Documents
Culture Documents
xDismiss
JointheStackOverflowCommunity
Signup
Howtogeneratearandomrealsymmetricsquarematrixwithuniformlydistributedentries
Iwouldliketogeneratearandomrealsymmetricsquarematrixwithentriesuniformlydistributedbetween0and1.Myattemptis: a=rand(5);
b=a+a.'
Myworryisthatwhilstmatrixaisuniformlydistributedaccordingtothedocumentationhttp://www.mathworks.com.au/help/techdoc/ref/rand.html
matrixbmightnotbesincetheaverageoftworandomnumbersmightnotbethesameastheoriginalnumber.
Itriedtouse hist(a);
hist(b) butnotsurehowtointerprettheresultinggraph.EDIT:AccordingtoOlimatrixbisnolongeruniformlydistributed,isthereawayto
makeitthatway?
editedMar17'12at13:49 askedMar17'12at13:42
Aina
181 1 3 14
2Answers
No,ifyoudothatthen b willnotbeuniformlydistributeditwillhaveatriangular
distribution.
Howaboutsomethinglikethis:
a=rand(5);
b=triu(a)+triu(a,1)';
editedMar17'12at14:07 answeredMar17'12at13:44
OliverCharlesworth
189k 22 381 529
thanks,Oli,sousingtriufunctionkeepstheuniformdistribution?Ihavejustrunitandhist(b)looksdifferent
towhatIhadformymatrixb. Aina Mar17'12at13:53
@Aina:25elementsisnotenoughtoproduceausefulhistogram.Youshouldgenerate,say,10000ofthese
randommatrices,andthendoahistogramonthewholething.OliverCharlesworthMar17'12at14:03
Youcanonlygetuniformlydistributedentriesonhalfofthematrix.
http://stackoverflow.com/questions/9750432/howtogeneratearandomrealsymmetricsquarematrixwithuniformlydistributed 1/2
1/17/2017 matlabHowtogeneratearandomrealsymmetricsquarematrixwithuniformlydistributedentriesStackOverflow
a=rand(5);
b=triu(a).'+triu(a,1);
editedMar17'12at13:50 answeredMar17'12at13:45
user677656
thanksg24l,sothenitisIMPOSSIBLEtohavearandomsymmetricmatrixwithuniformlydistributed
entries? Aina Mar17'12at13:58
@Aina:Iwastalkingonhowtogeneratethematrix.Theelementsofthematrixareuniformlydistributed,
butnotrandom,andnotiid.user677656Mar17'12at14:38
http://stackoverflow.com/questions/9750432/howtogeneratearandomrealsymmetricsquarematrixwithuniformlydistributed 2/2