79 if (tmp.
length () && tmp(0).is_defined ())
83 warning (
"quad: ignoring imaginary part returned from user-supplied function");
87 retval = tmp(0).double_value ();
124 if (tmp.
length () && tmp(0).is_defined ())
128 warning (
"quad: ignoring imaginary part returned from user-supplied function");
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}}.\n\
184 @var{f} is a function handle, inline function, or a string containing the\n\
185 name of the function to evaluate. The function must have the form @code{y =\n\
186 f (x)} where @var{y} and @var{x} are scalars.\n\
188 @var{a} and @var{b} are the lower and upper limits of integration. Either\n\
189 or both may be infinite.\n\
191 The optional argument @var{tol} is a vector that specifies the desired\n\
192 accuracy of the result. The first element of the vector is the desired\n\
193 absolute tolerance, and the second element is the desired relative\n\
194 tolerance. To choose a relative test only, set the absolute\n\
195 tolerance to zero. To choose an absolute test only, set the relative\n\
196 tolerance to zero. Both tolerances default to @code{sqrt (eps)} or\n\
197 approximately @math{1.5e^{-8}}.\n\
199 The optional argument @var{sing} is a vector of values at which the\n\
200 integrand is known to be singular.\n\
202 The result of the integration is returned in @var{q}.\n\
204 @var{ier} contains an integer error code (0 indicates a successful\n\
207 @var{nfun} indicates the number of function evaluations that were\n\
210 @var{err} contains an estimate of the error in the solution.\n\
212 The function @code{quad_options} can set other optional parameters for\n\
215 Note: because @code{quad} is written in Fortran it cannot be called\n\
216 recursively. This prevents its use in integrating over more than one\n\
217 variable by routines @code{dblquad} and @code{triplequad}.\n\
218 @seealso{quad_options, quadv, quadl, quadgk, quadcc, trapz, dblquad, triplequad}\n\
223 std::string fcn_name;
235 int nargin = args.length ();
237 if (nargin > 2 && nargin < 6 && nargout < 5)
239 if (args(0).is_function_handle () || args(0).is_inline_function ())
244 std::string fname =
"function y = ";
245 fname.append (fcn_name);
246 fname.append (
"(x) y = ");
254 if (args(1).is_single_type () || args(2).is_single_type ())
256 float a = args(1).float_value ();
259 QUAD_ABORT1 (
"expecting second argument to be a scalar");
261 float b = args(2).float_value ();
264 QUAD_ABORT1 (
"expecting third argument to be a scalar");
292 bool have_sing =
false;
300 QUAD_ABORT1 (
"singularities not allowed on infinite intervals");
307 QUAD_ABORT1 (
"expecting vector of singularities as fourth argument");
313 QUAD_ABORT1 (
"expecting vector of tolerances as fifth argument");
325 QUAD_ABORT1 (
"expecting tol to contain no more than two values");
366 double a = args(1).double_value ();
369 QUAD_ABORT1 (
"expecting second argument to be a scalar");
371 double b = args(2).double_value ();
374 QUAD_ABORT1 (
"expecting third argument to be a scalar");
401 bool have_sing =
false;
409 QUAD_ABORT1 (
"singularities not allowed on infinite intervals");
416 QUAD_ABORT1 (
"expecting vector of singularities as fourth argument");
422 QUAD_ABORT1 (
"expecting vector of tolerances as fifth argument");
434 QUAD_ABORT1 (
"expecting tol to contain no more than two values");
472 if (fcn_name.length ())
void set_single_precision_relative_tolerance(float val)
virtual double integrate(void)
virtual octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
virtual float float_integrate(void)
OCTINTERP_API void print_usage(void)
void set_relative_tolerance(double val)
octave_idx_type length(void) const
double quad_user_function(double x)
#define DEFUN(name, args_name, nargout_name, doc)
static Quad_options quad_opts
std::string unique_symbol_name(const std::string &basename)
void clear_function(const std::string &nm)
void set_single_precision_absolute_tolerance(float val)
float quad_float_user_function(float x)
#define panic_impossible()
octave_idx_type capacity(void) const
Number of elements in the array.
static bool warned_imaginary
void set_options(const Quad_options &opt)
static octave_function * quad_fcn
void warning(const char *fmt,...)
void set_absolute_tolerance(double val)
octave_function * extract_function(const octave_value &arg, const std::string &warn_for, const std::string &fname, const std::string &header, const std::string &trailer)
virtual octave_function * function_value(bool silent=false)
int quad_integration_error
void gripe_user_supplied_eval(const char *name)
F77_RET_T const double * x