calculating probability in Matlab

11 ビュー (過去 30 日間)
SSBGH
SSBGH 2022 年 10 月 16 日
編集済み: Torsten 2022 年 10 月 16 日
i have this question:
create a MATLAB function that approximates the probability in the following experiment with simulations!Two fair dice are thrown. Find the probability that the sum of the numbers obtained is 8.
The number of simulation should be N = 10^3. The variable p should store the approximation.
function p = sim()
N = 10^3;
p = ;
end
does any body have an idea how to continue from here?

採用された回答

Torsten
Torsten 2022 年 10 月 16 日
編集済み: Torsten 2022 年 10 月 16 日
p = sim()
p = 0.1330
5/36
ans = 0.1389
function p = sim()
N = 10^3;
k=0;
for i=1:N
p=randi(6,1,2);
if sum(p)==8
k=k+1;
end
end
p = k/N;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by