I don't think that the code behind adaptIntegrate
will help you what's happen. You can type in a console adaptIntegrate
and you will get the code. It is essentially a call to a C algorithm.
In order to understand what it is happen , I think you need before to understand what you integrate. Try to simplify your function, to see his definition domain.
INV_PI <- 1/pi fun <- function(X){ scale <- -1*((n+2)/(2*pi*(L^2)))*INV_PI^2 *acos(d/(d+r)) res <- scale*asin(sqrt((pi*area)/X))* (1+((X/L)^2))^(n/2) sqrt(prod(res)) }
Here the 2 terms on X , but only one can produce problem.
asin(sqrt((pi*area)/X))
asin
is defined only between[-1,1], sqrt
is defined only for positive numbers.
So here fun is defined between [pi*area,INF]
, and you have to integrate in this domain.
for example :
low.Lim <- pi*area
doubleintegration <- function()
{
integrand <- adaptIntegrate(fun, lowerLimit=c(low.Lim,low.Lim),
upperLimit=c(200*low.Lim,200*low.Lim))
return(integrand$integral)
}
doubleintegration()
[1] 0.1331089