Mercurial > hg > octave-nkf
annotate scripts/statistics/distributions/geoinv.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 1740012184f9 |
children | 19b9f17d22af |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Kurt Hornik |
5410 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5410 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5410 | 18 |
19 ## -*- texinfo -*- | |
5411 | 20 ## @deftypefn {Function File} {} geoinv (@var{x}, @var{p}) |
5410 | 21 ## For each element of @var{x}, compute the quantile at @var{x} of the |
22 ## geometric distribution with parameter @var{p}. | |
23 ## @end deftypefn | |
24 | |
5428 | 25 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 26 ## Description: Quantile function of the geometric distribution |
27 | |
5411 | 28 function inv = geoinv (x, p) |
5410 | 29 |
30 if (nargin != 2) | |
6046 | 31 print_usage (); |
5410 | 32 endif |
33 | |
34 if (!isscalar (x) && !isscalar (p)) | |
35 [retval, x, p] = common_size (x, p); | |
36 if (retval > 0) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
37 error ("geoinv: X and P must be of common size or scalar"); |
5410 | 38 endif |
39 endif | |
40 | |
41 inv = zeros (size (x)); | |
42 | |
43 k = find (!(x >= 0) | !(x <= 1) | !(p >= 0) | !(p <= 1)); | |
44 if (any (k)) | |
45 inv(k) = NaN; | |
46 endif | |
47 | |
48 k = find ((x == 1) & (p >= 0) & (p <= 1)); | |
49 if (any (k)) | |
50 inv(k) = Inf; | |
51 endif | |
52 | |
53 k = find ((x > 0) & (x < 1) & (p > 0) & (p <= 1)); | |
54 if (any (k)) | |
55 if (isscalar (x)) | |
56 inv(k) = max (ceil (log (1 - x) ./ log (1 - p(k))) - 1, 0); | |
57 elseif (isscalar (p)) | |
58 inv(k) = max (ceil (log (1 - x(k)) / log (1 - p)) - 1, 0); | |
59 else | |
60 inv(k) = max (ceil (log (1 - x(k)) ./ log (1 - p(k))) - 1, 0); | |
61 endif | |
62 endif | |
63 | |
64 endfunction |