[Math] Monte Carlo Simulation- Simulating Sum of a DICE. Matlab CODE.

MATLABmonte carloprobability

Hello everyone, I try to solve the following problem:

Use Monte Carlo simulation to approximate the sum of the 100 consecutive rolls of a fair die.

My work in math lab is:

sum=0;
roll= 100; 

for i = 1:roll    
    numbroll = ceil(6*rand);     
    sum=sum+numbroll;
end
sum

This code return the sum of 100 rolls.
Back in the book the answer for this exerise said:
enter image description here

Question: I don't know if I missunderstand the statement or not. What is the correct answer? and if someone know how to do the coding for a pair of dice I will be really apreciated.

Thanks for your help !

Best Answer

Electro82 was definitely on the right track - just a couple of mods here and this works:

sum = 0;
roll = 100; 
distribution = zeros(1,12);

for i = 1:roll    
      dice_one = ceil(6 * rand);  
      dice_two = ceil(6 * rand);
      cursum = dice_one + dice_two;
      distribution(cursum) = distribution(cursum) + 1;
end

distribution/roll
Related Question