Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MATLAB PROGRAM PLEASE Assignment I. Create a function called bern.m that returns the probability of k successes in N trials of an independent experiment with
MATLAB PROGRAM PLEASE
Assignment I. Create a function called bern.m that returns the probability of k successes in N trials of an independent experiment with individual probability of p e Your function must accept three parameters: k, N and p . Your function must return the Bernoulli probability * Your function should include error checking. Check the help information for the MATLAB functions error and/or return. You should verify that k 20 and N> 0 and k S N etc; when there is a problem, you should notify the user of the issue and return to the calling function without calculating anything 2. Empirically test the validity of the Bernoli equation using your dice rolling function from the pre-lab assignment. This part of the lab doesn't need to be described in your report-this is just to learn the approach. Create and edit a script lab02.m to empirically test the Bernoulli equation and compare it to the theoretically predicted result. Assuming we want to examine the probability that out of N dice rolls, k times the dice value was in some certain range (e.g., the outcome that the die face is even). follow this strategy: Start by seeding your random number generator such that it generates a different random stream each time it executes based on the current clock (see RandStream or use rng 'shuffle or other methods). This should be done only once in your code and towards the very beginning of your main script lab02. m. Loop to call your dice function to roll the dice N times while keeping count of the number of times the die value was in the specified range (for our example, count the number of times the dice value was 2, 4 or 6). This is k for this trial. . Assign Success to this trial ifk rolls were in the desired range and Failure to this trial if k rls were not in the desired range * Run L trials of this experiment and count the number of successful trials. That is, repeat the experiment of olingthe die N times itself L times (where Lis a large e number; the larger the better computers are pretty fast so don't be shy) Compute the empirical determined probability of achieving k successes in N trials by computing the ratio of the number of tests in which k successes were achieved to the total number of tests L Compare to the theoretical result by calling your bern function. Format output to . the user to inform them of your empirically determined result as compared to your theoretically predicted result. Compute percent difference 3. Configure your lab02.m script to compare the theoretical and empirical results for the test cases enumerated below (assuming independent rolls of a fair die). Format your output to properly describe the experiment and the results a. In 5 out of 10 die rolls, the face value is even b. In 9 rolls, the face numbers 3 and 5 never occur c. In 30 rolls, there are at least 11 prime numbers (note is not prime) d. In 8 rolls, the die face is greater than 3 more often than not. Compare your re sults. Do the empirical and theoretical re sults agree? Why or why not? 4. 5. Do the numbers you obtain make sense? For example, the probability of obtaining an even-valued die face is p 0.5, yet is the probability of obtaining exactly 5 even rolls in 10 tries equal to 0.5? Explain your findingsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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