romberg_int2d: Vectorized Two-dimensional Romberg Numerical Integration

View source: R/romberg_int2d.R

romberg_int2dR Documentation

Vectorized Two-dimensional Romberg Numerical Integration

Description

romberg_int2d performs vectorized numerical integration of a given two-dimensional function.

Usage

romberg_int2d(
  f,
  a = c(-Inf, -Inf),
  b = c(Inf, Inf),
  eps = 1e-06,
  max = 16,
  d = 5
)

Arguments

f

The function (of two variables) to integrate, returning either a scalar or a vector.

a

A two-element vector or a two-column matrix giving the lower bounds. It cannot contain both -Inf and finite values.

b

A two-element vector or a two-column matrix giving the upper bounds. It 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 2k 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::int2 by J.K. Lindsey, who adapted function from Gentleman and Ihaka (2000) Jr Comp Graph Stat 9, 491-508)

References

Gentleman and Ihaka (2000) Jr Comp Graph Stat 9, 491-508

Examples


f <- function(x,y) sin(x)+cos(y)-x^2
romberg_int2d(f, a=c(0,1), b=c(2,4))
#
fn1 <- function(x, y) x^2+y^2
fn2 <- function(x, y) (1:4)*x^2+(2:5)*y^2
romberg_int2d(fn1, c(1,2), c(2,4))
romberg_int2d(fn2, c(1,2), c(2,4))
romberg_int2d(fn1, matrix(c(1:4,1:4),ncol=2), matrix(c(2:5,2:5),ncol=2))
romberg_int2d(fn2, matrix(c(1:4,1:4),ncol=2), matrix(c(2:5,2:5),ncol=2))


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