From: "Vassilios Vassiliadis" <>
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$>
References: <ibbfkv$l6m$> <PEdCo.12435$lL3.8212@newsfe08.iad> <ibbv7h$da7$>
Reply-To: "Vassilios Vassiliadis" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1289380504 9484 (10 Nov 2010 09:15:04 GMT)
NNTP-Posting-Date: Wed, 10 Nov 2010 09:15:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2604339
Xref: comp.soft-sys.matlab:685430

Thank you very much for your help...


"Roger Stafford" <> wrote in message <ibbv7h$da7$>...
> Walter Roberson <> 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