how to calculate the probability of a geometric distribution in matlab

To calculate the probability of a geometric distribution in Matlab, you can use the built-in functions geopdf and geocdf.

geopdf calculates the probability mass function (PMF) of a geometric distribution. The syntax is as follows:

p = geopdf(x, p)
17 chars
2 lines

where x is the number of trials until the first success, and p is the probability of success on each trial.

geocdf calculates the cumulative distribution function (CDF) of a geometric distribution. The syntax is as follows:

p = geocdf(x, p)
17 chars
2 lines

where x is the number of trials until the first success, and p is the probability of success on each trial.

Here's an example code snippet that calculates the PMF and CDF of a geometric distribution with a success probability of 0.2:

p = 0.2; % success probability
x = 0:10; % range of trials to consider
pmf = geopdf(x, p); % calculate PMF
cdf = geocdf(x, p); % calculate CDF
plot(x, pmf, 'bo-', x, cdf, 'rx-') % plot PMF and CDF
legend('PMF', 'CDF') % add legend
231 chars
7 lines

This code snippet will produce a plot showing the PMF and CDF of a geometric distribution with a success probability of 0.2.

gistlibby LogSnag