Random vectors with null sum

2 ビュー (過去 30 日間)
Matteo Cacciola
Matteo Cacciola 2012 年 6 月 20 日
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 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 20 日
Is the number of vectors to use known, or should it keep generating until it finds a solution?
Matteo Cacciola
Matteo Cacciola 2012 年 6 月 20 日
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
Matteo Cacciola 2012 年 6 月 23 日
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.

その他の回答 (1 件)

the cyclist
the cyclist 2012 年 6 月 20 日
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 件のコメント
Matteo Cacciola
Matteo Cacciola 2012 年 6 月 20 日
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 2012 年 6 月 20 日
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.)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by