simpson_num_integr {nhppp}R Documentation

Simpson's method to integrate a univariate function.

Description

Simpson's method to integrate a univariate continuous function. Faster that R's integrate() and precise enough, but does not do any checks. The error is at most ⁠M (b-a)^5/(180 n^4)⁠ where M is the maximum of the fourth derivative of the integrand in the interval ⁠[a, b]⁠.

Usage

simpson_num_integr(f, a, b, n)

Arguments

f

function that takes a single argument

a

the lower limit of integration

b

the upper limit of integration

n

integer, number of integration points with a and b

Value

numeric, the integration value examples #expect 1 simpson_num_integr(sin, 0, pi/2, 100) #max error for simpson_num_integr(sin, 0, pi/2, 100) is 5.312842e-10 1 * (pi/2 - 0)^5/(180 * 100^4)


[Package nhppp version 0.1.3 Index]