vc_integrate: Approximate a signed definite integral

View source: R/integrate.R

vc_integrateR Documentation

Approximate a signed definite integral

Description

Approximate a signed definite integral

Usage

vc_integrate(
  f,
  interval,
  method = c("trapezoid", "simpson", "adaptive"),
  n = 32L,
  abs_tol = 1e-08,
  rel_tol = 1e-08,
  subdivisions = 100L
)

Arguments

f

Deterministic function accepting a real scalar and returning one finite real scalar. Vectorization is not required.

interval

Two finite real bounds, allowing reversed or equal bounds.

method

Quadrature rule: trapezoid, Simpson, or adaptive QUADPACK through stats::integrate(). Improper infinite bounds are not supported.

n

Initial number of equal cells for fixed rules; positive integer, even and at least two for Simpson. Ignored by the adaptive rule.

abs_tol, rel_tol

Nonnegative finite absolute and relative diagnostic tolerances; at least one must be positive. Adaptive integration also applies the tolerance restrictions of stats::integrate().

subdivisions

Positive integer maximum adaptive subinterval count; ignored by fixed rules.

Details

Fixed rules evaluate n and 2*n cells and return the finer result. Richardson diagnostics use abs(fine-coarse)/3 for trapezoids and /15 for Simpson. They assume sufficiently smooth functions and an asymptotic error regime; aliasing or missed narrow features can make them misleading. tolerance_met is only a numerical diagnostic, never a certified bound. Adaptive status preserves QUADPACK failure messages without claiming convergence. Evaluation errors and nonfinite sampled values/results stop. Scalar-only functions are supported. Reversed bounds negate the integral; equal bounds return zero without evaluating f. Integrals are signed, not geometric areas. No method proves integrability or discovers every singularity; split known discontinuities/singularities explicitly.

Value

Plain list with type, interval, method, estimate, error_estimate, tolerance, tolerance_met, status, message, n (finest fixed cell count or NA), table (finest fixed nodes, values, signed weights/contributions), refinement (coarse/fine estimates), subdivisions and note. Adaptive internal nodes are unavailable and table/refinement are NULL.

Examples

(function(x)x^2) |> vc_integrate(c(0,2),method="simpson")
vc_integrate(sin,c(0,pi),method="adaptive")

vectorialcalculus documentation built on Nov. 17, 2026, 1:09 a.m.