Learn R Programming

broman (version 0.38-2)

simp: Numerical integration

Description

Perform numerical integration by Simpson's rule or the trapezoidal rule.

Usage

simp(f, a, b, tol=1e-8, max.step=1000, ...)
trap(f, a, b, tol=1e-8, max.step=1000, ...)

Arguments

f
The integrand; must be a vectorized function.
a
Lower limit of integration.
b
Upper limit of integration.
tol
Tolerance for choosing the number of grid points.
max.step
Log base 2 of the total number of grid points.
...
Other arguments passed to the integrand, f.

Value

  • The integral of f from a to b.

Details

Iterately doubles the number of grid points for the numerical integral, stopping when the integral decreases by less than tol.

References

Press et al. Numerial recipes in C.

See Also

integrate

Examples

Run this code
f <- function(x) x*x*(1-x)*sin(x*x)
I1 <- trap(f,0,2)
I2 <- simp(f,0,2)

Run the code above in your browser using DataLab