39 bool useConvergenceEstimate)
41 relAccuracy_(relAccuracy),
42 useConvergenceEstimate_(useConvergenceEstimate) {
63 const Real m = (a+
b)/2;
64 const Real h = (
b-a)/2;
80 Real acc=h*(0.0158271919734801831*(y1+y13)
81 +0.0942738402188500455*(f1+f2)
82 +0.1550719873365853963*(y3+y11)
83 +0.1888215739601824544*(f3+f4)
84 +0.1997734052268585268*(y5+y9)
85 +0.2249264653333395270*(f5+f6)
86 +0.2426110719014077338*y7);
89 if (acc == 0.0 && ( f1 != 0.0 || f2 != 0.0 || f3 != 0.0
90 || f4 != 0.0 || f5 != 0.0 || f6 != 0.0)) {
91 QL_FAIL(
"can not calculate absolute accuracy "
92 "from relative accuracy");
97 const Real integral2 = (h/6)*(y1+y13+5*(y5+y9));
98 const Real integral1 = (h/1470)*(77*(y1+y13)+432*(y3+y11)+
101 if (std::fabs(integral2-acc) != 0.0)
102 r = std::fabs(integral1-acc)/std::fabs(integral2-acc);
103 if (
r == 0.0 ||
r > 1.0)
119 "max number of iterations reached");
121 const Real h=(
b-a)/2;
122 const Real m=(a+
b)/2;
129 const Real fmll=
f(mll);
130 const Real fml =
f(ml);
131 const Real fm =
f(m);
132 const Real fmr =
f(mr);
133 const Real fmrr=
f(mrr);
136 const Real integral2=(h/6)*(fa+fb+5*(fml+fmr));
137 const Real integral1=(h/1470)*(77*(fa+fb)
138 +432*(fmll+fmrr)+625*(fml+fmr)+672*fm);
141 const Real dist = acc + (integral1-integral2);
142 if(dist==acc || mll<=a ||
b<=mrr) {
143 QL_REQUIRE(m>a &&
b>m,
"Interval contains no more machine number");
GaussLobattoIntegral(Size maxIterations, Real absAccuracy, Real relAccuracy=Null< Real >(), bool useConvergenceEstimate=true)
Real calculateAbsTolerance(const std::function< Real(Real)> &f, Real a, Real b) const
Real integrate(const std::function< Real(Real)> &f, Real a, Real b) const override
const bool useConvergenceEstimate_
Real adaptivGaussLobattoStep(const std::function< Real(Real)> &f, Real a, Real b, Real fa, Real fb, Real is) const
Real absoluteAccuracy() const
Size numberOfEvaluations() const
Size maxEvaluations() const
void increaseNumberOfEvaluations(Size increase) const
void setNumberOfEvaluations(Size evaluations) const
template class providing a null value for a given type.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
std::function< Real(Real)> b
integral of a one-dimensional function using the adaptive Gauss-Lobatto integral
std::size_t Size
size of a container
ext::shared_ptr< YieldTermStructure > r