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{x} =} raylinv (@var{p}, @var{sigma})
18 ## Compute the quantile of the Rayleigh distribution. The quantile is the
19 ## inverse of the cumulative distribution function.
21 ## @subheading Arguments
25 ## @var{p} is the cumulative distribution. The elements of @var{p} must be
29 ## @var{sigma} is the parameter of the Rayleigh distribution. The elements
30 ## of @var{sigma} must be positive.
32 ## @var{p} and @var{sigma} must be of common size or one of them must be
35 ## @subheading Return values
39 ## @var{x} is the quantile of the Rayleigh distribution at each element of
40 ## @var{p} and corresponding parameter @var{sigma}.
43 ## @subheading Examples
49 ## x = raylinv (p, sigma)
53 ## x = raylinv (p, 0.5)
57 ## @subheading References
61 ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics
62 ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC,
66 ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic
67 ## Processes}. pages 104 and 148, McGraw-Hill, New York, second edition,
72 ## Author: Arno Onken <asnelt@asnelt.org>
73 ## Description: Quantile of the Rayleigh distribution
75 function x = raylinv (p, sigma)
82 if (! isempty (p) && ! ismatrix (p))
83 error ("raylinv: p must be a numeric matrix");
85 if (! isempty (sigma) && ! ismatrix (sigma))
86 error ("raylinv: sigma must be a numeric matrix");
89 if (! isscalar (p) || ! isscalar (sigma))
90 [retval, p, sigma] = common_size (p, sigma);
92 error ("raylinv: p and sigma must be of common size or scalar");
97 x = sqrt (-2 .* log (1 - p) .* sigma .^ 2);
104 # Continue argument check
105 k = find (! (p >= 0) | ! (p <= 1) | ! (sigma > 0));
115 %! x = raylinv (p, sigma);
116 %! expected_x = [0.0000, 0.9181, 2.0041, 3.3784, 5.0538, 7.0645];
117 %! assert (x, expected_x, 0.001);
121 %! x = raylinv (p, 0.5);
122 %! expected_x = [0.0000, 0.2295, 0.3340, 0.4223, 0.5054, 0.5887];
123 %! assert (x, expected_x, 0.001);