Skip to content
Prev 56668 / 63421 Next

[r-devel] integrate over an infinite region produces wrong results depending on scaling

integrate(f, xmin, xmax) will have problems when f(x) is 0 over large parts
of (xmin,xmax).  It doesn't have any clues to where the non-zero regions
are.  It computes f(x) at 21 points at each step and if all of those are
zero (or some other constant?) for a few steps, it calls it a day.  If you
can narrow down the integration interval to the interesting part of the
function's domain you will get better results.

By the way, here is a way to see where integrate(f) evaluates f()  (the
keep.xy=TRUE argument doesn't seem to do anything).
{
    n_calls <- 0
    x_args <- list()
    other_args <- list()
    value <- list()
    function(x, ...) {
        n_calls <<- n_calls + 1
        x_args[[n_calls]] <<- x
        other_args[[n_calls]] <<- list(...)
        v <- f(x, ...)
        value[[n_calls]] <<- v
        v
    }
}
List of 5
 $ value       : num 1.5
 $ abs.error   : num 0.000145
 $ subdivisions: int 2
 $ message     : chr "OK"
 $ call        : language integrate(f = DF <- debugIntegrate(f), lower =
-Inf, upper = 0, numstab = sc)
 - attr(*, "class")= chr "integrate"
"Scaled f", bty = "n")
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sun, Apr 14, 2019 at 5:13 AM Andre? V. Kostyrka <andrei.kostyrka at uni.lu>
wrote: