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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3254
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "lo-specfun.h" |
|
29 |
|
30 #include "defun-dld.h" |
|
31 #include "error.h" |
|
32 #include "gripes.h" |
|
33 #include "oct-obj.h" |
|
34 #include "utils.h" |
|
35 |
|
36 DEFUN_DLD (betainc, args, , |
3444
|
37 "-*- texinfo -*-\n\ |
|
38 @deftypefn {Mapping Function} {} betainc (@var{x}, @var{a}, @var{b})\n\ |
|
39 Return the incomplete Beta function,\n\ |
|
40 @iftex\n\ |
|
41 @tex\n\ |
|
42 $$\n\ |
5402
|
43 \\beta (x, a, b) = B (a, b)^{-1} \\int_0^x t^{(a-z)} (1-t)^{(b-1)} dt.\n\ |
3444
|
44 $$\n\ |
|
45 @end tex\n\ |
|
46 @end iftex\n\ |
|
47 @ifinfo\n\ |
3254
|
48 \n\ |
3444
|
49 @smallexample\n\ |
5401
|
50 x\n\ |
|
51 /\n\ |
|
52 betainc (x, a, b) = beta (a, b)^(-1) | t^(a-1) (1-t)^(b-1) dt.\n\ |
|
53 /\n\ |
|
54 t=0\n\ |
3444
|
55 @end smallexample\n\ |
|
56 @end ifinfo\n\ |
3254
|
57 \n\ |
3444
|
58 If x has more than one component, both @var{a} and @var{b} must be\n\ |
|
59 scalars. If @var{x} is a scalar, @var{a} and @var{b} must be of\n\ |
|
60 compatible dimensions.\n\ |
|
61 @end deftypefn") |
3254
|
62 { |
|
63 octave_value retval; |
|
64 |
|
65 int nargin = args.length (); |
|
66 |
|
67 if (nargin == 3) |
|
68 { |
|
69 octave_value x_arg = args(0); |
|
70 octave_value a_arg = args(1); |
|
71 octave_value b_arg = args(2); |
|
72 |
|
73 if (x_arg.is_scalar_type ()) |
|
74 { |
|
75 double x = x_arg.double_value (); |
|
76 |
|
77 if (a_arg.is_scalar_type ()) |
|
78 { |
|
79 double a = a_arg.double_value (); |
|
80 |
|
81 if (! error_state) |
|
82 { |
|
83 if (b_arg.is_scalar_type ()) |
|
84 { |
|
85 double b = b_arg.double_value (); |
|
86 |
|
87 if (! error_state) |
|
88 retval = betainc (x, a, b); |
|
89 } |
|
90 else |
|
91 { |
4844
|
92 NDArray b = b_arg.array_value (); |
3254
|
93 |
|
94 if (! error_state) |
|
95 retval = betainc (x, a, b); |
|
96 } |
|
97 } |
|
98 } |
|
99 else |
|
100 { |
4844
|
101 NDArray a = a_arg.array_value (); |
3254
|
102 |
|
103 if (! error_state) |
|
104 { |
|
105 if (b_arg.is_scalar_type ()) |
|
106 { |
|
107 double b = b_arg.double_value (); |
|
108 |
|
109 if (! error_state) |
|
110 retval = betainc (x, a, b); |
|
111 } |
|
112 else |
|
113 { |
4844
|
114 NDArray b = b_arg.array_value (); |
3254
|
115 |
|
116 if (! error_state) |
|
117 retval = betainc (x, a, b); |
|
118 } |
|
119 } |
|
120 } |
|
121 } |
|
122 else |
|
123 { |
4844
|
124 NDArray x = x_arg.array_value (); |
3254
|
125 |
|
126 if (a_arg.is_scalar_type ()) |
|
127 { |
|
128 double a = a_arg.double_value (); |
|
129 |
|
130 if (! error_state) |
|
131 { |
|
132 if (b_arg.is_scalar_type ()) |
|
133 { |
|
134 double b = b_arg.double_value (); |
|
135 |
|
136 if (! error_state) |
|
137 retval = betainc (x, a, b); |
|
138 } |
|
139 else |
|
140 { |
4844
|
141 NDArray b = b_arg.array_value (); |
3254
|
142 |
|
143 if (! error_state) |
|
144 retval = betainc (x, a, b); |
|
145 } |
|
146 } |
|
147 } |
|
148 else |
|
149 { |
4844
|
150 NDArray a = a_arg.array_value (); |
3254
|
151 |
|
152 if (! error_state) |
|
153 { |
|
154 if (b_arg.is_scalar_type ()) |
|
155 { |
|
156 double b = b_arg.double_value (); |
|
157 |
|
158 if (! error_state) |
|
159 retval = betainc (x, a, b); |
|
160 } |
|
161 else |
|
162 { |
4844
|
163 NDArray b = b_arg.array_value (); |
3254
|
164 |
|
165 if (! error_state) |
|
166 retval = betainc (x, a, b); |
|
167 } |
|
168 } |
|
169 } |
|
170 } |
|
171 } |
|
172 else |
5823
|
173 print_usage (); |
3254
|
174 |
|
175 return retval; |
|
176 } |
|
177 |
|
178 /* |
|
179 ;;; Local Variables: *** |
|
180 ;;; mode: C++ *** |
|
181 ;;; End: *** |
|
182 */ |
|
183 |