Use the rectangle method to integrate a function

midpt(f, a, b, m = 100)

Arguments

f

function to integrate

a

the a-bound of integration

b

the b-bound of integration

m

the number of subintervals to calculate

Value

the value of the integral

Details

The midpt function uses the rectangle method to calculate the integral of the function f over the interval from a to b. The parameter m sets the number of intervals to use when evaluating the rectangles. Additional options are passed to the function f when evaluating.

See also

Other integration: adaptint(), gaussint(), giniquintile(), mcint(), revolution-solid, romberg(), simp38(), simp(), trap()

Other newton-cotes: adaptint(), giniquintile(), romberg(), simp38(), simp(), trap()

Examples

f <- function(x) { sin(x)^2 + cos(x)^2 }
midpt(f, -pi, pi, m = 10)
#> [1] 6.283185
midpt(f, -pi, pi, m = 100)
#> [1] 6.283185
midpt(f, -pi, pi, m = 1000)
#> [1] 6.283185