38 #ifndef INTEGRATEFUNCTION_H
39 #define INTEGRATEFUNCTION_H
177 double integrateClosedRcrsv(
double a,
double b,
double* fr);
201 double simpson(
double a,
double b,
double* fa,
double& s);
254 fr[1] = ifF(0.5 * (a + b));
259 return integrateClosedRcrsv(a, b, fr);
265 double fs, fa, ae, be, senew;
273 double e = (b - a) * ifTol;
275 double minstep = 10.0 * DBL_EPSILON;
276 if (fa > 1.0) minstep *= fa;
284 s = integrateClosed(ae, b);
285 be = ae; ae = a + 0.1 * e;
290 senew = integrateClosed(ae, be);
297 if ((fabs(senew) < ifTol * fs) || (fs < ifTol))
304 be = ae; ae = a + 0.1 * e;
305 }
while ((e > minstep) && (be > ae) && (ae > a));
309 if (fabs(senew) > ifTol)
313 cout <<
" Error:: Function Error Tolerance Exceeded ... " << endl
314 <<
" Tolerance Condition Was Not Met." << endl;
343 double se = simpson(a, b, fa, s);
345 if ((se < ifTol * fs) || (fs < ifTol))
352 double m = 0.5 * (a + b);
353 if ((m <= a) | (b <= m))
359 cout <<
" Error:: Function Error Tolerance Exceeded ... " << endl
360 <<
" Tolerance Condition Was Not Met." << endl;
368 return integrateClosedRcrsv(a, m, &fa[0]) +
369 integrateClosedRcrsv(m, b, &fa[2]);
397 inline double IntegrateFunction<F>::simpson(
double a,
double b,
398 double* fa,
double& s)
403 fa[1] = ifF(a + 0.25 * h);
404 fa[3] = ifF(a + 0.75 * h);
411 double s1 = 2.0 * dh * (fa[0] + 4.0 * fa[2] + fa[4]);
412 s = dh * (fa[0] + 4.0 * (fa[1] + fa[3]) + 2.0 * fa[2] + fa[4]);
Class supports numerical integration of an arbitrary function using a fourth order Simpsons rule for ...
void setTolerance(double tol)
Sets the integration tolerance value.
double integrateAOpenS(double a, double b)
Adaptive closed form numerical integration of the input function over the open interval a to b,...
IntegrateFunction(F &f, double tol)
Standard Constructor.
const F & getF() const
Returns a const reference to the integrated function.
IntegrateFunction< F > & operator=(const IntegrateFunction< F > &ifctn)
Assignment Operator.
IntegrateFunction(const IntegrateFunction< F > &ifctn)
Copy Constructor.
virtual ~IntegrateFunction()
Destructor.
double getTolerance() const
Returns the integration tolerance value.
double integrateClosed(double a, double b)
Adaptive closed form numerical integration of the input function over the closed interval a to b....
F & getF()
Returns a reference to the integrated function.