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{m}, @var{v}] =} raylstat (@var{sigma})
18 ## Compute mean and variance of the Rayleigh distribution.
20 ## @subheading Arguments
24 ## @var{sigma} is the parameter of the Rayleigh distribution. The elements
25 ## of @var{sigma} must be positive.
28 ## @subheading Return values
32 ## @var{m} is the mean of the Rayleigh distribution.
35 ## @var{v} is the variance of the Rayleigh distribution.
38 ## @subheading Example
43 ## [m, v] = raylstat (sigma)
47 ## @subheading References
51 ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics
52 ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC,
56 ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic
57 ## Processes}. McGraw-Hill, New York, second edition, 1984.
61 ## Author: Arno Onken <asnelt@asnelt.org>
62 ## Description: Moments of the Rayleigh distribution
64 function [m, v] = raylstat (sigma)
71 if (! isempty (sigma) && ! ismatrix (sigma))
72 error ("raylstat: sigma must be a numeric matrix");
76 m = sigma .* sqrt (pi ./ 2);
77 v = (2 - pi ./ 2) .* sigma .^ 2;
79 # Continue argument check
80 k = find (! (sigma > 0));
90 %! [m, v] = raylstat (sigma);
91 %! expected_m = [1.2533, 2.5066, 3.7599, 5.0133, 6.2666, 7.5199];
92 %! expected_v = [0.4292, 1.7168, 3.8628, 6.8673, 10.7301, 15.4513];
93 %! assert (m, expected_m, 0.001);
94 %! assert (v, expected_v, 0.001);