Path: news.mathworks.com!not-for-mail From: "Vassilios Vassiliadis" <v.vassiliadis@fme.aegean.gr> Newsgroups: comp.soft-sys.matlab Subject: Re: How to generate vector of random numbers in any interval (e.g. Date: Wed, 10 Nov 2010 09:15:04 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 21 Message-ID: <ibdnqo$98c$1@fred.mathworks.com> References: <ibbfkv$l6m$1@fred.mathworks.com> <PEdCo.12435$lL3.8212@newsfe08.iad> <ibbv7h$da7$1@fred.mathworks.com> Reply-To: "Vassilios Vassiliadis" <v.vassiliadis@fme.aegean.gr> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1289380504 9484 172.30.248.35 (10 Nov 2010 09:15:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Wed, 10 Nov 2010 09:15:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2604339 Xref: news.mathworks.com comp.soft-sys.matlab:685430 Thank you very much for your help... Vassilios "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ibbv7h$da7$1@fred.mathworks.com>... > Walter Roberson <roberson@hushmail.com> wrote in message <PEdCo.12435$lL3.8212@newsfe08.iad>... > > On 09/11/10 6:43 AM, Vassilios Vassiliadis wrote: > > > > > I'd like to generate a vector of random numbers,which take values in any > > > interval (e.g. [-1 1]),and this vector sums to 1... > > > > If you use a fixed number of entries in the vector, then the last one > > will never be random: it's value is fully predictable by knowing the > > previous ones. > > ........ > - - - - - - - - - > It does make sense to have random vectors which have a given sum, Walter. It is a standard problem in conditional probability analogous to asking to simulate a random toss of two dice given that their sum has been observed to be say seven. If two values, x and y, of the 'rand' function are chosen, this can be viewed statistically as the selection of a random point in a unit square in the x-y plane where equal areas have equal probabilities. However if we require that their sum be given as say one, then it is a conditional probability problem and can be regarded as a uniformly distributed selection along the line of the square's diagonal where equal lengths then have equal probabilities as required by the conditional probability concept. > > Vassilios is asking how to generate random points in a certain polytope in n-dimensional space corresponding to a given sum of random variables, and this makes perfectly good sense. Unfortunately if one simply normalizes a set of random values from 'rand' so as to have the given sum, this skews the distribution. In the case of the unit square doing so would have the effect of projecting the square's area orthogonally onto its diagonal which produces a triangular distribution along its length. It requires a little more sophistication to produce a uniform distribution length-wise, which is why I wrote the 'randfixedsum' routine. > > Roger Stafford