[R] Adapt function
bolker at ufl.edu
Thu Oct 8 22:19:32 CEST 2009
Doran, Harold wrote:
> I am trying to use the adapt function in the package adapt. To make sure
> I am using it correctly, I am trying a toy example that should yield a
> result of 2/3.
> Suppose the function is f(x,y) = x*y^2 and I want to integrate over f as
> Int_0^1 Int_0^2 x*y^2 dxdy
> Where the limits of integration for y are 0 to 1 and the limits for x
> are 0 to 2. So, I tried
> ff <- function(xy) x*y^2
> adapt(2, lo = c(0,0), up = c(1,2), fun = ff)
> And this produces
>> adapt(2, lo = c(0,0), up = c(1,2), fun = ff)
> value relerr minpts lenwrk ifail
> 2 7.38275e-08 165 73 0
> Can anyone offer insight into my error?
adapt() wants a function whose first argument is a vector of parameters
(and you had your limits switched, I think).
> ff <- function(p) p*p^2
value relerr minpts lenwrk ifail
0.6666667 7.142849e-08 165 73 0
View this message in context: http://www.nabble.com/Adapt-function-tp25808121p25808382.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help