3254
|
1 /* |
|
2 |
|
3 Copyright (C) 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
3254
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
3254
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "lo-specfun.h" |
|
28 |
|
29 #include "defun-dld.h" |
|
30 #include "error.h" |
|
31 #include "gripes.h" |
|
32 #include "oct-obj.h" |
|
33 #include "utils.h" |
|
34 |
|
35 DEFUN_DLD (gammainc, args, , |
3548
|
36 "-*- texinfo -*-\n\ |
3444
|
37 @deftypefn {Mapping Function} {} gammainc (@var{x}, @var{a})\n\ |
5517
|
38 Compute the normalized incomplete gamma function,\n\ |
3444
|
39 @iftex\n\ |
|
40 @tex\n\ |
|
41 $$\n\ |
3683
|
42 \\gamma (x, a) = {\\displaystyle\\int_0^x e^{-t} t^{a-1} dt \\over \\Gamma (a)}\n\ |
3444
|
43 $$\n\ |
|
44 @end tex\n\ |
|
45 @end iftex\n\ |
|
46 @ifinfo\n\ |
3254
|
47 \n\ |
3444
|
48 @smallexample\n\ |
3683
|
49 x\n\ |
|
50 1 /\n\ |
|
51 gammainc (x, a) = --------- | exp (-t) t^(a-1) dt\n\ |
|
52 gamma (a) /\n\ |
|
53 t=0\n\ |
3444
|
54 @end smallexample\n\ |
5517
|
55 \n\ |
3444
|
56 @end ifinfo\n\ |
5517
|
57 with the limiting value of 1 as @var{x} approaches infinity.\n\ |
|
58 The standard notation is @math{P(a,x)}, e.g. Abramowitz and Stegun (6.5.1).\n\ |
3254
|
59 \n\ |
3683
|
60 If @var{a} is scalar, then @code{gammainc (@var{x}, @var{a})} is returned\n\ |
3444
|
61 for each element of @var{x} and vice versa.\n\ |
|
62 \n\ |
3683
|
63 If neither @var{x} nor @var{a} is scalar, the sizes of @var{x} and\n\ |
|
64 @var{a} must agree, and @var{gammainc} is applied element-by-element.\n\ |
5642
|
65 @seealso{gamma, lgamma}\n\ |
|
66 @end deftypefn") |
3254
|
67 { |
|
68 octave_value retval; |
|
69 |
|
70 int nargin = args.length (); |
|
71 |
|
72 if (nargin == 2) |
|
73 { |
|
74 octave_value x_arg = args(0); |
|
75 octave_value a_arg = args(1); |
|
76 |
|
77 if (x_arg.is_scalar_type ()) |
|
78 { |
|
79 double x = x_arg.double_value (); |
|
80 |
|
81 if (! error_state) |
|
82 { |
|
83 if (a_arg.is_scalar_type ()) |
|
84 { |
|
85 double a = a_arg.double_value (); |
|
86 |
|
87 if (! error_state) |
|
88 retval = gammainc (x, a); |
|
89 } |
|
90 else |
|
91 { |
4844
|
92 NDArray a = a_arg.array_value (); |
3254
|
93 |
|
94 if (! error_state) |
|
95 retval = gammainc (x, a); |
|
96 } |
|
97 } |
|
98 } |
|
99 else |
|
100 { |
4844
|
101 NDArray x = x_arg.array_value (); |
3254
|
102 |
|
103 if (! error_state) |
|
104 { |
|
105 if (a_arg.is_scalar_type ()) |
|
106 { |
|
107 double a = a_arg.double_value (); |
|
108 |
|
109 if (! error_state) |
|
110 retval = gammainc (x, a); |
|
111 } |
|
112 else |
|
113 { |
4844
|
114 NDArray a = a_arg.array_value (); |
3254
|
115 |
|
116 if (! error_state) |
|
117 retval = gammainc (x, a); |
|
118 } |
|
119 } |
|
120 } |
|
121 } |
|
122 else |
5823
|
123 print_usage (); |
3254
|
124 |
|
125 return retval; |
|
126 } |
|
127 |
|
128 /* |
|
129 ;;; Local Variables: *** |
|
130 ;;; mode: C++ *** |
|
131 ;;; End: *** |
|
132 */ |
|
133 |