mardi 21 juillet 2020

How to generate random uniform disturbed random vectors of euclidian lenght of one?

Hi Stackoverflow Community,

I am trying to randomly generate uniformly distributed vectors, which are of Euclidian length of 1. By uniformly distributed I mean that each entry (coordinate) of the vectors is uniformly distributed.

More specifically, I would like to create a set of, say, 1000 vectors (lets call them V_i, with i=1,…,1000), where each of these random vectors has unit Euclidian length and the same dimension V_i=(v_1i,…,v_ni)' (let’s say n = 5, but the algorithm should work with any dimension). If we then look on the distribution of e.g. v_1i, the first element of each V_i, then I would like that this is uniformly distributed.

In the attached MATLAB example you see that you cannot simply draw random vectors from a uniform distribution and then normalize the vectors to Euclidian length of 1, as the distribution of the elements across the vectors is then no longer uniform.

Is there a way to generate this set of vectors such, that the distribution of the single elements across the vector-set is uniform?

Thank you for any ideas.

PS: MATLAB is our Language of choice, but solutions in any languages are, of course, welcome.

clear all
   rng('default')
   
   nvar=5;
   sample = 1000;
   
   x = zeros(nvar,sample);
   
   for ii = 1:sample
       
       y=rand(nvar,1);  
       x(:,ii) = y./norm(y);
       
   end
   
   hist(x(1,:))
   figure
   hist(x(2,:))
   figure

   hist(x(3,:))
   figure
   hist(x(4,:))
   figure
   hist(x(5,:))



Aucun commentaire:

Enregistrer un commentaire