function cdf = binomial_cdf ( x, a, b )
%*****************************************************************************80
%
%% binomial_cdf() evaluates the Binomial CDF.
%
% Discussion:
%
% CDF(X)(A,B) is the probability of at most X successes in A trials,
% given that the probability of success on a single trial is B.
%
% A sequence of trials with fixed probability of success on
% any trial is known as a sequence of Bernoulli trials.
%
% Licensing:
%
% This code is distributed under the MIT license.
%
% Modified:
%
% 11 January 2021
%
% Author:
%
% John Burkardt
%
% Input:
%
% integer X, the desired number of successes.
% 0 <= X <= A.
%
% integer A, the number of trials.
% 1 <= A.
%
% real B, the probability of success on one trial.
% 0.0 <= B <= 1.0.
%
% Output:
%
% real CDF, the value of the CDF.
%
if ( x < 0 )
cdf = 0.0;
elseif ( a <= x )
cdf = 1.0;
elseif ( b == 0.0 )
cdf = 1.0;
elseif ( b == 1.0 )
cdf = 0.0;
else
cdf = 0.0;
for j = 0 : x
cnk = nchoosek ( a, j );
pr = cnk * b ^ j * ( 1.0 - b ) ^ ( a - j );
cdf = cdf + pr;
end
end
return
end