Random vectors with null sum

Asked by Matteo Cacciola on 20 Jun 2012
Latest activity Answered by Matteo Cacciola on 23 Jun 2012

Hello, I have a question for you. I have to initialize a number of 3D vectors, with fixed magnitude (intensity) equal to I, but the sum (in the geometrical sense) of vectors should be null. I prefer to work with angles (azimuth and elevation), but obviously a solution just considering the x-, y- and z-components of the vectors is fine, since thereafter I can make the transformation with cart2sph function.

Thanks a lot to all that could give me a support

Regards Matteo

2 Comments

Walter Roberson on 20 Jun 2012

Is the number of vectors to use known, or should it keep generating until it finds a solution?

Matteo Cacciola on 20 Jun 2012

Yes it is. Let me say that I have to generate N vectors, for instance N=100, each vectors has intensity I, for instance I=2, but the geometrical sum of vectors should be zero. Thanks

Matteo Cacciola

Products

No products are associated with this question.

2 Answers

Answer by Matteo Cacciola on 23 Jun 2012
Accepted answer

I added a trivial solution. If the number to generate is even, I take couples of vectors. An element of each pair is randomly set, the other in opposite phase. If the number is odd, I do as for even vectors, but excluding three of them, which will be set manually as a null vector according to the rule of parallelogram. Thanks for your help.

0 Comments

Matteo Cacciola
Answer by the cyclist on 20 Jun 2012

Even in just one dimension, it's a non-trivial problem to combine random numbers to have a fixed sum. (The question comes up with some frequency here.) The following doesn't do exactly what you want (I don't believe), but you might be able to bend it to your needs.

http://www.mathworks.com/matlabcentral/fileexchange/9700

2 Comments

Matteo Cacciola on 20 Jun 2012

Thanks a lot, but unfortunately I already tried to exploit that code by considering that a vector is null if and only if all the components are null. So I tried to generate vectors where the sum of x- and y-components are null, then calculating each z-component by means of the well known relationship x^2 +y^2+z^2=I^2.
But I didn't take a suitable solution, since for some cases x^2+y^2>I^2, since random generation of x- and y-components are carried out independently. Any suggestion about?

Walter Roberson on 20 Jun 2012

Usually the easiest thing to do is to reject those (x,y) pairs and generate more. (Some of those might have problems too, so put yourself in a loop until you get N valid (x,y) pairs, each time generating (N minus number you have so far) samples.)

the cyclist

Contact us