Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB: Please solve using a function file and a script file Write a function named flipUntil that takes one parameter, numHeads, repeatedly flips a coin

MATLAB: Please solve using a function file and a script file

Write a function named flipUntil that takes one parameter, numHeads, repeatedly flips a coin until a heads has been seen numHeads times, and returns the number of flips needed to get numHeads heads. You may assume that numHeads is a single non-negative integer.

The first line of your flipUntil function should be:

function numFlips = flipUntil(numHeads) 

To receive full credit, your flipUntil function must use a while loop.

If you run your flipUntil several times with the same value for the input parameter, you will find that you get different results each time. Suppose we consider one call to flipUntil to be a single trial.

Write a code fragment that asks the user for the number of heads and runs 2000 trials and then displays the average number of flips needed to get that number of heads. (Hint: you will need to use a for loop.) You may assume that the user always enters a single non-negative integer when prompted for the number of heads

Add code to your answer for part 1.b that plots the average number of flips vs the number of trials completed. (Hint: at the end of each trial, compute and save the current average, then plot the saved current averages after all the trials have been completed.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

What factors in Nooyis Five C model facilitate employee trust?

Answered: 1 week ago

Question

=+ Who do you think is right? Why?

Answered: 1 week ago