Write a Matlab code that will generate a random number which

Write a Matlab code that will generate a random number, which can take only two possible values H (representing a heads outcome in a random coin toss) and T (representing a tails in a random coin toss). Generate a sequence of toss outcomes of 10 random trials. Count how many times H and T are generated out of the 10 outcomes. How can you estimate the probability of H and T in this case? Repeat the experiment with a 1XY, 5XY and 1XYZ outcomes generated. Estimate the probabilities in each case. What do you notice? XYZ represent the last 3 digits of your student ID number Example: Assume Student ID 20101234 which corresponds to X=2, Y=3 and Z = 4.

Solution

num_outcomes =10; %number of times a coin is tossed
trials = 1:num_outcomes;
heads = 0;
t = rand(num_outcomes,1);

percent_h=zeros(size(t));

for i = trials % count number of heads

if (t(i) < 0.5)
heads = heads + 1;
end   
end
tails=num_outcomes-heads; %number of tails is equal to total number of outcomes minus total heads
probability_heads= (factorial(num_outcomes)/(factorial(heads)*factorial(num_outcomes-heads)))/1024; % calculate probability using binomial distribution
probability_tails=1-probability_heads;
display(heads)
display(tails)
display(probability_heads)
display(probability_tails)

For small p and large num_outcomes, the binomial distribution approaches symmetry. Here p is 0.5. When dealing with very large samples, it can become tedious to compute certain probabilities. In such cases, the normal distribution can be used to approximate the probabilities.

 Write a Matlab code that will generate a random number, which can take only two possible values H (representing a heads outcome in a random coin toss) and T (r

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site