Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Simulation of 5 Random Variables with Sum Constraint
Replies: 8   Last Post: Apr 3, 2013 3:05 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Siddhartha

Posts: 6
Registered: 11/19/12
Simulation of 5 Random Variables with Sum Constraint
Posted: Mar 27, 2013 4:50 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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));



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.