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, , |
|
36 "betainc (x, a, b)\n\ |
|
37 \n\ |
|
38 Compute the incomplete beta function\n\ |
|
39 \n\ |
|
40 betainc(x,a,b) = beta(a,b)^(-1) \\int_0^x t^(a-1) (1-t)^(b-1) dt\n\ |
|
41 \n\ |
|
42 The sizes of x, a, and b must agree.") |
|
43 { |
|
44 octave_value retval; |
|
45 |
|
46 int nargin = args.length (); |
|
47 |
|
48 if (nargin == 3) |
|
49 { |
|
50 octave_value x_arg = args(0); |
|
51 octave_value a_arg = args(1); |
|
52 octave_value b_arg = args(2); |
|
53 |
|
54 if (x_arg.is_scalar_type ()) |
|
55 { |
|
56 double x = x_arg.double_value (); |
|
57 |
|
58 if (a_arg.is_scalar_type ()) |
|
59 { |
|
60 double a = a_arg.double_value (); |
|
61 |
|
62 if (! error_state) |
|
63 { |
|
64 if (b_arg.is_scalar_type ()) |
|
65 { |
|
66 double b = b_arg.double_value (); |
|
67 |
|
68 if (! error_state) |
|
69 retval = betainc (x, a, b); |
|
70 } |
|
71 else |
|
72 { |
|
73 Matrix b = b_arg.matrix_value (); |
|
74 |
|
75 if (! error_state) |
|
76 retval = betainc (x, a, b); |
|
77 } |
|
78 } |
|
79 } |
|
80 else |
|
81 { |
|
82 Matrix a = a_arg.matrix_value (); |
|
83 |
|
84 if (! error_state) |
|
85 { |
|
86 if (b_arg.is_scalar_type ()) |
|
87 { |
|
88 double b = b_arg.double_value (); |
|
89 |
|
90 if (! error_state) |
|
91 retval = betainc (x, a, b); |
|
92 } |
|
93 else |
|
94 { |
|
95 Matrix b = b_arg.matrix_value (); |
|
96 |
|
97 if (! error_state) |
|
98 retval = betainc (x, a, b); |
|
99 } |
|
100 } |
|
101 } |
|
102 } |
|
103 else |
|
104 { |
|
105 Matrix x = x_arg.matrix_value (); |
|
106 |
|
107 if (a_arg.is_scalar_type ()) |
|
108 { |
|
109 double a = a_arg.double_value (); |
|
110 |
|
111 if (! error_state) |
|
112 { |
|
113 if (b_arg.is_scalar_type ()) |
|
114 { |
|
115 double b = b_arg.double_value (); |
|
116 |
|
117 if (! error_state) |
|
118 retval = betainc (x, a, b); |
|
119 } |
|
120 else |
|
121 { |
|
122 Matrix b = b_arg.matrix_value (); |
|
123 |
|
124 if (! error_state) |
|
125 retval = betainc (x, a, b); |
|
126 } |
|
127 } |
|
128 } |
|
129 else |
|
130 { |
|
131 Matrix a = a_arg.matrix_value (); |
|
132 |
|
133 if (! error_state) |
|
134 { |
|
135 if (b_arg.is_scalar_type ()) |
|
136 { |
|
137 double b = b_arg.double_value (); |
|
138 |
|
139 if (! error_state) |
|
140 retval = betainc (x, a, b); |
|
141 } |
|
142 else |
|
143 { |
|
144 Matrix b = b_arg.matrix_value (); |
|
145 |
|
146 if (! error_state) |
|
147 retval = betainc (x, a, b); |
|
148 } |
|
149 } |
|
150 } |
|
151 } |
|
152 } |
|
153 else |
|
154 print_usage ("betainc"); |
|
155 |
|
156 return retval; |
|
157 } |
|
158 |
|
159 /* |
|
160 ;;; Local Variables: *** |
|
161 ;;; mode: C++ *** |
|
162 ;;; End: *** |
|
163 */ |
|
164 |