Random vectors with null sum
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 20 Jun. 2012
Is the number of vectors to use known, or should it keep generating until it finds a solution?
Akzeptierte Antwort
Weitere Antworten (1)
the cyclist
am 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 Kommentare
Walter Roberson
am 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.)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!