The binomial distribution is given by the following function

The binomial distribution is given by the following function of x: f(x) = n!/x! (n - x)! p^x (1 - p)^n - x where n is the number of trials (in an experiment like the flip of a coin for instance), x is the number of successes, and p is the probability of success in a single trial. Write a MATLAB function to plot the binomial distribution (as a function of x) for user specified values of n and p. You can use the built-in MATLAB factorial function for the factorial.

Solution

function y= bdf(x,n,p)

y=zeros(size(x));
for m=1:length(x)
xx=x(m);
fact_n=factorial(n);
fact_x=factorial(xx);
fact_nx=factorial(n-xx);
y(m)=(fact_n*(p^xx)*((1-p)^(n-xx)))/...
(fact_x*fact_nx);
  
end

plot(x,y)

end

 The binomial distribution is given by the following function of x: f(x) = n!/x! (n - x)! p^x (1 - p)^n - x where n is the number of trials (in an experiment li

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site