monte carlo simulation
Afficher commentaires plus anciens
can anyone please 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 doesnt follow the given conditions based on the code and instead seems to excute only one of the statements instead of following the given conditions
a=5; % person 1 int coin
b=5; % person 2 int coin
c=5; % person 3 int coin
step=0
for i=1:1:100
step=step+1
d=rand(1,3) % coin flip for 3 people
if d(1,1)&&d(1,2) < .5
a= a -1
b= b-1
c= c+2
elseif d(1,1)&&d(1,2) >.5
a= a -1
b= b-1
c= c+2
elseif d(1,1)&&d(1,3) < .5
a= a -1
b= b+2
c= c-1
elseif d(1,1)&&d(1,3) >.5
a= a -1
b= b+2
c= c-1
elseif d(1,3)&&d(1,2) < .5
a= a +2
b= b-1
c= c-1
elseif d(1,2)&&d(1,3) >.5
a= a +2
b= b-1
c= c-1
elseif d(1,1)&&d(1,2)&&d(1,3) >.5
a=a+0
b=b+0
c=c+0
elseif d(1,1)&&d(1,2)&&d(1,3) <.5
a=a+0
b=b+0
c=c+0
end
end
disp(d(1,1))
disp(d(1,2))
disp(d(1,3))
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Monte-Carlo 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!