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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
5411
|
21 ## @deftypefn {Function File} {} exppdf (@var{x}, @var{lambda}) |
5410
|
22 ## For each element of @var{x}, compute the probability density function |
|
23 ## (PDF) of the exponential distribution with parameter @var{lambda}. |
|
24 ## @end deftypefn |
|
25 |
|
26 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
27 ## Description: PDF of the exponential distribution |
|
28 |
5411
|
29 function pdf = exppdf (x, l) |
5410
|
30 |
|
31 if (nargin != 2) |
5411
|
32 usage ("exppdf (x, lambda)"); |
5410
|
33 endif |
|
34 |
|
35 if (!isscalar (x) && !isscalar(l)) |
|
36 [retval, x, l] = common_size (x, l); |
|
37 if (retval > 0) |
5411
|
38 error ("exppdf: x and lambda must be of common size or scalar"); |
5410
|
39 endif |
|
40 endif |
|
41 |
|
42 if (isscalar (x)) |
|
43 sz = size (l); |
|
44 else |
|
45 sz = size (x); |
|
46 endif |
|
47 pdf = zeros (sz); |
|
48 |
|
49 k = find (!(l > 0) | isnan (x)); |
|
50 if (any (k)) |
|
51 pdf(k) = NaN; |
|
52 endif |
|
53 |
|
54 k = find ((x > 0) & (x < Inf) & (l > 0)); |
|
55 if (any (k)) |
|
56 if isscalar (l) |
|
57 pdf(k) = l .* exp (- l .* x(k)); |
|
58 elseif isscalar (x) |
|
59 pdf(k) = l(k) .* exp (- l(k) .* x); |
|
60 else |
|
61 pdf(k) = l(k) .* exp (- l(k) .* x(k)); |
|
62 endif |
|
63 endif |
|
64 |
|
65 endfunction |