double simpsons(Function func, double a, double b, double tol, int nmax);
Returns an approximation to the integral of the function func from a to b. The relative error of the approximation is no more than tol. nmax is the maximum number of iteration to perform to reach this error level. Integration is performed using Simpson's rule.
Parameters:
func | Function to integrate. |
---|---|
a | Lower bound of integration. |
b | Upper bound of integration. |
tol | Maximum error tolerance. |
nmax | Maximum number of iterations. |
Returns:
Integral of func from a to b.
Usage:
double sine(double x) { return sin(x); }
double s = simpsons(sine, 0.0, 3.14, 5e-10, 20);
Header:
#include "integrate.h"
See Also:
Function