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