Please I need the full code for part D AND E only includes

Please I need the full code for part ( D AND E ) only includes all the codes written in the MATLAB, the results of running the code and your comments on the result. Using the Matlab code:

a. Convert the code that generates the random number (H,T) with equal probabilities into a function called myBernolli(p, S) that takes as an input the probability of success p and S is the outcome defined as success (either T or H) and returns the outcome of the trial (either T or H).

b. Test that your function is actually producing the success outcome with probability p by running the function in a loop of 1000 trials and counting how many times success is produced (it should be close to p*1000).

c. Write a Matlab function called myBinomial(n,p) that takes as an input the total number of trials n, the probability of success p and the outcome defined as success S and uses myBernolli() to return as an output the number of successes x.

d. Write a Matlab function called myGeometric() that takes as an input the probability of success p and the outcome defined as success S and uses myBernolli() to return as an output the number of trials till first success x.

e. Verify that myBinomial() and myGeometric() generates values that follows Binomial and Geometric Distributions by running each of them 5000 times in a loop and plotting a histogram of the random variable x generated from each.

Solution

Part d:

function [n] = mygeometric (p,s)
n = 0;
for i = 1:p
n = myBernoulli (p,s)
if (n~=s)
n = n+1;
end
n
end

Part e:

function [x] = myBinomial(n,p,s)
x=0;
for i = 1:5000
o = myBernoulli(p,s);
if (o == s)
x = x+1;

function [n] = mygeometric (p,s)
n = 0;
for i = 1:p
n = myBernoulli (p,s)
if (n~=s)
n = n+1;
end
n
h = histogram(x, success)
end
end
end

Please I need the full code for part ( D AND E ) only includes all the codes written in the MATLAB, the results of running the code and your comments on the res

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site