Dice Rolling simulation in MATLAB, using relative frequency approach
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Achyuth S.S
am 11 Nov. 2022
Kommentiert: Achyuth S.S
am 12 Nov. 2022
Consider the dice rolling experiment. Use the relative frequency approach to assign the probability of the event, A = {sum of two dice = 5}. Simulate the tossing of two dice using the MATLAB code. The results of this dice tossing simulation must approximately follow the results shown in Table 1.

Akzeptierte Antwort
Image Analyst
am 11 Nov. 2022
Hint:
n = 1000;
rolls = randi(6, n, 2)
sumOfRolls = sum(rolls, 2)
3 Kommentare
Image Analyst
am 12 Nov. 2022
Bearbeitet: Image Analyst
am 12 Nov. 2022
Looks like you figured it out since you Accepted the answer (thank you 🙂).
I guess you finally realized that it is the number of times the rolls sum to 5 in n tosses.
format short g
alln = 1000 : 1000 : 10000;
for k = 1 : length(alln)
n = alln(k);
rolls = randi(6, n, 2);
sumOfRolls = sum(rolls, 2);
% Count how many times the sums equal 5.
nA(k) = sum(sumOfRolls == 5);
% Compute fraction of 5's
fract(k) = nA(k) / n;
end
nA
fract
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!