Question

Do the following in MATLAB: trials = 100; flip = rand(trials,1); heads = (flip >= 0.5);...

Do the following in MATLAB:

trials = 100;

flip = rand(trials,1);

heads = (flip >= 0.5);

percentheads = sum(heads)/trials

a.We can use a random number generator to estimate probabilities that might otherwise be difficult to evaluate. Consider the probability of obtaining four heads on four flips. Generate four separate random experiments of 0s and 1s representing N trials each. (You can do this by generating an Nx4 random array rather than an Nx1 array as in #1.) Now look at the corresponding rows and determine what percentage of the time all four coin flips across a row are heads (all entries equal 1). Show how you do this in MATLAB. Report the percentage with N=10,000 and 100,000, and compare this to the expected percentage.

b.Suppose the coin is unfair and has a 45% probability of being heads. You want to test this coin by doing 100 coin flips. Modify your code from #1 so that the probability of heads is 0.45. If you repeat this 100-flip experiment over and over, the relative frequency should vary around 0.45. How likely is it that the result will show a fair coin by giving a relative frequency of 50% or higher? Calculate the expected percentage of times this would happen by doing this 100-flip experiment 1000 times and calculating the percentage of time the relative frequency in 100 flips is 50% or higher. Does 100 flips appear to be enough trials to reliably detect an unfair coin with a 45% probability of heads?

please answer these a and b, thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

%part a

N=10000;
flips=round(rand(N,4));
Fourheads=0;
for i=1:N
    if all(flips(i,:)==1)
        Fourheads=Fourheads+1;
    end
end
percentheads = sum(Fourheads)/N;

fprintf('N = %d Probability: %f ',N,percentheads)

===================================================

clear
percent50=0;
for i=1:1000
    N = 100;
    flip = rand(N,1);
    heads = (flip >= 0.55);
    percentheads = sum(heads)/N;
    if percentheads>=.5
        percent50=percent50+1;
    end
end
p=percent50/1000;
fprintf('Probability that relative frequency is higher than 50: %f ',p)

Add a comment
Know the answer?
Add Answer to:
Do the following in MATLAB: trials = 100; flip = rand(trials,1); heads = (flip >= 0.5);...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You flip the same coin 90 mores times (100 total flips). If half of the 90...

    You flip the same coin 90 mores times (100 total flips). If half of the 90 additional flips are heads (45 heads) and half are tails (45 tails), what is the empirical probability of getting a heads for this coin? (So there are the original 10 heads plus an additional 45 heads for a total of 55 heads in 100 flips) (You can give the answer as either a decimal or percent. Give the answer to two decimal places.)

  • You flip a coin 100 times. Let X= the number of heads in 100 flips. Assume...

    You flip a coin 100 times. Let X= the number of heads in 100 flips. Assume we don’t know the probability, p, the coin lands on heads (we don’t know its a fair coin). So, let Y be distributed uniformly on the interval [0,1]. Assume the value of Y = the probability that the coin lands on heads. So, we are given Y is uniformly distributed on [0,1] and X given Y=p is binomially distributed on (100,p). Find E(X) and...

  • Flip N coins using a random number generator, and count the observed number of heads. Repeat...

    Flip N coins using a random number generator, and count the observed number of heads. Repeat M times, and compute the average, max, min, and standard deviation for the observed numbers of heads. Tabulate results. Do this for at least N = {10, 100, 1000} but also higher if you can, and one value of M (at least 30 but 10^4 or more if you can). To flip a coin in Excel, for example, CEILING(RAND()-0.5,1) returns 0=tail and 1=head with...

  • Using R-studio 2. Consider an experiment where we flip a fair coin six times in a row, and i is the number of heads toss...

    Using R-studio 2. Consider an experiment where we flip a fair coin six times in a row, and i is the number of heads tossed:             a.         Calculate the probability mass function for i = 0. . . 6 using the equation from Ross section 2.8 for Binomial Random Variables             b.         Conduct a simulation of this experiment in R, with T trials of the experiment – pick several values of T from 10 to 10,000.             c.         Create a plot of the...

  • 1. For a given binomial distribution with n fixed trials and p, which is the probability...

    1. For a given binomial distribution with n fixed trials and p, which is the probability of success of each trial, the binomial distribution is skewed left if p=0.50 Select one: True or False 2. Consider a graph of a normal distribution with the mean μμ and standard deviation σσ. The graph will never cross the horizontal axis. This happens because the normal distribution is an exponential function. Select one: True or False 3. Suppose you flip a fair a...

  • 1a) Suppose you flip a weighted coin 19 times with probability of heads 0.55. Let X...

    1a) Suppose you flip a weighted coin 19 times with probability of heads 0.55. Let X equal the number of heads. What is the mean number of heads (to two decimal places)? 1b) Suppose we have weighted coin with probability of heads being 0.30. What is the probability of getting four heads in five flips, to 2 decimal places?    2) Suppose a particular stock follows the "random walk" model where on any given day there is a 0.02 chance that...

  • We will be using Matlab as the software tool for this lab project. 1.Explore and become...

    We will be using Matlab as the software tool for this lab project. 1.Explore and become familiar with the random number generators in Matlab such as “rand”, “randn”, and “randi” (in fact all software tools can only generate pseudo-random numbers). Notice that to randomize the generators the use of “rng” function is encouraged as the previous techniques are discouraged. 2. “Random walk” is one of the primary and relative simple random processes in which the process starts from a neutral...

  • Can anyone please answer these? It's python coding question focusing on random practice!! 1. Write a...

    Can anyone please answer these? It's python coding question focusing on random practice!! 1. Write a function biasedCoinFlip(p) to return a biased coin flip that returns ''heads'' with probability p and tails otherwise. For example, when p=0.5, this function will behave like the last. On the other hand, p=0.25 will mean that there is only one chance in four of getting the result of "heads". 2. Write a function randomCard() to randomly return a card in a standard deck(suits: diamonds,...

  • 1. Suppose that random variables X and Y are independent and have the following properties: E(X)...

    1. Suppose that random variables X and Y are independent and have the following properties: E(X) = 5, Var(X) = 2, E(Y ) = −2, E(Y 2) = 7. Compute the following. (a) E(X + Y ). (b) Var(2X − 3Y ) (c) E(X2 + 5) (d) The standard deviation of Y . 2. Consider the following data set: �x = {90, 88, 93, 87, 85, 95, 92} (a) Compute x¯. (b) Compute the standard deviation of this set. 3....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT