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

8 views (last 30 days)
Hi MATLAB 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,:))
  2 Comments
Bruno Luong
Bruno Luong on 21 Jul 2020
Edited: Bruno Luong on 21 Jul 2020
After thinking more carefully I have impression that what you ask for is impossible, unless n=3, where generating uniform of the 2-ball implies uniform for each component.
Not sure how to prove it though.
But start with something easier, for n=1 it's trivial that it's impossible.
For n=2 I bet you to be able generate such distribution.
John D'Errico
John D'Errico on 21 Jul 2020
You need to very carefully define what you mean by "uniformly distributed". Otherwise this discussion is itself meaningless.
That is, you say that you want uniformly distributed vectors. By this, do you mean the vectors must be uniformly distributed in some space? On the surface of a sphere, for exmple? Or only that you want the elements of the vectors to be uniformly distributed? And even at that, what do you mean by uniformly distributed? Do you mean that V(1) is uniformly distributed on some interval, as well as V(2), V(3), etc? Or do you mean that the elements of V are in some way uniformly distributed as a set?
So before I would even try to go any further, you need to explain exactly what you mean. Then we can have some hope of either explaining why that goal is impossible, or explain how you might achieve it.

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 21 Jul 2020
Edited: Bruno Luong on 22 Jul 2020
My conjecture: the only dimension that is possible of generate uniform distribution for all components is n==3 (n is nvars in the question). In that case the solution is
m = 1000000;
n = 3; % only possible dimension
x = randn(m,n); % Important: Do not change Normmal law to something else
x = x ./ sqrt(sum(x.^2,2));
Check
figure
for k=1:n
subplot(1,n,k);
hist(x(:,k),100);
xlabel(sprintf('x_%d',k));
ylabel('count');
end
  4 Comments
Sebastian Kupek
Sebastian Kupek on 21 Jul 2020
Dear John,
thank you for your comment.
It is true the rotation is distributed unifromly, but as asked in the question above i need the entries (coordinates) directly, as presented in the histogram I plotted, to be uniform and not the rotation coefficients. I'm sorry if that was not expressed precisely enough.
Kind regards.
Sebastian
Bruno Luong
Bruno Luong on 22 Jul 2020
Response in my edit post. Only dimension the required random vector is possible is for n=3.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!