Aina
Aina

Reputation: 653

How to generate a random real symmetric square matrix with uniformly distributed entries

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

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

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

Upvotes: 7

Views: 13791

Answers (2)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272487

No, if you do that then b will not be uniformly distributed; it 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.

Upvotes: 15

user677656
user677656

Reputation:

You can only get uniformly distributed entries on half of the matrix.

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

Upvotes: 2

Related Questions