Categories &

Functions List

Function Reference: binopdf

statistics: y = binopdf (x, n, ps)

Binomial probability density function (PDF).

For each element of x, compute the probability density function (PDF) of the binomial distribution with parameters n and ps, where n is the number of trials and ps is the probability of success. The size of y is the common size of x, n, and ps. A scalar input functions as a constant matrix of the same size as the other inputs.

Matlab incompatibility: Octave’s binopdf does not allow complex input values. Matlab 2021b returns values for complex inputs despite the documentation indicates integer and real value inputs are required.

Further information about the binomial distribution can be found at https://en.wikipedia.org/wiki/Binomial_distribution

See also: binocdf, binoinv, binornd, binofit, binolike, binostat, binotest

Source Code: binopdf

Example: 1

 

 ## Plot various PDFs from the binomial distribution
 x = 0:40;
 y1 = binopdf (x, 20, 0.5);
 y2 = binopdf (x, 20, 0.7);
 y3 = binopdf (x, 40, 0.5);
 plot (x, y1, "*b", x, y2, "*g", x, y3, "*r")
 grid on
 ylim ([0, 0.25])
 legend ({"n = 20, ps = 0.5", "n = 20, ps = 0.7", ...
          "n = 40, ps = 0.5"}, "location", "northeast")
 title ("Binomial PDF")
 xlabel ("values in x (number of successes)")
 ylabel ("density")

                    
plotted figure