7017
|
1 ## Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007 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} {} exppdf (@var{x}, @var{lambda}) |
5410
|
21 ## For each element of @var{x}, compute the probability density function |
|
22 ## (PDF) of the exponential 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 exponential distribution |
|
27 |
5411
|
28 function pdf = exppdf (x, l) |
5410
|
29 |
|
30 if (nargin != 2) |
6046
|
31 print_usage (); |
5410
|
32 endif |
|
33 |
|
34 if (!isscalar (x) && !isscalar(l)) |
|
35 [retval, x, l] = common_size (x, l); |
|
36 if (retval > 0) |
5411
|
37 error ("exppdf: x and lambda must be of common size or scalar"); |
5410
|
38 endif |
|
39 endif |
|
40 |
|
41 if (isscalar (x)) |
|
42 sz = size (l); |
|
43 else |
|
44 sz = size (x); |
|
45 endif |
|
46 pdf = zeros (sz); |
|
47 |
|
48 k = find (!(l > 0) | isnan (x)); |
|
49 if (any (k)) |
|
50 pdf(k) = NaN; |
|
51 endif |
|
52 |
|
53 k = find ((x > 0) & (x < Inf) & (l > 0)); |
|
54 if (any (k)) |
|
55 if isscalar (l) |
6777
|
56 pdf(k) = exp (- x(k) ./ l) ./ l; |
5410
|
57 elseif isscalar (x) |
6777
|
58 pdf(k) = exp (- x ./ l(k)) ./ l(k); |
5410
|
59 else |
6777
|
60 pdf(k) = exp (- x(k) ./ l(k)) ./ l(k); |
5410
|
61 endif |
|
62 endif |
|
63 |
|
64 endfunction |