You are on page 1of 2

1/17/2017 matlabHowtogeneratearandomrealsymmetricsquarematrixwithuniformlydistributedentriesStackOverflow

signup login tour help

xDismiss

JointheStackOverflowCommunity

Stack Overflow is a community of 6.6 million


programmers, just like you, helping each other.
Join them it only takes a minute:

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?

matlab random matrix symmetric

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)';

where triu() takestheuppertriangularpartofthematrix.

editedMar17'12at14:07 answeredMar17'12at13:44
OliverCharlesworth
189k 22 381 529

thanks,Oli,anyadviceonhowtomakeituniformlydistributed? Aina Mar17'12at13:46

@Aina:Seemyupdatedanswer. OliverCharlesworth Mar17'12at13:50

thanks,Oli,sousingtriufunctionkeepstheuniformdistribution?Ihavejustrunitandhist(b)looksdifferent
towhatIhadformymatrixb. Aina Mar17'12at13:53

@Aina:Thisapproachavoidsaddinganyelementstogether. OliverCharlesworth 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

You might also like