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 (betainc, args, , |
3444
|
36 "-*- texinfo -*-\n\ |
|
37 @deftypefn {Mapping Function} {} betainc (@var{x}, @var{a}, @var{b})\n\ |
|
38 Return the incomplete Beta function,\n\ |
|
39 @iftex\n\ |
|
40 @tex\n\ |
|
41 $$\n\ |
|
42 \\beta (a, b, x) = B (a, b)^{-1} \\int_0^x t^{(a-z)} (1-t)^{(b-1)} dt.\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 /\n\ |
|
51 betai (a, b, x) = beta (a, b)^(-1) | t^(a-1) (1-t)^(b-1) dt.\n\ |
|
52 /\n\ |
|
53 t=0\n\ |
|
54 @end smallexample\n\ |
|
55 @end ifinfo\n\ |
3254
|
56 \n\ |
3444
|
57 If x has more than one component, both @var{a} and @var{b} must be\n\ |
|
58 scalars. If @var{x} is a scalar, @var{a} and @var{b} must be of\n\ |
|
59 compatible dimensions.\n\ |
|
60 @end deftypefn") |
3254
|
61 { |
|
62 octave_value retval; |
|
63 |
|
64 int nargin = args.length (); |
|
65 |
|
66 if (nargin == 3) |
|
67 { |
|
68 octave_value x_arg = args(0); |
|
69 octave_value a_arg = args(1); |
|
70 octave_value b_arg = args(2); |
|
71 |
|
72 if (x_arg.is_scalar_type ()) |
|
73 { |
|
74 double x = x_arg.double_value (); |
|
75 |
|
76 if (a_arg.is_scalar_type ()) |
|
77 { |
|
78 double a = a_arg.double_value (); |
|
79 |
|
80 if (! error_state) |
|
81 { |
|
82 if (b_arg.is_scalar_type ()) |
|
83 { |
|
84 double b = b_arg.double_value (); |
|
85 |
|
86 if (! error_state) |
|
87 retval = betainc (x, a, b); |
|
88 } |
|
89 else |
|
90 { |
4844
|
91 NDArray b = b_arg.array_value (); |
3254
|
92 |
|
93 if (! error_state) |
|
94 retval = betainc (x, a, b); |
|
95 } |
|
96 } |
|
97 } |
|
98 else |
|
99 { |
4844
|
100 NDArray a = a_arg.array_value (); |
3254
|
101 |
|
102 if (! error_state) |
|
103 { |
|
104 if (b_arg.is_scalar_type ()) |
|
105 { |
|
106 double b = b_arg.double_value (); |
|
107 |
|
108 if (! error_state) |
|
109 retval = betainc (x, a, b); |
|
110 } |
|
111 else |
|
112 { |
4844
|
113 NDArray b = b_arg.array_value (); |
3254
|
114 |
|
115 if (! error_state) |
|
116 retval = betainc (x, a, b); |
|
117 } |
|
118 } |
|
119 } |
|
120 } |
|
121 else |
|
122 { |
4844
|
123 NDArray x = x_arg.array_value (); |
3254
|
124 |
|
125 if (a_arg.is_scalar_type ()) |
|
126 { |
|
127 double a = a_arg.double_value (); |
|
128 |
|
129 if (! error_state) |
|
130 { |
|
131 if (b_arg.is_scalar_type ()) |
|
132 { |
|
133 double b = b_arg.double_value (); |
|
134 |
|
135 if (! error_state) |
|
136 retval = betainc (x, a, b); |
|
137 } |
|
138 else |
|
139 { |
4844
|
140 NDArray b = b_arg.array_value (); |
3254
|
141 |
|
142 if (! error_state) |
|
143 retval = betainc (x, a, b); |
|
144 } |
|
145 } |
|
146 } |
|
147 else |
|
148 { |
4844
|
149 NDArray a = a_arg.array_value (); |
3254
|
150 |
|
151 if (! error_state) |
|
152 { |
|
153 if (b_arg.is_scalar_type ()) |
|
154 { |
|
155 double b = b_arg.double_value (); |
|
156 |
|
157 if (! error_state) |
|
158 retval = betainc (x, a, b); |
|
159 } |
|
160 else |
|
161 { |
4844
|
162 NDArray b = b_arg.array_value (); |
3254
|
163 |
|
164 if (! error_state) |
|
165 retval = betainc (x, a, b); |
|
166 } |
|
167 } |
|
168 } |
|
169 } |
|
170 } |
|
171 else |
|
172 print_usage ("betainc"); |
|
173 |
|
174 return retval; |
|
175 } |
|
176 |
|
177 /* |
|
178 ;;; Local Variables: *** |
|
179 ;;; mode: C++ *** |
|
180 ;;; End: *** |
|
181 */ |
|
182 |