Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Generate random numbers with fixed sum and different constraints
Replies: 25   Last Post: Sep 17, 2013 2:28 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Roger Stafford

Posts: 5,852
Registered: 12/7/04
Re: Generate random numbers with fixed sum and different constraints
Posted: Nov 17, 2012 1:32 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Greg Heath" <heath@alumni.brown.edu> wrote in message <k87s11$h6u$1@newscl01ah.mathworks.com>...
> "Dmitrey Yershov" <pierrevanstulov@mail.ru> wrote in message <k80995$9eo$1@newscl01ah.mathworks.com>...
> > Hello. I need to generate non-negative rundom numbers sum of which is equal to 1. Each number xi is constrained: ai<=xi<=bi. How can I do this? Similar question was solved here
> >
> > http://www.mathworks.com/matlabcentral/fileexchange/9700
> >
> > but in this alghorithm a<=xi<=b (a and b are the same for all xi). Any ideas?

>
> Z = a + (b-a)*rand(m,n);
>
> sumZ = repmat(sum(Z),m,1);
>
> I'll let you figure out the rest.
>
> Hope this helps
>
> Greg

- - - - - - - - - -
I'd like to know the answer to that too, Greg. Suppose your m = 3, n = 1, a = 0, and b = 2/3, and suppose z comes up randomly with z = [.6;.1;.1] as is possible. How is that point supposed to be projected onto a plane so as to have a sum of 1? A simple division by its sum(z) = .8 gives [.75;.125;.125] which exceeds the stated limit.

The space of points in this case having a sum of 1 within the permitted three-dimensional cube cuts it in half in a planar hexagon, and it is difficult to see how to project all points in the cube onto this hexagon in a simple manner using just the sum(z), never mind doing so in an area-wise uniform manner throughout the hexagon.

This is one of the reasons I went to the trouble of writing 'randfixedsum' which breaks such a hexagon into triangles and deals with each separately. However doing a similar thing with an n-dimensional rectangular box other than an n-dimensional cube as Dmitrey wishes to do is a project involving much more complicated simplex structure. At the moment I have no idea how to set about such a task.

Roger Stafford


Date Subject Author
11/14/12
Read Generate random numbers with fixed sum and different constraints
Dmitrey Yershov
11/17/12
Read Re: Generate random numbers with fixed sum and different constraints
Greg Heath
11/17/12
Read Re: Generate random numbers with fixed sum and different constraints
Roger Stafford
11/17/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/17/12
Read Re: Generate random numbers with fixed sum and different constraints
Roger Stafford
11/18/12
Read Re: Generate random numbers with fixed sum and different constraints
Dmitrey Yershov
11/18/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/19/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/19/12
Read Re: Generate random numbers with fixed sum and different constraints
Dmitrey Yershov
11/19/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/19/12
Read Re: Generate random numbers with fixed sum and different constraints
Dmitrey Yershov
11/19/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/19/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/19/12
Read Re: Generate random numbers with fixed sum and different constraints
Roger Stafford
11/20/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/20/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/20/12
Read Re: Generate random numbers with fixed sum and different constraints
Roger Stafford
11/21/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/21/12
Read Re: Generate random numbers with fixed sum and different constraints
james bejon
11/20/12
Read Re: Generate random numbers with fixed sum and different constraints
james bejon
9/17/13
Read Re: Generate random numbers with fixed sum and different constraints
JS Hong
9/17/13
Read Re: Generate random numbers with fixed sum and different constraints
JS Hong
11/19/12
Read Re: Generate random numbers with fixed sum and different constraints
David Epstein
11/19/12
Read Re: Generate random numbers with fixed sum and different constraints
Roger Stafford
11/20/12
Read Re: Generate random numbers with fixed sum and different constraints
Bruno Luong
11/17/12
Read Re: Generate random numbers with fixed sum and different constraints
Greg Heath

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.