DicePlotと呼ばれる関数は、10個のサイコロを5000回振るのをシミュレートします。
この関数は、各ロールの10個のサイコロの値の合計を計算します。これは1⇥5000のベクトルになり、ビンのエッジが選択された相対度数ヒストグラムをプロットします。ヒストグラムの各ビンは、合計の可能な値を表します。サイコロの。
ダイス値の1⇥5000の合計の平均と標準偏差が計算され、相対頻度ヒストグラムの上に正規分布の確率密度関数(平均と標準偏差が計算された)がプロットされます。
以下はこれまでの私のコードです-私は何が間違っているのですか?グラフは表示されますが、上部の余分な赤い線は表示されませんか?私はこのような答えを見ましたが、ガウス関数のようなものをプロットすることはないと思います。
% function[]= DicePlot()
for roll=1:5000
diceValues = randi(6,[1, 10]);
SumDice(roll) = sum(diceValues);
end
distr=zeros(1,6*10);
for i = 10:60
distr(i)=histc(SumDice,i);
end
bar(distr,1)
Y = normpdf(X)
xlabel('sum of dice values')
ylabel('relative frequency')
title(['NumDice = ',num2str(NumDice),' , NumRolls = ',num2str(NumRolls)]);
end
それは次のように見えるはずです
しかし、それはのように見えます