MATLAB, Random Variable, Probability and Statistics Please indicate which MATLAB
ID: 3764631 • Letter: M
Question
MATLAB, Random Variable, Probability and Statistics
Please indicate which MATLAB programs are being used to generate the date at the end.
Simulation of Game of craps. A player rolls two fair dice. If the sum of the dice is either 2 3 or 12 the player loses: if the sum is either a 7 or an 11 he or she wins. If the outcome is anything else, the player continues to roll the two dice until he or she rolls either the initial outcome or a 7. If the 7 comes first, the player loses; whereas if the initial outcome reoccurs before the 7, the player wins. Write a MATLAB program to generate sum of two fair dice using t =10000 samples. Compute the probability of winning on the first roll based on your samples?Explanation / Answer
firstwins=0;
wins=0;
lost=0;
for i=1:10000
result =0;
turn =1;
chck=zeros(12);
while result==0
a=randi(6);
b=randi(6);
c=a+b;
if turn==1
if c==7 || c==11
wins=wins+1;
firstwins=firstwins+1;
result=1;
elseif c==2 || c==3 || c==12
lost=lost+1;
result=1;
else
turn=turn+1;
chck(c)=1;
end;
else
if c==7
lost=lost+1;
result=1;
elseif chck(c)==1
wins=wins+1;
result=1;
else
chck(c)=1;
turn=turn+1;
end;
end;
end;
end;
prob=firstwins/10000;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.