1#ifndef PIVOT_INTEGRATION_H
2#define PIVOT_INTEGRATION_H
43 const double h = (hi - lo) / N;
45 for (
int i = 0; i <= N; ++i) {
46 const double x = lo + i * h;
47 const double v = f(x);
48 if (std::isnan(v))
return std::numeric_limits<double>::quiet_NaN();
49 const double coeff = (i == 0 || i == N) ? 1.0 : (i % 2 == 1 ? 4.0 : 2.0);
59 if (k > n)
return 0.0;
60 if (k > n - k) k = n - k;
62 for (
unsigned i = 1; i <= k; ++i) {
63 r *=
static_cast<double>(n - i + 1);
64 r /=
static_cast<double>(i);
78template <
typename Raw>
82 if (!mu_opt)
return std::nullopt;
83 const double mu = *mu_opt;
84 if (k == 1)
return 0.0;
86 for (
unsigned i = 0; i <= k; ++i) {
88 if (!m_i)
return std::nullopt;
90 * std::pow(-mu,
static_cast<double>(k - i)) * (*m_i);
std::optional< double > centralFromRaw(unsigned k, Raw &&raw)
Central moment of order k from a raw-moment closure: .
double simpsonIntegrate(double lo, double hi, int N, F &&f)
Composite-Simpson with N panels.
double binomial(unsigned n, unsigned k)
Binomial coefficient as a double (exact for the small orders the moment expansions use).
constexpr int kSimpsonPanels
Panel count shared by every composite-Simpson quadrature over a distribution's integration range: exa...