Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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

a=rand(5);
b=triu(a).'+triu(a,1);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top