Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: draw normal random numbers with fixed sum
Date: Fri, 11 Mar 2011 14:19:04 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 31
Message-ID: <ildb0o$9gd$1@fred.mathworks.com>
References: <il7mnh$j2s$1@fred.mathworks.com> <il8eig$jht$1@fred.mathworks.com> <ilamog$3o0$1@fred.mathworks.com> <ilb1bt$gnb$1@fred.mathworks.com> <ild7g8$kgd$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1299853144 9741 172.30.248.45 (11 Mar 2011 14:19:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 11 Mar 2011 14:19:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:715224

"Claudia" wrote in message <ild7g8$kgd$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ilb1bt$gnb$1@fred.mathworks.com>...
> > s = 10; % target sum
> > N=3; % number of random variables
> > sigma = 2; % standard deviation
> > ndata = 1e6; % number of data
> > 
> > Q = null(ones(1,N));
> > X = (sigma*sqrt(N/(N-1)))*Q*randn(N-1,ndata);
> > mu = s/N;
> > X = mu + X;
> > 
> > % Test
> > sum(X(:,1:10),1)
> > std(X')
> > 
> > % Bruno
> > 
> > As Roger wrote earlier, by imposing the sum, the three variables will not be independent.
> 
> Okay, I now understand it, but why the factor "sigma*sqrt(N/(N-1))"? 

If Y = Q*randn; then Y has covariance matrix H = Q*Q'. The standard deviation of each component of Y is:

sqrt(H(i,i)).

It can be showed that the diagonal of H: H(i,i) is (N-1)/N for Q = null(ones(1,N)).

Thus in order to normalize X from Y such that the standard deviation is sigma; we need to multiply Y by (sigma*sqrt(N/(N-1))).

Bruno