1 ## Copyright (C) 2006, 2007 Arno Onken <asnelt@asnelt.org>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{p} =} raylcdf (@var{x}, @var{sigma})
18 ## Compute the cumulative distribution function of the Rayleigh
21 ## @subheading Arguments
25 ## @var{x} is the support. The elements of @var{x} must be non-negative.
28 ## @var{sigma} is the parameter of the Rayleigh distribution. The elements
29 ## of @var{sigma} must be positive.
31 ## @var{x} and @var{sigma} must be of common size or one of them must be
34 ## @subheading Return values
38 ## @var{p} is the cumulative distribution of the Rayleigh distribution at
39 ## each element of @var{x} and corresponding parameter @var{sigma}.
42 ## @subheading Examples
48 ## p = raylcdf (x, sigma)
52 ## p = raylcdf (x, 0.5)
56 ## @subheading References
60 ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics
61 ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC,
65 ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic
66 ## Processes}. pages 104 and 148, McGraw-Hill, New York, second edition,
71 ## Author: Arno Onken <asnelt@asnelt.org>
72 ## Description: CDF of the Rayleigh distribution
74 function p = raylcdf (x, sigma)
81 if (! isempty (x) && ! ismatrix (x))
82 error ("raylcdf: x must be a numeric matrix");
84 if (! isempty (sigma) && ! ismatrix (sigma))
85 error ("raylcdf: sigma must be a numeric matrix");
88 if (! isscalar (x) || ! isscalar (sigma))
89 [retval, x, sigma] = common_size (x, sigma);
91 error ("raylcdf: x and sigma must be of common size or scalar");
96 p = 1 - exp ((-x .^ 2) ./ (2 * sigma .^ 2));
98 # Continue argument check
99 k = find (! (x >= 0) | ! (x < Inf) | ! (sigma > 0));
109 %! p = raylcdf (x, sigma);
110 %! expected_p = [0.0000, 0.0308, 0.0540, 0.0679, 0.0769, 0.0831];
111 %! assert (p, expected_p, 0.001);
115 %! p = raylcdf (x, 0.5);
116 %! expected_p = [0.0000, 0.3935, 0.8647, 0.9889, 0.9997, 1.0000];
117 %! assert (p, expected_p, 0.001);