Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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/n

Explanation / 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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote