To use these functionalities, you should include pnl/pnl_integration.h.
Numerical integration methods are designed to numerically evaluate the integral over a finite or non finite interval (resp. over a square) of real valued functions defined on ℝ (resp. on ℝ2).
typedef struct { double (*function) (double x, void *params); void *params; } PnlFunc; typedef struct { double (*function) (double x, double y, void *params); void *params; } PnlFunc2D;
We provide the following two macros to evaluate a PnlFunc or PnlFunc2D at a given point
#define PNL_EVAL_FUNC(F, x) (*((F)->function))(x, (F)->params) #define PNL_EVAL_FUNC2D(F, x, y) (*((F)->function))(x, y, (F)->params)
double pnl_integration (PnlFunc *F, double x0, double x1, int n, char *meth)
Description Evaluate ∫
x0x1F using n discretization steps. The method used to
discretize the integral is defined by meth which can be "rect" (rectangle rule), "trap"
(trapezoidal rule), "simpson" (Simpson’s rule).
double pnl_integration_2d (PnlFunc2D *F, double x0, double x1, double y0,
double y1, int nx, int ny, char *meth)
Description Evaluate ∫
[x0,x1]×[y0,y1]F using nx (resp. ny) discretization steps for [x0,
x1] (resp. [y0, y1]). The method used to discretize the integral is defined by meth which
can be "rect" (rectangle rule), "trap" (trapezoidal rule), "simpson" (Simpson’s rule).
int pnl_integration_qng (PnlFunc *F, double x0, double x1, double epsabs, double
epsrel, double *result, double *abserr, int *neval)
Description Evaluate ∫
x0x1F with an absolute error less than espabs and a relative
error less than esprel. The value of the integral is stored in result, while the variables
abserr and neval respectively contain the absolute error and the number of function
evaluations. This function returns OK if the required accuracy has been reached and
FAIL otherwise. This function uses a non-adaptive Gauss Konrod procedure (qng routine
from QuadPack).
int pnl_integration_GK (PnlFunc *F, double x0, double x1, double epsabs, double
epsrel, double *result, double *abserr, int *neval)
Description This function is a synonymous of pnl_integration_qng and is only
available for backward compatibility. It is deprecated, please use pnl_integration_qng
instead.
int pnl_integration_qng_2d (PnlFunc2D *F, double x0, double x1, double y0,
double y1, double epsabs, double epsrel, double *result, double *abserr, int *neval)
Description Evaluate ∫
[x0,x1]×[y0,y1]F with an absolute error less than espabs and a
relative error less than esprel. The value of the integral is stored in result, while the
variables abserr and neval respectively contain the absolute error and the number of
function evaluations. This function returns OK if the required accuracy has been reached
and FAIL otherwise.
int pnl_integration_GK2D (PnlFunc *F, double x0, double x1, double epsabs,
double epsrel, double *result, double *abserr, int *neval)
Description This function is a synonymous of pnl_integration_qng_2d and
is only available for backward compatibility. It is deprecated, please use
pnl_integration_qng_2d instead.
int pnl_integration_qag (PnlFunc *F, double x0, double x1, double epsabs, int
limit, double epsrel, double *result, double *abserr, int *neval)
Description Evaluate ∫
x0x1F with an absolute error less than espabs and a
relative error less than esprel. x0 and x1 can be non finite (i.e. PNL_NEGINF or
PNL_POSINF). The value of the integral is stored in result, while the variables abserr
and neval respectively contain the absolute error and the number of iterations. limit is
the maximum number of subdivisions of the interval (x0,x1) used during the integration.
If on input, limit 0, then 750 subdivisions are used. This function returns OK if the
required accuracy has been reached and FAIL otherwise. This function uses some
adaptive procedures (qags and qagi routines from QuadPack). This function is able to
handle functions F with integrable singularities on the interval [x0,x1].
int pnl_integration_qagp (PnlFunc *F, double x0, double x1, const PnlVect
*singularities, double epsabs, int limit, double epsrel, double *result, double *abserr, int
*neval)
Description Evaluate ∫
x0x1F for a function F with known singularities listed in
singularities. singularities must be a sorted vector which does not contain x0 nor x1. x0
and x1 must be finite. The value of the integral is stored in result, while the variables
abserr and neval respectively contain the absolute error and the number of iterations.
limit is the maximum number of subdivisions of the interval (x0,x1) used during the
integration. If on input, limit = 0, then 750 subdivisions are used. This function returns
OK if the required accuracy has been reached and FAIL otherwise. This function uses
some adaptive procedures (qagp routine from QuadPack). This function is able to handle
functions F with integrable singularities on the interval [x0,x1].