IEN 310: MATLAB Assignment 1 Definitions of Probability 01. Recollect the first
ID: 3069181 • Letter: I
Question
IEN 310: MATLAB Assignment 1 Definitions of Probability 01. Recollect the first two definitions of probability that we have covered in class 1. Probability of an event is the relative frequency of occurrence of the event when a random experiment is repeated multiple times Probability of an event is the ratio of the count of the number of outcomes of interest and the total number of outcomes that are possible (assuming that all outcomes are equally likely to occur) 2. Now, our first task (using MATLAB) is to verify if the two definitions give the same answer; if yes, under what conditions and if no, then what are the conditions. So, find the probability of getting a. b. c. d. e. f. An outcome of a 5 when you roll a six sided dice An outcome of 3, 4, or 5 when you roll a six sided dice A head when you toss a fair coin Two heads when you toss two fair coins A sum of more than 9 when you roll two six sided dice An ace when you draw one card from a deck of 52 cards Proceed as follows: i. Define the Sample Space ii. Define the event of interest iii. Determine the probability of the event of interest using the enumeration process iv. Verify if the probability is the same as that obained using the relative frequency approach. For the relative frequency approach, assume that you are repeating the experiment 1000, 2000, ...10,000 number of times. Plot the graph of relative frequency of the outcome of interest (y axis) vs. the number of iterations. Submit a word documents with your group members names, the graphs for the problems in the assignment, as well as the Matlab code you wrote. Please write down you observations about the equivalence of (and differences in) the two definitions of probability v. Email ass gnment word document Please Note: You will need to take a printout of the assignment and hand it over in classExplanation / Answer
Answer:
i=1000:1000:10000;
pro=zeros(1,length(i));
% An outcome of a 5 when you roll a six sided dice.
for k=1:length(i)
n=0;
for j=1:i(k)
outcome=randi(6);
if outcome==5
n=1+n;
end
end
pro(k)=n/i(k);
end
figure
plot(i,pro)
title('Getting 5 Probability')
xlabel('Iterations Count')
ylabel('Probability')
grid on
% An outcome of 3,4 or 5 hen you roll a six sided dice.
for k=1:length(i)
n=0;
for j=1:i(k)
outcome=randi(6);
if outcome==5 || outcome ==3 ||outcome==4
n=1+n;
end
end
pro(k)=n/i(k);
end
figure
plot(i,pro)
title('Probability of Getting 3,4, or 5.')
xlabel('Iterations COunt')
ylabel('probability')
grid on
%A head when you toss a fair coin
for k=1:length(i)
n=0;
for j=1:i(k)
outcome=randi(2);
if outcome==1
n=1+n;
end
end
pro(k)=n/i(k);
end
figure
plot(i,pro)
title('Getting a head in a coin toss')
xlabel('Iterations Count')
ylabel('probability')
grid on
%Two heads when you toss two fair coins
for k=1:length(i)
n=0;
for j=1:i(k)
outcome1=randi(2,[1,2]);
if sum(outcome1)==4
n=1+n;
end
end
pro(k)=n/i(k);
end
figure
plot(i,pro)
title('Getting 2 heads in 2 coin toss')
xlabel('Iterations Count')
ylabel('probability')
grid on
%A sum of more than 9 when you roll two six sided dice
for k=1:length(i)
n=0;
for j=1:i(k)
outcome=randi(6,[1,2]);
if sum(outcome)>9
n=1+n;
end
end
pro(k)=n/i(k);
end
figure
plot(i,pro)
title('Getting a sum of more than 9 in a two dice roll')
xlabel('Iterations COunt')
ylabel('probability')
grid on
%AN ace when you draw one card from a deck of 52 cards
for k=1:length(i)
n=0;
for j=1:i(k)
outcome=randi(52);
if outcome==1 || outcome ==14 ||outcome==27||outcome==40
n=1+n;
end
end
pro(k)=n/i(k);
end
figure
plot(i,pro)
title('Probabiliy of Getting an ace from deck of 52 cards ')
xlabel('Iterations Count')
ylabel('probability')
grid on