55 inline double romberg(
const double low,
const double high,
const uint8 n,
const std::function<
double(
double)>& f)
60 rombergIntegral(0, 0) =
trapazoidal(low, high, 1, f);
62 double h = high - low;
63 for (
uint8 step = 1; step < n; step++)
68 double trapezoidal_integration = 0.;
70 for (
uint32 tzStep = 1; tzStep <= stepEnd; ++tzStep)
72 const double deltaX = (2. *
static_cast<double>(tzStep - 1)) * h;
73 trapezoidal_integration += f(low + deltaX);
76 rombergIntegral(step, 0) = 0.5 * rombergIntegral(step - 1, 0);
77 rombergIntegral(step, 0) += trapezoidal_integration * h;
80 for (
uint8 rbStep = 1; rbStep <= step; ++rbStep)
83 rombergIntegral(step, rbStep) = k * rombergIntegral(step, rbStep - 1);
84 rombergIntegral(step, rbStep) -= rombergIntegral(step - 1, rbStep - 1);
85 rombergIntegral(step, rbStep) /= (k - 1.);
89 return rombergIntegral.
back();
double romberg(const double low, const double high, const uint8 n, const std::function< double(double)> &f)
Definition romberg.hpp:55
double trapazoidal(const double low, const double high, const uint32 n, const std::function< double(double)> &f) noexcept
Definition trapazoidal.hpp:51