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} {} gamcdf (@var{x}, @var{a}, @var{b}) |
5410
|
22 ## For each element of @var{x}, compute the cumulative distribution |
|
23 ## function (CDF) at @var{x} of the Gamma distribution with parameters |
|
24 ## @var{a} and @var{b}. |
5642
|
25 ## @seealso{gamma, gammaln, gammainc, gampdf, gaminv, gamrnd} |
5410
|
26 ## @end deftypefn |
|
27 |
|
28 ## Author: TT <Teresa.Twaroch@ci.tuwien.ac.at> |
|
29 ## Description: CDF of the Gamma distribution |
|
30 |
5411
|
31 function cdf = gamcdf (x, a, b) |
5410
|
32 |
|
33 if (nargin != 3) |
5411
|
34 usage ("gamcdf (x, a, b)"); |
5410
|
35 endif |
|
36 |
|
37 if (!isscalar (a) || !isscalar(b)) |
|
38 [retval, x, a, b] = common_size (x, a, b); |
|
39 if (retval > 0) |
5411
|
40 error ("gamcdf: x, a and b must be of common size or scalars"); |
5410
|
41 endif |
|
42 endif |
|
43 |
|
44 sz = size (x); |
|
45 cdf = zeros (sz); |
|
46 |
|
47 k = find (!(a > 0) | !(b > 0) | isnan (x)); |
|
48 if (any (k)) |
|
49 cdf (k) = NaN; |
|
50 endif |
|
51 |
|
52 k = find ((x > 0) & (a > 0) & (b > 0)); |
|
53 if (any (k)) |
|
54 if (isscalar (a) && isscalar(b)) |
|
55 cdf (k) = gammainc (b * x(k), a); |
|
56 else |
|
57 cdf (k) = gammainc (b(k) .* x(k), a(k)); |
|
58 endif |
|
59 endif |
|
60 |
|
61 endfunction |