Coin (Final) 001

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

% START %

% 50 SAMPLES %
for loop = 1:50;
a = rand(1,3);
% for 3 tosses %
b = a*100;
c = round(b);
d = rem(c,2);
head = sum(d);
tail = 3 - head;
var(loop) = head - (2*tail); % formula given %
if var(1, loop) == 3
y1(loop) = 0.125;
elseif var(1, loop) == -3
y1(loop) = 0.125;
else
y1(loop) = 0.375;
end
end
x1 = 1:50;
% 100 SAMPLES %
for loop2 = 1:100;
a2 = rand(1,3);
% for 3 tosses %
b2 = a2*100;
c2 = round(b2);
d2 = rem(c2,2);
head2 = sum(d2);
tail2 = 3 - head2;
var2(loop2) = head2 - (2*tail2); % formula given %
if var2(1, loop2) == 3
y2(loop2) = 0.125;
elseif var2(1, loop2) == -3
y2(loop2) = 0.125;
else
y2(loop2) = 0.375;
end
end
x2 = 1:100;
% 500 SAMPLES %
for loop3 = 1:500;
a3 = rand(1,3);
% for 3 tosses %
b3 = a3*100;
c3 = round(b3);
d3 = rem(c3,2);
head3 = sum(d3);
tail3 = 3 - head3;
var3(loop3) = head3 - (2*tail3); % formula given %
if var3(1, loop3) == 3
y3(loop3) = 0.125;
elseif var3(1, loop3) == -3
y3(loop3) = 0.125;
else
y3(loop3) = 0.375;
end
end
x3 = 1:500;
% 1000 SAMPLES %

for loop4 = 1:1000;


a4 = rand(1,3);
% for 3 tosses %
b4 = a4*100;
c4 = round(b4);
d4 = rem(c4,2);
head4 = sum(d4);
tail4 = 3 - head4;
var4(loop4) = head4 - (2*tail4); % formula given %
if var4(1, loop4) == 3
y4(loop4) = 0.125;
elseif var4(1, loop4) == -3
y4(loop4) = 0.125;
else
y4(loop4) = 0.375;
end
end
x4 = 1:1000;
% SUBPLOT %
figure(1);
subplot(2,2,1); plot(x1,y1)
title('50 Trials')
xlabel('Number of Trials')
ylabel('Probability')
subplot(2,2,2); plot(x2,y2)
title('100 Trials')
xlabel('Number of Trials')
ylabel('Probability')
subplot(2,2,3); plot(x3,y3)
title('500 Trials')
xlabel('Number of Trials')
ylabel('Probability')
subplot(2,2,4); plot(x4,y4)
title('1000 Trials')
xlabel('Number of Trials')
ylabel('Probability')
figure(2);
subplot(2,2,1); hist(var, -6:3)
title('50 Trials')
xlabel('Random Variable')
ylabel('Probability')
subplot(2,2,2); hist(var2, -6:3)
title('100 Trials')
xlabel('Random Variable')
ylabel('Probability')
subplot(2,2,3); hist(var3, -6:3)
title('500 Trials')
xlabel('Random Variable')
ylabel('Probability')
subplot(2,2,4); hist(var4, -6:3)
title('1000 Trials')
xlabel('Random Variable')
ylabel('Probability')

You might also like