5410
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
|
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} {} poisspdf (@var{x}, @var{lambda}) |
5410
|
21 ## For each element of @var{x}, compute the probability density function |
|
22 ## (PDF) at @var{x} of the poisson distribution with parameter @var{lambda}. |
|
23 ## @end deftypefn |
|
24 |
5428
|
25 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410
|
26 ## Description: PDF of the Poisson distribution |
|
27 |
5411
|
28 function pdf = poisspdf (x, l) |
5410
|
29 |
|
30 if (nargin != 2) |
6046
|
31 print_usage (); |
5410
|
32 endif |
|
33 |
|
34 if (!isscalar (l)) |
|
35 [retval, x, l] = common_size (x, l); |
|
36 if (retval > 0) |
5411
|
37 error ("poisspdf: x and lambda must be of common size or scalar"); |
5410
|
38 endif |
|
39 endif |
|
40 |
|
41 pdf = zeros (size (x)); |
|
42 |
|
43 k = find (!(l > 0) | isnan (x)); |
|
44 if (any (k)) |
|
45 pdf(k) = NaN; |
|
46 endif |
|
47 |
|
48 k = find ((x >= 0) & (x < Inf) & (x == round (x)) & (l > 0)); |
|
49 if (any (k)) |
|
50 if (isscalar (l)) |
|
51 pdf(k) = exp (x(k) .* log (l) - l - gammaln (x(k) + 1)); |
|
52 else |
|
53 pdf(k) = exp (x(k) .* log (l(k)) - l(k) - gammaln (x(k) + 1)); |
|
54 endif |
|
55 endif |
|
56 |
|
57 endfunction |