Skip to contents

IntegralProblem(f, domain, p) asks for the integral of f(u, p) over domain = c(lb, ub) (vectors lb and ub give a box; infinite bounds are allowed). IntegralFunction(f) is the integrand, BatchIntegralFunction(f) an integrand evaluated at many points at once (f(U, p) with one point per column of U, returning one value or column per point). SampledIntegralProblem(y, x, dim) integrates sampled values y over the points x (along dimension dim of an array y).

Usage

IntegralFunction(f, integrand_prototype = NULL)

BatchIntegralFunction(f, integrand_prototype = NULL, max_batch = 1000L)

IntegralProblem(f, domain, p = numeric(), ...)

SampledIntegralProblem(y, x, dim = NULL, ...)

IntegralSolution(
  u,
  resid = NA_real_,
  retcode = "Success",
  prob = NULL,
  alg = NULL
)

TrapezoidalRule()

SimpsonsRule()

Arguments

f

Integrand.

integrand_prototype, max_batch

Options of the Julia signature.

domain

Bounds c(lb, ub) or list(lb, ub).

p

Parameters.

...

Options passed to solve().

y, x, dim

Sampled values, points and dimension.

u, resid, retcode

Solution fields.

prob, alg

A problem and an algorithm.

Value

A problem, a function, an algorithm or a solution.

Details

solve(prob) integrates: one dimension adaptively with Gauss-Kronrod quadrature (stats::integrate()), several dimensions by nested quadrature; vector valued integrands are integrated per component. solve(sampled, alg) uses the trapezoidal rule (TrapezoidalRule(), the default) or Simpson's rule (SimpsonsRule()). The result is an IntegralSolution with u (the integral), resid (the error estimate) and retcode. Options: abstol, reltol (default 1e-8), maxiters.

Examples

solve(IntegralProblem(function(x, p) exp(-x^2), c(-Inf, Inf)))$u
#> [1] 1.772454
solve(IntegralProblem(function(x, p) x[1] * x[2], list(c(0, 0), c(1, 2))))$u
#> [1] 1
x <- seq(0, pi, length.out = 101)
solve(SampledIntegralProblem(sin(x), x), SimpsonsRule())$u
#> [1] 2