romberg_int1d: Vectorized One-dimensional Romberg Numerical Integration

View source: R/romberg_int1d.R

romberg_int1dR Documentation

Vectorized One-dimensional Romberg Numerical Integration

Description

romberg_int1d performs numerical romberg integration of 1-dimensional functions. Vectorized to handle several functions at once. See examples.

Usage

romberg_int1d(f, a = -Inf, b = Inf, eps = 1e-04, max = NULL, d = NULL)

Arguments

f

The function (of one variable) to integrate, returning either a scalar or a vector.

a

A scalar or vector (only Romberg) giving the lower bound(s). A vector cannot contain both -Inf and finite values.

b

A scalar or vector (only Romberg) giving the upper bound(s). A vector cannot contain both Inf and finite values.

eps

Precision.

max

The maximum number of steps, by default set to 16.

d

The number of extrapolation points so that 2d is the order of integration, by default set to 5; d=2 is Simpson's rule.

Value

The vector of values of the integrals of the function supplied.

Author(s)

Bruce Swihart (based on rmutil::int by J.K. Lindsey.)

Examples


f <- function(x) sin(x)+cos(x)-x^2
romberg_int1d(f, a=0, b=2)

#
f <- function(x) exp(-(x-2)^2/2)/sqrt(2*pi)
romberg_int1d(f, a=0:3)
romberg_int1d(f, a=0:3, d=2)
1-pnorm(0:3, 2)
#
f <- function(x) dnorm(x)
romberg_int1d(f, a=-Inf, b=qnorm(0.975))

# NOTE: see \code{rmutil::int} for TOMS614.

swihart/gnlrim documentation built on Oct. 18, 2023, 8:29 p.m.