MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply TodayMATLAB Central > MATLAB Newsreader > Generate random numbers with fixed sum and differe... 

Subject: Generate random numbers with fixed sum and different constraints From: Dmitrey Yershov Date: 14 Nov, 2012 14:19:17 Message: 1 of 26 
Hello. I need to generate nonnegative 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 
Subject: Generate random numbers with fixed sum and different constraints From: Greg Heath Date: 17 Nov, 2012 11:22:09 Message: 2 of 26 
"Dmitrey Yershov" <pierrevanstulov@mail.ru> wrote in message <k80995$9eo$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Roger Stafford Date: 17 Nov, 2012 18:32:16 Message: 3 of 26 
"Greg Heath" <heath@alumni.brown.edu> wrote in message <k87s11$h6u$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 17 Nov, 2012 19:59:12 Message: 4 of 26 
"Roger Stafford" wrote in message <k88l7g$7tm$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Roger Stafford Date: 18 Nov, 2012 01:44:16 Message: 5 of 26 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <k88qag$nm1$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Greg Heath Date: 18 Nov, 2012 02:05:23 Message: 6 of 26 
"Roger Stafford" wrote in message <k88l7g$7tm$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Dmitrey Yershov Date: 18 Nov, 2012 17:04:09 Message: 7 of 26 
"Roger Stafford" wrote in message <k89ehg$rm6$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 18 Nov, 2012 18:46:10 Message: 8 of 26 
I have not fully tested, but it should go like this: 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 19 Nov, 2012 06:39:13 Message: 9 of 26 
Sorry, I miss the definition of the variable 'tol' in my previous posted code; here we go again: 
Subject: Generate random numbers with fixed sum and different constraints From: David Epstein Date: 19 Nov, 2012 10:26:09 Message: 10 of 26 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <k8badi$8rd$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Dmitrey Yershov Date: 19 Nov, 2012 10:58:07 Message: 11 of 26 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <k8ck6h$lhp$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 19 Nov, 2012 12:04:13 Message: 12 of 26 
"Dmitrey Yershov" <pierrevanstulov@mail.ru> wrote in message 
Subject: Generate random numbers with fixed sum and different constraints From: Dmitrey Yershov Date: 19 Nov, 2012 12:29:08 Message: 13 of 26 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <k8d77s$lfd$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 19 Nov, 2012 12:39:13 Message: 14 of 26 
"Dmitrey Yershov" <pierrevanstulov@mail.ru> wrote in message 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 19 Nov, 2012 13:02:11 Message: 15 of 26 
It seems to me this task 
Subject: Generate random numbers with fixed sum and different constraints From: Roger Stafford Date: 19 Nov, 2012 23:10:18 Message: 16 of 26 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <k8dakj$39u$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Roger Stafford Date: 20 Nov, 2012 01:54:09 Message: 17 of 26 
"David Epstein" <David.Epstein.spam@remove.warwick.ac.uk> wrote in message <k8d1g1$4gr$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 20 Nov, 2012 06:53:08 Message: 18 of 26 
"Roger Stafford" wrote in message <k8ee8q$k6f$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 20 Nov, 2012 07:02:09 Message: 19 of 26 
Just a small typo correction in a comment of my code. It should read: 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 20 Nov, 2012 07:17:08 Message: 20 of 26 
"Roger Stafford" wrote in message <k8ens1$kfr$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: james bejon Date: 20 Nov, 2012 08:16:14 Message: 21 of 26 
"Roger Stafford" wrote in message <k8ee8q$k6f$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Roger Stafford Date: 20 Nov, 2012 19:54:09 Message: 22 of 26 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <k8f9ck$gng$1@newscl01ah.mathworks.com>... 
Subject: Generate random numbers with fixed sum and different constraints From: Bruno Luong Date: 21 Nov, 2012 07:38:17 Message: 23 of 26 
Thanks Roger for the explanation. 
Subject: Generate random numbers with fixed sum and different constraints From: james bejon Date: 21 Nov, 2012 21:14:09 Message: 24 of 26 
Very nice. I hadn't thought of it in those terms. 
Subject: Generate random numbers with fixed sum and different constraints From: JS Hong Date: 17 Sep, 2013 05:52:09 Message: 25 of 26 
Similar error happened to me with five variable. 
Subject: Generate random numbers with fixed sum and different constraints From: JS Hong Date: 17 Sep, 2013 06:28:06 Message: 26 of 26 
Actually, I found the similar error with original parameters 
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.