R/simp_int.R

simp_int <-
function (x, fx, n.pts = 256, ret = FALSE) 
{
    if (inherits(fx, "function") )
        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
    return(sum(integral))
    #  invisible(list(value = sum(integral), cdf = list(x = ap$x[2 * 
    #     (1:n.pts)], y = cumsum(integral))))
}

Try the Conake package in your browser

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

Conake documentation built on June 13, 2022, 5:09 p.m.