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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
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\ |
|
38 Computes the incomplete gamma function,\n\ |
|
39 @iftex\n\ |
|
40 @tex\n\ |
|
41 $$\n\ |
|
42 \\gamma (a, x) = {\\displaystyle\\int_0^x e^{-t} t^{a-1} dt \\over \\Gamma (a)}\n\ |
|
43 $$\n\ |
|
44 @end tex\n\ |
|
45 @end iftex\n\ |
|
46 @ifinfo\n\ |
3254
|
47 \n\ |
3444
|
48 @smallexample\n\ |
|
49 x\n\ |
|
50 1 /\n\ |
|
51 gammainc (a, x) = --------- | exp (-t) t^(a-1) dt\n\ |
|
52 gamma (a) /\n\ |
|
53 t=0\n\ |
|
54 @end smallexample\n\ |
|
55 @end ifinfo\n\ |
3254
|
56 \n\ |
3444
|
57 If @var{a} is scalar, then @code{gammainc (@var{a}, @var{x})} is returned\n\ |
|
58 for each element of @var{x} and vice versa.\n\ |
|
59 \n\ |
|
60 If neither @var{a} nor @var{x} is scalar, the sizes of @var{a} and\n\ |
|
61 @var{x} must agree, and @var{gammainc} is applied element-by-element.\n\ |
|
62 @end deftypefn\n\ |
|
63 @seealso{gamma and lgamma}") |
3254
|
64 { |
|
65 octave_value retval; |
|
66 |
|
67 int nargin = args.length (); |
|
68 |
|
69 if (nargin == 2) |
|
70 { |
|
71 octave_value x_arg = args(0); |
|
72 octave_value a_arg = args(1); |
|
73 |
|
74 if (x_arg.is_scalar_type ()) |
|
75 { |
|
76 double x = x_arg.double_value (); |
|
77 |
|
78 if (! error_state) |
|
79 { |
|
80 if (a_arg.is_scalar_type ()) |
|
81 { |
|
82 double a = a_arg.double_value (); |
|
83 |
|
84 if (! error_state) |
|
85 retval = gammainc (x, a); |
|
86 } |
|
87 else |
|
88 { |
|
89 Matrix a = a_arg.matrix_value (); |
|
90 |
|
91 if (! error_state) |
|
92 retval = gammainc (x, a); |
|
93 } |
|
94 } |
|
95 } |
|
96 else |
|
97 { |
|
98 Matrix x = x_arg.matrix_value (); |
|
99 |
|
100 if (! error_state) |
|
101 { |
|
102 if (a_arg.is_scalar_type ()) |
|
103 { |
|
104 double a = a_arg.double_value (); |
|
105 |
|
106 if (! error_state) |
|
107 retval = gammainc (x, a); |
|
108 } |
|
109 else |
|
110 { |
|
111 Matrix a = a_arg.matrix_value (); |
|
112 |
|
113 if (! error_state) |
|
114 retval = gammainc (x, a); |
|
115 } |
|
116 } |
|
117 } |
|
118 } |
|
119 else |
|
120 print_usage ("gammainc"); |
|
121 |
|
122 return retval; |
|
123 } |
|
124 |
|
125 /* |
|
126 ;;; Local Variables: *** |
|
127 ;;; mode: C++ *** |
|
128 ;;; End: *** |
|
129 */ |
|
130 |