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, , |
|
36 "gammainc (x, a)\n\ |
|
37 \n\ |
|
38 Compute the incomplete gamma function\n\ |
|
39 \n\ |
|
40 gammainc(x,a) = (\\int_0^x exp(-t) t^(a-1) dt) / gamma(a).\n\ |
|
41 \n\ |
|
42 If a is scalar, then gammainc(x,a) is returned for each element of x\n\ |
|
43 and vice versa.\n\ |
|
44 \n\ |
|
45 If neither a nor x is scalar, the sizes of a and x must agree, and\n\ |
|
46 gammainc is applied for corresponding elements of x and a.") |
|
47 { |
|
48 octave_value retval; |
|
49 |
|
50 int nargin = args.length (); |
|
51 |
|
52 if (nargin == 2) |
|
53 { |
|
54 octave_value x_arg = args(0); |
|
55 octave_value a_arg = args(1); |
|
56 |
|
57 if (x_arg.is_scalar_type ()) |
|
58 { |
|
59 double x = x_arg.double_value (); |
|
60 |
|
61 if (! error_state) |
|
62 { |
|
63 if (a_arg.is_scalar_type ()) |
|
64 { |
|
65 double a = a_arg.double_value (); |
|
66 |
|
67 if (! error_state) |
|
68 retval = gammainc (x, a); |
|
69 } |
|
70 else |
|
71 { |
|
72 Matrix a = a_arg.matrix_value (); |
|
73 |
|
74 if (! error_state) |
|
75 retval = gammainc (x, a); |
|
76 } |
|
77 } |
|
78 } |
|
79 else |
|
80 { |
|
81 Matrix x = x_arg.matrix_value (); |
|
82 |
|
83 if (! error_state) |
|
84 { |
|
85 if (a_arg.is_scalar_type ()) |
|
86 { |
|
87 double a = a_arg.double_value (); |
|
88 |
|
89 if (! error_state) |
|
90 retval = gammainc (x, a); |
|
91 } |
|
92 else |
|
93 { |
|
94 Matrix a = a_arg.matrix_value (); |
|
95 |
|
96 if (! error_state) |
|
97 retval = gammainc (x, a); |
|
98 } |
|
99 } |
|
100 } |
|
101 } |
|
102 else |
|
103 print_usage ("gammainc"); |
|
104 |
|
105 return retval; |
|
106 } |
|
107 |
|
108 /* |
|
109 ;;; Local Variables: *** |
|
110 ;;; mode: C++ *** |
|
111 ;;; End: *** |
|
112 */ |
|
113 |