Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 Greg Heath Posts: 6,387 Registered: 12/7/04
Re: Generate random numbers with fixed sum and different constraints
Posted: Nov 17, 2012 6:22 AM

"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

Date Subject Author
11/14/12 Dmitrey Yershov
11/17/12 Greg Heath
11/17/12 Roger Stafford
11/17/12 Bruno Luong
11/17/12 Roger Stafford
11/18/12 Dmitrey Yershov
11/18/12 Bruno Luong
11/19/12 Bruno Luong
11/19/12 Dmitrey Yershov
11/19/12 Bruno Luong
11/19/12 Dmitrey Yershov
11/19/12 Bruno Luong
11/19/12 Bruno Luong
11/19/12 Roger Stafford
11/20/12 Bruno Luong
11/20/12 Bruno Luong
11/20/12 Roger Stafford
11/21/12 Bruno Luong
11/21/12 james bejon
11/20/12 james bejon
9/17/13 JS Hong
9/17/13 JS Hong
11/19/12 David Epstein
11/19/12 Roger Stafford
11/20/12 Bruno Luong
11/17/12 Greg Heath