trap: Trapezoid method

Description Usage Arguments Details Value See Also Examples

View source: R/trap.R

Description

Use the trapezoid method to integrate a function

Usage

1
trap(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

Details

The trap function uses the trapezoid 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 trapezoids. Additional options are passed to the function f when evaluating.

Value

the value of the integral

See Also

Other integration: adaptint, gaussint, giniquintile, mcint, midpt, revolution-solid, romberg, simp38, simp

Other newton-cotes: adaptint, giniquintile, midpt, romberg, simp38, simp

Examples

1
2
3
4
f <- function(x) { sin(x)^2 + cos(x)^2 }
trap(f, -pi, pi, m = 10)
trap(f, -pi, pi, m = 100)
trap(f, -pi, pi, m = 1000)

cmna documentation built on June 20, 2017, 9:08 a.m.

Search within the cmna package
Search all R packages, documentation and source code