How to create a random real symmetric square matrix with uniformly distributed elements

I would like to create a random real symmetric square matrix with elements evenly distributed between 0 and 1. My attempt: a = rand(5); b = a + a.' a = rand(5); b = a + a.'

My concern is that although matrix a is evenly distributed according to the documentation http://www.mathworks.com.au/help/techdoc/ref/rand.html , matrix b may not be, since the average of the two random numbers may not be the same as the original number.

I tried using hist(a); hist(b) hist(a); hist(b) but not sure how to interpret the resulting graph. EDIT: According to the Oli matrix, b is no longer evenly distributed, is there a way to do it this way?

+6
source share
2 answers

No, if you do this, then b will not be evenly distributed; he will have a triangular distribution .

How about something like this:

 a = rand(5); b = triu(a) + triu(a,1)'; 

where triu() takes the upper triangular part of the matrix.

+14
source

You can get evenly distributed records in half the matrix.

 a=rand(5); b=triu(a).'+triu(a,1); 
+2
source

Source: https://habr.com/ru/post/910984/


All Articles