Counting Probability of Dice Tossing One Two and Three in Matlab
Counting Probability of Dice Tossing One Two and Three in Matlab
Well, this is article was written to accomodate my curiosity to find the probability of tossing one to three dices simultanously. There is no need further explanation about how it works or probability theory. I believe one will understand in short times. Take a look at the codes below including the results. One and two dices Codes
clear; clc; A=[1,2,3,4,5,6]; PA=ones(1,6); % jumlah kemunculan untuk 1 buah dadu figure(1) stem(A,PA) axis([1 6 0 2]); xlabel('Sisi Yang Muncul'); ylabel('Jumlah Kemunculan'); title('Distribusi Peluang Kemunculan Pada 1 Dadu'); % jumlah kemunculan untuk 2 buah dadu for n=0:5 B(n+1,:)=A+A(6-n); end B = sort(reshape(B,1,36)); k=1; m=1; while k<=36 jum=length(find(B==m)); jumP(m,:)=jum; m=m+1; k=k+jum; end figure(2) stem(1:12,jumP); axis([1 12 0 7]); xlabel('Penjumlahan Sisi-sisi Yang Muncul'); ylabel('Jumlah Kemunculan'); title('Distribusi Peluang Kemunculan Pada 2 Dadu');
Page 1
[sharing is caring]
result
Three dices
Page 2
[sharing is caring]
Codes
clear; clc; A=[1,2,3,4,5,6]; % jumlah kemunculan untuk 3 buah dadu k=1; m=1; while k<=36 for n=1:6 for l=1:6 B(n,l)=A(m)+A(n)+A(l); end end C(k:k+5,:)=B; k=k+6; m=m+1; end kl=1; ml=1; while kl<=216 jum=length(find(C==ml)); jumP(ml,1)=jum; ml=ml+1; kl=kl+jum; end stem(1:18,jumP) axis([2 20 0 30]); xlabel('Penjumlahan Sisi-sisi Yang Muncul'); ylabel('Jumlah Kemunculan'); title('Distribusi Peluang Kemunculan Pada 3 Dadu');
Page 3
[sharing is caring]
result
Page 4