Two Dice Monte Carlo Simulation
이전 댓글 표시
On a roll of two dice, a total of seven occurs with probability 1=6. In 100 rolls of the dice, what is the probability that five consecutive rolls of seven will occur? Model using Monte Carlo simulation.
..................................................
p=1/6;
N=100;
sumseven=zeros(N,1);
for m=1:N
l=0;
for k=1:5
x=rand;
if x<p
l=l+1;
else
l=0;
end
if l==5
sumseven(m)=1;
break;
end
end
end
p_sumseven=sum(sumseven(:))/N;
fprintf('Probability of a 5 consecutive rolls of 7: p=%6.5f\n',p_sumseven);
........................................
not sure about (if x < p)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Monte-Carlo에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!