Random vectors with null sum
1 view (last 30 days)
Show older comments
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?
Accepted Answer
More Answers (1)
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
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.)
See Also
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!