www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ComputeGeometricDistributionIcdfExample.m
%% Compute Geometric Distribution icdf % % Copyright 2015 The MathWorks, Inc. %% % Suppose the probability of a five-year-old car battery not starting in % cold weather is 0.03. If we want no more than a ten percent chance that the % car does not start, what is the maximum number of days in a row % that we should try to start the car? %% % To solve, compute the inverse cdf of the geometric distribution. In this % example, a "success" means the car does not start, while a "failure" % means the car does start. The probability of success for each trial % _p_ equals 0.03, while the probability of observing _x_ failures in a row % before observing a success _y_ equals 0.1. y = 0.1; p = 0.03; x = geoinv(y,p) %% % The returned result indicates that if we start the car three % times, there is at least a ten percent chance that it will not start on one of % those tries. Therefore, if we want no greater than a ten percent chance that the % car will not start, we should only attempt to start it for a maximum % of two days in a row. %% % We can confirm this result by evaluating the cdf at values of _x_ equal % to 2 and 3, given the probability of success for each trial _p_ equal to % 0.03. y2 = geocdf(2,p) % cdf for x = 2 y3 = geocdf(3,p) % cdf for x = 3 %% % The returned results indicate an 8.7% chance of the car not starting if % we try two days in a row, and an 11.5% chance of not starting if we try % three days in a row.