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{y} =} raylpdf (@var{x}, @var{sigma})
18 ## Compute the probability density function of the Rayleigh distribution.
20 ## @subheading Arguments
24 ## @var{x} is the support. The elements of @var{x} must be non-negative.
27 ## @var{sigma} is the parameter of the Rayleigh distribution. The elements
28 ## of @var{sigma} must be positive.
30 ## @var{x} and @var{sigma} must be of common size or one of them must be
33 ## @subheading Return values
37 ## @var{y} is the probability density of the Rayleigh distribution at each
38 ## element of @var{x} and corresponding parameter @var{sigma}.
41 ## @subheading Examples
47 ## y = raylpdf (x, sigma)
51 ## y = raylpdf (x, 0.5)
55 ## @subheading References
59 ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics
60 ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC,
64 ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic
65 ## Processes}. pages 104 and 148, McGraw-Hill, New York, second edition,
70 ## Author: Arno Onken <asnelt@asnelt.org>
71 ## Description: PDF of the Rayleigh distribution
73 function y = raylpdf (x, sigma)
80 if (! isempty (x) && ! ismatrix (x))
81 error ("raylpdf: x must be a numeric matrix");
83 if (! isempty (sigma) && ! ismatrix (sigma))
84 error ("raylpdf: sigma must be a numeric matrix");
87 if (! isscalar (x) || ! isscalar (sigma))
88 [retval, x, sigma] = common_size (x, sigma);
90 error ("raylpdf: x and sigma must be of common size or scalar");
95 y = x .* exp ((-x .^ 2) ./ (2 .* sigma .^ 2)) ./ (sigma .^ 2);
97 # Continue argument check
98 k = find (! (x >= 0) | ! (x < Inf) | ! (sigma > 0));
108 %! y = raylpdf (x, sigma);
109 %! expected_y = [0.0000, 0.1212, 0.1051, 0.0874, 0.0738, 0.0637];
110 %! assert (y, expected_y, 0.001);
114 %! y = raylpdf (x, 0.5);
115 %! expected_y = [0.0000, 1.2131, 0.5413, 0.0667, 0.0027, 0.0000];
116 %! assert (y, expected_y, 0.001);