25#ifndef quantlib_trapezoid_integral_hpp
26#define quantlib_trapezoid_integral_hpp
51 template <
class IntegrationPolicy>
63 Real I = (
f(a)+
f(
b))*(
b-a)/2.0, newI;
68 newI = IntegrationPolicy::integrate(
f,a,
b,I,N);
70 N *= IntegrationPolicy::nbEvalutions();
79 QL_FAIL(
"max number of iterations reached");
94 for (
Size i=0; i<N; x += dx, ++i)
96 return (I + dx*sum)/2.0;
112 for (
Size i=0; i<N; x += dx, ++i)
113 sum +=
f(x) +
f(x+D);
114 return (I + dx*sum)/3.0;
Real absoluteAccuracy() const
Size maxEvaluations() const
void increaseNumberOfEvaluations(Size increase) const
Integral of a one-dimensional function.
TrapezoidIntegral(Real accuracy, Size maxIterations)
Real integrate(const ext::function< Real(Real)> &f, Real a, Real b) const override
Classes and functions for error handling.
#define QL_FAIL(message)
throw an error (possibly with file and line information)
ext::function< Real(Real)> b
std::size_t Size
size of a container
Integrators base class definition.
static Real integrate(const ext::function< Real(Real)> &f, Real a, Real b, Real I, Size N)
static Size nbEvalutions()
static Real integrate(const ext::function< Real(Real)> &f, Real a, Real b, Real I, Size N)
static Size nbEvalutions()