Adaptive Numerical Integration
Integrate a function of one variable over a finite range using a recursive adaptive method. This function is mainly for demonstration purposes.
area(f, a, b, ..., fa = f(a, ...), fb = f(b, ...), limit = 10, eps = 1e-05)
- The integrand as an
Sfunction object. The variable of integration must be the first argument.
- Lower limit of integration.
- Upper limit of integration.
- Additional arguments needed by the integrand.
- Function value at the lower limit.
- Function value at the upper limit.
- Limit on the depth to which recursion is allowed to go.
- Error tolerance to control the process.
The method divides the interval in two and compares the values given by Simpson's rule and the trapezium rule. If these are within eps of each other the Simpson's rule result is given, otherwise the process is applied separately to each half of the interval and the results added together.
- The integral from
Venables, W. N. and Ripley, B. D. (1994) Modern Applied Statistics with S-Plus. Springer. pp. 105--110.
area(sin, 0, pi) # integrate the sin function from 0 to pi.