Dice Rolling simulation in MATLAB, using relative frequency approach

13 ビュー (過去 30 日間)
Achyuth S.S
Achyuth S.S 2022 年 11 月 11 日
コメント済み: Achyuth S.S 2022 年 11 月 12 日
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.
  1 件のコメント
the cyclist
the cyclist 2022 年 11 月 11 日
Please read this guide about getting help with homework, and edit your question accordingly.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2022 年 11 月 11 日
Hint:
n = 1000;
rolls = randi(6, n, 2)
rolls = 1000×2
6 2 1 5 5 3 2 1 2 4 5 1 6 4 6 3 5 3 1 3
sumOfRolls = sum(rolls, 2)
sumOfRolls = 1000×1
8 6 8 3 6 6 10 9 8 4
  3 件のコメント
Image Analyst
Image Analyst 2022 年 11 月 12 日
編集済み: Image Analyst 2022 年 11 月 12 日
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
nA = 1×10
99 229 337 442 527 657 780 865 1003 1114
fract
fract = 1×10
0.099 0.1145 0.11233 0.1105 0.1054 0.1095 0.11143 0.10812 0.11144 0.1114
Achyuth S.S
Achyuth S.S 2022 年 11 月 12 日
thanks , I had figured it out!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by