philsupertramp/game-math
Loading...
Searching...
No Matches
Functions
integration Namespace Reference

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)
 

Function Documentation

◆ quad_adaptive_rec()

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)

  • f(b) \right] \end{equation}

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

Parameters
fungiven Function to calculate the exact integral of
aleft boundary of integral
bright boundary of integral
tollocal tolerance
hMinminimum distance between a and b
nodesalready visited nodes on the integral ("x-axis")
valuesalready calculated function values for visited nodes
Returns
approximation of given exact integral.