function cdf = discrete_cdf (x, v, p)
% discrete_pdf (x, v, p)
% For each element of x, compute the cumulative probability density 
% function (CDF) at x of a univariate discrete distribution which 
% assumes the values in v with probabilities p.

if (nargin ~= 3)
  print_usage ();
end%if

if (~isvector (v))
  error ('discrete_pdf: V must be a vector');
elseif (any (isnan (v)))
  error ('discrete_cdf: V must not have any NaN elements');
elseif (~isvector (p) || (length (p) ~= length (v)))
  error ('discrete_cdf: P must be a vector with length (V) elements');
elseif (~(all (p >= 0) && any (p)))
  error ('discrete_cdf: P must be a nonzero, non-negative vector');
end%if
 
cdf = cumsum(discrete_pdf(x,v,p));

end%function

%% Copyright (C) 2012 Rik Wehbring
%% Copyright (C) 2010-2015 David Bateman
%%
%% This code is based on code provided by Octave.
%% Addapted to work with Matlab too, by Andreas Stahel (2016)
%%
%% Octave is free software; you can redistribute it and/or modify it
%% under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 3 of the License, or (at
%% your option) any later version.
%%
%% Octave is distributed in the hope that it will be useful, but
%% WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%% General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with Octave; see the file COPYING.  If not, see
%% <http://www.gnu.org/licenses/>.
