Mercurial > octave-nkf
comparison scripts/statistics/distributions/poissinv.m @ 11469:c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 09 Jan 2011 12:41:21 -0800 |
parents | 95c3e38098bf |
children | 1740012184f9 |
comparison
equal
deleted
inserted
replaced
11468:e1edf0ba3bcb | 11469:c776f063fefe |
---|---|
24 ## @end deftypefn | 24 ## @end deftypefn |
25 | 25 |
26 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> | 26 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
27 ## Description: Quantile function of the Poisson distribution | 27 ## Description: Quantile function of the Poisson distribution |
28 | 28 |
29 function inv = poissinv (x, l) | 29 function inv = poissinv (x, lambda) |
30 | 30 |
31 if (nargin != 2) | 31 if (nargin != 2) |
32 print_usage (); | 32 print_usage (); |
33 endif | 33 endif |
34 | 34 |
35 if (!isscalar (l)) | 35 if (!isscalar (lambda)) |
36 [retval, x, l] = common_size (x, l); | 36 [retval, x, lambda] = common_size (x, lambda); |
37 if (retval > 0) | 37 if (retval > 0) |
38 error ("poissinv: x and lambda must be of common size or scalar"); | 38 error ("poissinv: x and lambda must be of common size or scalar"); |
39 endif | 39 endif |
40 endif | 40 endif |
41 | 41 |
42 inv = zeros (size (x)); | 42 inv = zeros (size (x)); |
43 | 43 |
44 k = find ((x < 0) | (x > 1) | isnan (x) | !(l > 0)); | 44 k = find ((x < 0) | (x > 1) | isnan (x) | !(lambda > 0)); |
45 if (any (k)) | 45 if (any (k)) |
46 inv(k) = NaN; | 46 inv(k) = NaN; |
47 endif | 47 endif |
48 | 48 |
49 k = find ((x == 1) & (l > 0)); | 49 k = find ((x == 1) & (lambda > 0)); |
50 if (any (k)) | 50 if (any (k)) |
51 inv(k) = Inf; | 51 inv(k) = Inf; |
52 endif | 52 endif |
53 | 53 |
54 k = find ((x > 0) & (x < 1) & (l > 0)); | 54 k = find ((x > 0) & (x < 1) & (lambda > 0)); |
55 if (any (k)) | 55 if (any (k)) |
56 if (isscalar (l)) | 56 if (isscalar (lambda)) |
57 cdf = exp (-l) * ones (size (k)); | 57 cdf = exp (-lambda) * ones (size (k)); |
58 else | 58 else |
59 cdf = exp (-l(k)); | 59 cdf = exp (-lambda(k)); |
60 endif | 60 endif |
61 while (1) | 61 while (1) |
62 m = find (cdf < x(k)); | 62 m = find (cdf < x(k)); |
63 if (any (m)) | 63 if (any (m)) |
64 inv(k(m)) = inv(k(m)) + 1; | 64 inv(k(m)) = inv(k(m)) + 1; |
65 if (isscalar (l)) | 65 if (isscalar (lambda)) |
66 cdf(m) = cdf(m) + poisspdf (inv(k(m)), l); | 66 cdf(m) = cdf(m) + poisspdf (inv(k(m)), lambda); |
67 else | 67 else |
68 cdf(m) = cdf(m) + poisspdf (inv(k(m)), l(k(m))); | 68 cdf(m) = cdf(m) + poisspdf (inv(k(m)), lambda(k(m))); |
69 endif | 69 endif |
70 else | 70 else |
71 break; | 71 break; |
72 endif | 72 endif |
73 endwhile | 73 endwhile |