Random vectors with null sum

1 view (last 30 days)
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
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
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

Sign in to comment.

Accepted Answer

Matteo Cacciola
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.

More Answers (1)

the cyclist
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.
  2 Comments
Matteo Cacciola
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
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.)

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!