Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB: The following program simulates a coin toss: % this program simulates a coin toss p = 0.5; % the probability of heads is 0.5

MATLAB:

  1. The following program simulates a coin toss:

% this program simulates a coin toss

p = 0.5; % the probability of heads is 0.5

r = rand; % generate a random number from 0 to 1

if r < p % this should happen about 50% of the time

fprintf(H)

else % if its not Heads, it must be Tails

fprintf(T)

end

fprintf( ) % newline after the simulation

  1. Type the program above into an m-file, and then run it several times. Does it appear to generate random results?

  2. Now create a for loop around everything except the first and last lines of code. Have the loop perform Ntoss iterations, and start out with Ntoss = 20. Run the program several times and observe the results. Do you get exactly 10 Heads every time?

  3. Now replace the fprintf statements with counters for Heads and Tails (remember to initialize them before the loop). Calculate and output the percentage of Heads after the loop is completed.

After you verify that your program executes successfully, try running it repeatedly with Ntoss = 50. Then change Ntoss to 500 and run it several times again. Repeat with Ntoss = 5000 and then 50000. What happens to the percentage of Heads as Ntoss increases?

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

More Books

Students also viewed these Databases questions

Question

Discuss all branches of science

Answered: 1 week ago

Question

The company has fair promotion/advancement policies.

Answered: 1 week ago