In Matlab, simulate n = 100,000 independent trials of the following experiment.
ID: 2267987 • Letter: I
Question
In Matlab, simulate n = 100,000 independent trials of the following experiment. Using the Matlab command randi. choose with replacement N = 23 random numbers from 1 to 365 and determine whether there is a repetition. Then compute the ratio of the number of trials in which a repetition has occurred to the total number n of trials. How well does this number compare with what you obtained analytically in the second problem? 4. Hint: The basic structure of the program can be as follows. n-100000; %This sets the number of trials of the experiment N-23; %This sets the number of students in the class x=0; %This initializes a variable that counts the no. of times %a birthday coincidence occurs for i-1 n %Sample N days out of 365 with replacement. %Determine if there is a coincidence in your sampled set of dates %If there is a coincidence, update the value of x, otherwise, % keep x unchanged end prob x/nExplanation / Answer
Program to complete the task:
clc;
close all;
clear all;
n=10000;%number of iterations
x = 0;%initaialising number of repitions to zero
for n =1 : 10000
%Creating random sequence
randSeq = randi([1,365],23,1);
%Finding repetitions by sorting and equatinf diffence of successive
%elements to zero
randSort = sort(randSeq);
for i = 2:length(randSort)
if(randSort(i)-randSort(i-1) == 0)
x = x+1;
break;
end
end
end
prob =x/n
Output will dispaly the value of probability
prob =
0.4996
After running the program several times it is observed that the probability is always near to 0.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.