Re: using random with constraints



thanks for your help!

"Lorenzo Guerrasio" <lorenzo.guerrasio@xxxxxxxx> wrote in
message <g7utam$afn$1@xxxxxxxxxxxxxxxxxx>...
"Lorenzo Guerrasio" <lorenzo.guerrasio@xxxxxxxx> wrote in
message <g7usia$2n$1@xxxxxxxxxxxxxxxxxx>...
"Anna Chen" <icedredtea@xxxxxxxxx> wrote in message
<g7uqs2
$8eq$1@xxxxxxxxxxxxxxxxxx>...
hello,
i would like to generate random vectors that have the
constraint that the components should sum to zero,
and
that
the components are picked from some distribution.
would
there be an easy way to do this using "random"?
thanks!



Hi, the only distribution I know is the Von Mises.
There
is
a nice file the the exchange (randraw) to produce
vectors
from a von mises distribution.

Once you get these vectors, you can multiply them for a
random variable, to change the amplitude, and add the
opposite distribution.

Alternatively you can extract the hor and ver component
from a gaussian distribution with 0 mean and adding a
last
component so that sum([hor_comp,ver_comp])==0.

Maybe there are more elegant way...

bye

just to give an example...

hor_comp = normrnd(0,10,1000,1);
ver_comp = normrnd(0,10,1000,1);
hor_comp = [hor_comp;-sum(hor_comp)];
ver_comp = [ver_comp;-sum(ver_comp)];


.



Relevant Pages


Loading