1 ## Copyright (C) 2012 Rik Wehbring
2 ## Copyright (C) 1995-2012 Kurt Hornik
4 ## This file is part of Octave.
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
21 ## @deftypefn {Function File} {} kolmogorov_smirnov_cdf (@var{x}, @var{tol})
22 ## Return the cumulative distribution function (CDF) at @var{x} of the
23 ## Kolmogorov-Smirnov distribution,
25 ## $$ Q(x) = \sum_{k=-\infty}^\infty (-1)^k \exp (-2 k^2 x^2) $$
32 ## Q(x) = SUM (-1)^k exp (-2 k^2 x^2)
41 ## The optional parameter @var{tol} specifies the precision up to which
42 ## the series should be evaluated; the default is @var{tol} = @code{eps}.
45 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
46 ## Description: CDF of the Kolmogorov-Smirnov distribution
48 function cdf = kolmogorov_smirnov_cdf (x, tol)
50 if (nargin < 1 || nargin > 2)
55 if (isa (x, "single"))
61 if (! (isscalar (tol) && (tol > 0)))
62 error ("kolmogorov_smirnov_cdf: TOL must be a positive scalar");
67 error ("kolmogorov_smirnov_cdf: X must not be empty");
70 cdf = zeros (size (x));
74 if (columns (ind) < rows (ind))
79 K = ceil (sqrt (- log (tol) / 2) / min (y));
81 A = exp (- 2 * k.^2 * y.^2);
82 odd = find (rem (k, 2) == 1);
84 cdf(ind) = 1 + 2 * sum (A);
90 %% Test input validation
91 %!error kolmogorov_smirnov_cdf ()
92 %!error kolmogorov_smirnov_cdf (1,2,3)
93 %!error kolmogorov_smirnov_cdf (1, ones(2))
94 %!error kolmogorov_smirnov_cdf ([], 1)