Contenido principal

geopdf

Geometric probability density function

Description

y = geopdf(x,p) returns the probability density function (pdf) of the geometric distribution, evaluated at each value in x using the corresponding probabilities in p. The parameter p is the probability of success in any given trial, and x is the number of failures before the first success.

example

Examples

collapse all

Compute the probability density function (pdf) of the geometric distribution with a probability of success p=0.25, for integer values between 0 and 20.

x = 0:1:20;
p = 0.25;
y = geopdf(x,p);

Plot the pdf. Use blue circle markers.

plot(x,y,"o",MarkerFaceColor="b")
grid on
xlabel("x")
ylabel("y")

Figure contains an axes object. The axes object with xlabel x, ylabel y contains a line object which displays its values using only markers.

The plot indicates that there is approximately a 14% chance of experiencing exactly two failures before the first success.

Suppose you toss a fair coin repeatedly, and a success occurs when the coin lands with heads facing up. What is the probability of observing exactly three tails (failures) before tossing heads?

Determine the value of the probability density function (pdf) for the geometric distribution at x equal to 3. The probability of success (tossing heads) p in any given trial is 0.5.

x = 3;
p = 0.5;
y = geopdf(x,p)
y = 
0.0625

The returned value of y indicates that the probability of observing exactly three tails before tossing heads is 0.0625.

Input Arguments

collapse all

Values at which to evaluate the pdf, specified as a nonnegative integer scalar or an array of nonnegative integer scalars. x is the number of failures before the first success.

To evaluate the pdf at multiple values, specify x using an array. To evaluate the pdfs of multiple distributions, specify p using an array. If both input arguments x and p are arrays, then the array sizes must be the same. If only one of the input arguments is an array, then geopdf expands the scalar input into a constant array of the same size as the array input. Each element in y is the pdf value of the distribution specified by the corresponding element in p, evaluated at the corresponding element in x.

Data Types: single | double

Probability of success in any given trial, specified as a scalar or an array of scalars in the range [0,1].

To evaluate the pdf at multiple values, specify x using an array. To evaluate the pdfs of multiple distributions, specify p using an array. If both input arguments x and p are arrays, then the array sizes must be the same. If only one of the input arguments is an array, then geopdf expands the scalar input into a constant array of the same size as the array input. Each element in y is the pdf value of the distribution specified by the corresponding element in p, evaluated at the corresponding element in x.

Data Types: single | double

Output Arguments

collapse all

Geometric pdf values, returned as a scalar or an array of scalars in the range [0,1]. y is the same size as x and p after any necessary scalar expansion.

More About

collapse all

Alternative Functionality

  • geopdf is a function specific to the geometric distribution. Statistics and Machine Learning Toolbox™ also offers the generic function pdf, which supports various probability distributions. To use pdf, specify the probability distribution name and its parameters. Note that the distribution-specific function geopdf is faster than the generic function pdf.

  • Use the Probability Distribution Function Tool to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a