Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Matlab given a group of Npeople people, what is the probability that at least two of them w birthdays on the same day? The goal
Matlab
given a group of Npeople people, what is the probability that at least two of them w birthdays on the same day? The goal of this program, birthday.m is to calculate 9. Solve the birthday problem by Monte Carlo simulation. The question to be answ will have probability for Naorpl n the range I2. nPeopleMaxl Break the problem up into three programs: the main program birthday.m, a funets nRowswith Match(M), and another function vectorHas Match(v) The function hasMatch-vectorHasMatch(v) ta value of true if the vector has as least one pair of identical elements. (Hint: Use the LAB function sort to first sort the vector, and then search it for adjoining elements that are identical.) io kes a vector argument and re returns a MAT The function m-nRowswithMatch(M) takes a matrix as an argument and returns an inte- ger that is the number of rows of the matrix with at least one pair of identical elements. (Hint Use the MATLAB function size to get the number of rows and columns of the matrix, then loop through each row and call vectorHasMatch to determine if that row has a match) The main program birthday should use rand to set up an N sets N people array of integers between 1 and 365. The number of sets (once the program is debugged) shouldbe larger than 5000. For each such array, find nM, the number of rows with at least one match. The probability of a birthday match is then just nM/Nsets. Tabulate that probability for the various values of Npeople in the given range and plot the results. Try plotting using the bar command. given a group of Npeople people, what is the probability that at least two of them w birthdays on the same day? The goal of this program, birthday.m is to calculate 9. Solve the birthday problem by Monte Carlo simulation. The question to be answ will have probability for Naorpl n the range I2. nPeopleMaxl Break the problem up into three programs: the main program birthday.m, a funets nRowswith Match(M), and another function vectorHas Match(v) The function hasMatch-vectorHasMatch(v) ta value of true if the vector has as least one pair of identical elements. (Hint: Use the LAB function sort to first sort the vector, and then search it for adjoining elements that are identical.) io kes a vector argument and re returns a MAT The function m-nRowswithMatch(M) takes a matrix as an argument and returns an inte- ger that is the number of rows of the matrix with at least one pair of identical elements. (Hint Use the MATLAB function size to get the number of rows and columns of the matrix, then loop through each row and call vectorHasMatch to determine if that row has a match) The main program birthday should use rand to set up an N sets N people array of integers between 1 and 365. The number of sets (once the program is debugged) shouldbe larger than 5000. For each such array, find nM, the number of rows with at least one match. The probability of a birthday match is then just nM/Nsets. Tabulate that probability for the various values of Npeople in the given range and plot the results. Try plotting using the bar commandStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started