Geometric PDF
y = distfun_geopdf(X,Pr)
a 1x1 or nxm matrix of doubles, the number of Bernoulli trials after which first success occurs . X belongs to the set {0,1,2,3,.....}
a 1x1 or nxm matrix of doubles, the probability of success in a Bernoulli trial
a nxm matrix of doubles, the Probability density.
Computes the probability distribution function of the Geometric distribution function.
Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.
The function definition is:
Note : X belongs to the set {0,1,2,3,...}. This choice is compatible with Matlab and R.
// Test X scalar , Pr scalar computed = distfun_geopdf(3,0.5) expected = 0.0625; // Test with X expanded, with Pr scalar computed = distfun_geopdf([2 3],0.1) expected = [0.081 0.0729]; //Test with X scalar, Pr expanded computed = distfun_geopdf(3,[0.2 0.4]) expected = [0.1024 0.0864]; //Test with both arguments expanded computed = distfun_geopdf([3 4 8],[0.5 0.8 0.2]) expected = [0.0625 0.00128 0.033554432]; // Plot the function // Note that geometric distribution is discrete in nature // i.e it gives output only at discrete values of X = {0,1,2,3,.....} scf(); X = 0:10; y = distfun_geopdf(X,0.2); plot(X,y,"ro-"); y1 = distfun_geopdf(X,0.5); plot(X,y1,"go-"); y2 = distfun_geopdf(X,0.8); plot(X,y2,"bo-"); xtitle("Geometric PDF","x","P(X=x)"); legend(["Pr=0.2","Pr=0.5","Pr=0.8"]); | ![]() | ![]() |
http://en.wikipedia.org/wiki/Geometric_distribution