34 throw Elements::Exception() <<
"Simpson's Rule integration is define only for order bigger than 2";
38 double h = (max - min) /
N;
40 double partial_sum = 0;
41 for (
int i = 3;
i <
N - 2;
i++) {
42 partial_sum += function(min +
i *
h);
45 partial_sum += 0.375 * (function(min) + function(max));
46 partial_sum += 7. * (function(min +
h) + function(max -
h)) / 6.;
47 partial_sum += 23. * (function(min + 2. *
h) + function(max - 2 *
h)) / 24.;
49 return partial_sum *
h;
54 throw Elements::Exception() <<
"Simpson's Rule integration with recursion is define only for order bigger than 3";
58 double h = (max - min) /
N;
60 double partial_sum = 0;
62 for (
int j = 1;
j <
N / 2 - 1;
j++) {
64 partial_sum += function(min +
i *
h);
67 partial_sum += 7. * (function(min +
h) + function(max -
h)) / 6.;
68 partial_sum -= 5. * (function(min + 2. *
h) + function(max - 2. *
h)) / 24.;
69 partial_sum += (function(min + 4. *
h) + function(max - 4. *
h)) / 24.;
Interface class representing a function with an arbitrary number of parameters.
double operator()(const Function &function, double min, double max, int order)
Integrate a function between min and max using a mesh of 2^order steps. order>=3.
std::array< std::vector< double >, N > Coordinates
Used to pass the grid coordinates to interpn. Internally will make a copy of the required values.