monte carlo simulation question
Afficher commentaires plus anciens
can anyone help me figure out whats wrong with this code. im trying to run a simulation where 3 people flip a coin if all are heads or tais they take them back. however if two coins come up heads or tails the person with the unique coin wins a coin from the other two. my problem is that my code doest follow the given conditions based on the code and instead only executes the first if statement.
a=5 % person 1 int coin
b=5 % person 2 int coin
c=5 % person 3 int coin
d=0
step=0
for i=1:1:100000
t=rand() % person 1 flip
y=rand() % person 2 flip
z=rand() % person 3 flip
a=a+d
b=b+d
c=c+d
while ( (a>0 && b>0) || (b>0&& c>0)||(a>0 && c>0) || (b>0&& a>0) ||(c>0&& a>0)||(c>0&& b>0) )
step=step+1
t=rand() % person 1 flip
y=rand() % person 2 flip
z=rand() % person 3 flip
if y&&t < .5
a= a -1
b= b-1
c= c+2
elseif y&&t >.5
a= a -1
b= b-1
c= c+2
elseif z&&t < .5
a= a -1
b= b+2
c= c-1
elseif z&&t >.5
a= a -1
b= b+2
c= c-1
elseif y&&z < .5
a= a +2
b= b-1
c= c-1
elseif y&&z >.5
a= a +2
b= b-1
c= c-1
elseif z&&t&&y >.5
a=a+0
b=b+0
c=c+0
elseif z&&t&&y <.5
a=a+0
b=b+0
c=c+0
end
a=a+0
b=b+0
c=c+0
end
end
disp(a)
disp(b)
disp(c)
disp(i)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!