philsupertramp/game-math
|
Functions | |
std::pair< double, std::vector< double > > | quad_adaptive_rec (const std::function< double(double)> &fun, const double &a, const double &b, const double &tol, const double &hMin, std::vector< double > &nodes, Matrix< double > &values) |
std::pair< double, std::vector< double > > integration::quad_adaptive_rec | ( | const std::function< double(double)> & | fun, |
const double & | a, | ||
const double & | b, | ||
const double & | tol, | ||
const double & | hMin, | ||
std::vector< double > & | nodes, | ||
Matrix< double > & | values | ||
) |
Recursive implementation of numerical quadrature to approximate a given exact integral uses Simspon's - and Trapezoid Rule for approximation.
The Trapezoid Rule is given as
\begin{equation} \int \limits_a^b f(x) dx \approx T(x) = \frac{b - a}{2} \left[ f(a) + f(b) \right] \end{equation} Simpson is given as \begin{equation} \int \limits_a^b f(x) dx \approx S(x) = \frac{ b - a }{ 6 } \left[ f(a) + 4 f \left( \frac{a+b}{2} \right)
For approximation a tolerance is given, which is used to compare against the local error of approximation. The error is calculated as $$ | S - T | $$ Whenever the error reaches the threshold of tol, the method has succeeded and the result of Simpson's rule is returned.
Note if (b-a) < hMin we reached the minimal step with and haven't found an satisfying result, therefore the algorithm exits with error code 1
fun | given Function to calculate the exact integral of |
a | left boundary of integral |
b | right boundary of integral |
tol | local tolerance |
hMin | minimum distance between a and b |
nodes | already visited nodes on the integral ("x-axis") |
values | already calculated function values for visited nodes |