Binomial probability density function
computes the binomial probability density function at each of the values in
y = binopdf(
x using the corresponding number of trials in
and probability of success for each trial in
p can be
vectors, matrices, or multidimensional arrays of the same size. Alternatively, one or more
arguments can be scalars. The
binopdf function expands scalar inputs to
constant arrays with the same dimensions as the other inputs.
Compute and Plot Binomial Probability Density Function
Compute and plot the binomial probability density function for the specified range of integer values, number of trials, and probability of success for each trial.
In one day, a quality assurance inspector tests 200 circuit boards. 2% of the boards have defects. Compute the probability that the inspector will find no defective boards on any given day.
ans = 0.0176
Compute the binomial probability density function values at each value from 0 to 200. These values correspond to the probabilities that the inspector will find 0, 1, 2, ..., 200 defective boards on any given day.
defects = 0:200; y = binopdf(defects,200,.02);
Plot the resulting binomial probability values.
Compute the most likely number of defective boards that the inspector finds in a day.
[x,i] = max(y); defects(i)
ans = 4
x — Values at which to evaluate binomial pdf
integer from interval
[0 n] | array of integers from interval
Values at which to evaluate the binomial pdf, specified as an integer or an array of
integers. All values of
x must belong to the interval
n is the number of trials.
n — Number of trials
positive integer | array of positive integers
Number of trials, specified as a positive integer or an array of positive integers.
p — Probability of success for each trial
scalar value from interval
[0 1] | array of scalar values from interval
Probability of success for each trial, specified as a scalar value or an array of
scalar values. All values of
p must belong to the interval
y — Binomial pdf values
scalar value | array of scalar values
Binomial pdf values, returned as a scalar value or array of scalar values. Each
y is the binomial pdf value of the distribution evaluated
at the corresponding element in
Binomial Probability Density Function
The binomial probability density function lets you obtain the probability of observing exactly x successes in n trials, with the probability p of success on a single trial.
The binomial probability density function for a given value x and given pair of parameters n and p is
where q = 1 – p. The resulting value y is the probability of observing exactly x successes in n independent trials, where the probability of success in any given trial is p. The indicator function I(0,1,...,n)(x) ensures that x only adopts values of 0, 1, ..., n.
binopdfis a function specific to binomial distribution. Statistics and Machine Learning Toolbox™ also offers the generic function
BinomialDistributionprobability distribution object and pass the object as an input argument. Note that the distribution-specific function
binopdfis faster than the generic function
Use the Probability Distribution Function app to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Introduced before R2006a