79 if (tmp.
length () && tmp(0).is_defined ())
81 if (! warned_imaginary && tmp(0).is_complex_type ())
83 warning (
"quad: ignoring imaginary part returned from user-supplied function");
84 warned_imaginary =
true;
87 retval = tmp(0).double_value ();
124 if (tmp.
length () && tmp(0).is_defined ())
126 if (! warned_imaginary && tmp(0).is_complex_type ())
128 warning (
"quad: ignoring imaginary part returned from user-supplied function");
129 warned_imaginary =
true;
132 retval = tmp(0).float_value ();
150 #define QUAD_ABORT() \
153 if (fcn_name.length ()) \
154 clear_function (fcn_name); \
159 #define QUAD_ABORT1(msg) \
162 ::error ("quad: " msg); \
167 #define QUAD_ABORT2(fmt, arg) \
170 ::error ("quad: " fmt, arg); \
175 DEFUN (quad, args, nargout,
177 @deftypefn {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b})\n\
178 @deftypefnx {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b}, @var{tol})\n\
179 @deftypefnx {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b}, @var{tol}, @var{sing})\n\
180 @deftypefnx {Built-in Function} {[@var{q}, @var{ier}, @var{nfun}, @var{err}] =} quad (@dots{})\n\
181 Numerically evaluate the integral of @var{f} from @var{a} to @var{b} using\n\
182 Fortran routines from @w{@sc{quadpack}}. @var{f} is a function handle,\n\
183 inline function, or a string containing the name of the function to\n\
184 evaluate. The function must have the form @code{y = f (x)} where @var{y} and\n\
185 @var{x} are scalars.\n\
187 @var{a} and @var{b} are the lower and upper limits of integration. Either\n\
188 or both may be infinite.\n\
190 The optional argument @var{tol} is a vector that specifies the desired\n\
191 accuracy of the result. The first element of the vector is the desired\n\
192 absolute tolerance, and the second element is the desired relative\n\
193 tolerance. To choose a relative test only, set the absolute\n\
194 tolerance to zero. To choose an absolute test only, set the relative\n\
195 tolerance to zero. Both tolerances default to @code{sqrt (eps)} or\n\
196 approximately @math{1.5e^{-8}}.\n\
198 The optional argument @var{sing} is a vector of values at which the\n\
199 integrand is known to be singular.\n\
201 The result of the integration is returned in @var{q}. @var{ier}\n\
202 contains an integer error code (0 indicates a successful integration).\n\
203 @var{nfun} indicates the number of function evaluations that were\n\
204 made, and @var{err} contains an estimate of the error in the\n\
207 The function @code{quad_options} can set other optional\n\
208 parameters for @code{quad}.\n\
210 Note: because @code{quad} is written in Fortran it cannot be called\n\
211 recursively. This prevents its use in integrating over more than one\n\
212 variable by routines @code{dblquad} and @code{triplequad}.\n\
213 @seealso{quad_options, quadv, quadl, quadgk, quadcc, trapz, dblquad, triplequad}\n\
218 std::string fcn_name;
220 warned_imaginary =
false;
230 int nargin = args.length ();
232 if (nargin > 2 && nargin < 6 && nargout < 5)
234 if (args(0).is_function_handle () || args(0).is_inline_function ())
239 std::string fname =
"function y = ";
240 fname.append (fcn_name);
241 fname.append (
"(x) y = ");
249 if (args(1).is_single_type () || args(2).is_single_type ())
251 float a = args(1).float_value ();
254 QUAD_ABORT1 (
"expecting second argument to be a scalar");
256 float b = args(2).float_value ();
259 QUAD_ABORT1 (
"expecting third argument to be a scalar");
287 bool have_sing =
false;
295 QUAD_ABORT1 (
"singularities not allowed on infinite intervals");
302 QUAD_ABORT1 (
"expecting vector of singularities as fourth argument");
308 QUAD_ABORT1 (
"expecting vector of tolerances as fifth argument");
320 QUAD_ABORT1 (
"expecting tol to contain no more than two values");
361 double a = args(1).double_value ();
364 QUAD_ABORT1 (
"expecting second argument to be a scalar");
366 double b = args(2).double_value ();
369 QUAD_ABORT1 (
"expecting third argument to be a scalar");
396 bool have_sing =
false;
404 QUAD_ABORT1 (
"singularities not allowed on infinite intervals");
411 QUAD_ABORT1 (
"expecting vector of singularities as fourth argument");
417 QUAD_ABORT1 (
"expecting vector of tolerances as fifth argument");
429 QUAD_ABORT1 (
"expecting tol to contain no more than two values");
467 if (fcn_name.length ())