www.gusucode.com > stats 源码程序 matlab案例代码 > stats/PDFAndCDFForGeometricDistributionExample.m

    %% PDF and CDF for Geometric Distribution

% Copyright 2015 The MathWorks, Inc.


%% Compute and Plot PDF
x = [1:10];
y1 = geopdf(x,0.1);   % For p = 0.1
y2 = geopdf(x,0.25);  % For p = 0.25
y3 = geopdf(x,0.75);  % For p = 0.75

figure;
plot(x,y1,'kd')
hold on
plot(x,y2,'ro')
plot(x,y3,'b+')
legend({'p = 0.1','p = 0.25','p = 0.75'})
hold off


%% Compute and Plot CDF
x = [1:10];
y1 = geocdf(x,0.1);   % For p = 0.1
y2 = geocdf(x,0.25);  % For p = 0.25
y3 = geocdf(x,0.75);  % For p = 0.75

figure;
plot(x,y1,'kd')
hold on
plot(x,y2,'ro')
plot(x,y3,'b+')
legend({'p = 0.1','p = 0.25','p = 0.75'})
hold off

%% Generate random number
p = 0.1;
r = geornd(p)

%% Generate inverse cdf
y = 0.1;
p = 0.03;
x = geoinv(y,p)

%% Compute mean and variance
p = 0.25;
[m,v] = geostat(p)