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} {} expcdf (@var{x}, @var{lambda}) |
5410
|
21 ## For each element of @var{x}, compute the cumulative distribution |
|
22 ## function (CDF) at @var{x} of the exponential distribution with |
|
23 ## parameter @var{lambda}. |
|
24 ## |
|
25 ## The arguments can be of common size or scalar. |
|
26 ## @end deftypefn |
|
27 |
5428
|
28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410
|
29 ## Description: CDF of the exponential distribution |
|
30 |
5411
|
31 function cdf = expcdf (x, l) |
5410
|
32 |
|
33 if (nargin != 2) |
6046
|
34 print_usage (); |
5410
|
35 endif |
|
36 |
|
37 if (!isscalar (x) && !isscalar(l)) |
|
38 [retval, x, l] = common_size (x, l); |
|
39 if (retval > 0) |
5411
|
40 error ("expcdf: x and lambda must be of common size or scalar"); |
5410
|
41 endif |
|
42 endif |
|
43 |
|
44 if (isscalar (x)) |
|
45 sz = size (l); |
|
46 else |
|
47 sz = size (x); |
|
48 endif |
|
49 |
|
50 cdf = zeros (sz); |
|
51 |
|
52 k = find (isnan (x) | !(l > 0)); |
|
53 if (any (k)) |
|
54 cdf(k) = NaN; |
|
55 endif |
|
56 |
|
57 k = find ((x == Inf) & (l > 0)); |
|
58 if (any (k)) |
|
59 cdf(k) = 1; |
|
60 endif |
|
61 |
|
62 k = find ((x > 0) & (x < Inf) & (l > 0)); |
|
63 if (any (k)) |
|
64 if isscalar (l) |
6777
|
65 cdf (k) = 1 - exp (- x(k) ./ l); |
5410
|
66 elseif isscalar (x) |
6777
|
67 cdf (k) = 1 - exp (- x ./ l(k)); |
5410
|
68 else |
6777
|
69 cdf (k) = 1 - exp (- x(k) ./ l(k)); |
5410
|
70 endif |
|
71 endif |
|
72 |
|
73 endfunction |