R/simp_int.R

Defines functions simp_int

Documented in simp_int

simp_int <- function(x, fx, n.pts = 256, ret = FALSE) {
  if (is.function(fx)) {
    fx <- fx(x)
  }
  n.x <- length(x)
  if (n.x != length(fx)) {
    stop("Unequal input vector lengths")
  }
  if (n.pts < 64) {
    n.pts <- 64
  }
  ap <- approx(x, fx, n = 2 * n.pts + 1)
  h <- diff(ap$x)[1]
  integral <- h * (ap$y[2 * (1:n.pts) - 1] + 4 * ap$y[2 * (1:n.pts)] + ap$y[2 * (1:n.pts) + 1]) / 3
  invisible(list(value = sum(integral), cdf = list(x = ap$x[2 * (1:n.pts)], y = cumsum(integral))))
}

Try the kerdiest package in your browser

Any scripts or data that you put into this service are public.

kerdiest documentation built on June 23, 2025, 5:08 p.m.