Path: news.mathworks.com!not-for-mail
From: "Siddhartha " <siddhsam@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Simulation of 5 Random Variables with Sum Constraint
Date: Wed, 27 Mar 2013 20:50:11 +0000 (UTC)
Organization: Intel Corp
Lines: 29
Message-ID: <kivm23$ip1$1@newscl01ah.mathworks.com>
Reply-To: "Siddhartha " <siddhsam@hotmail.com>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1364417411 19233 172.30.248.37 (27 Mar 2013 20:50:11 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 27 Mar 2013 20:50:11 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3857760
Xref: news.mathworks.com comp.soft-sys.matlab:792126

Let's say I have 5 random variables that are discrete.  Each one of them can possess a low, base and high value somewhere between 15 and 35. I know their sum can never exceed 98. What's the best way to simulate this? Is the rejection method good? The sudden drop in the pdf of the sum bothers me, not sure if that's right, but it maybe.


n = 5;
a(n,3) = 0;
for i = 1:n
    a(i,1:3) = [100/(1.5*n)+(-1)^fix(rand)*rand*(100/(2*n)) 100/(1.1*n)+(-1)^fix(rand)*rand*(100/(2*n)) 100/(0.8*n)+(-1)^fix(rand)*rand*(100/(2*n))];
end


d = lhsdesign(n,10000);

e = 0;
b(1,10000)=0;
for i = 1:n
    b(d(i,:)<0.3) = a(i,1);
    b(d(i,:)>0.7) = a(i,3);
    b(b==0) = a(i,2);
    e = e + b;
end

f = e(e<98);
[~,cole] = size(unique(e));
[~,colf] = size(unique(f));

subplot(2,2,1), hist(e,cole);
subplot(2,2,2), hist(e(e<98),colf);
subplot(2,2,3), ecdf(e);
subplot(2,2,4), ecdf(e(e<98));