# 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

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

## Products

No products are associated with this question.

Answer by Matteo Cacciola on 23 Jun 2012

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.

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