integrate() (PR#1755)
Bill.Venables@cmis.csiro.au
Bill.Venables@cmis.csiro.au
Mon, 8 Jul 2002 11:26:47 +1000
There is no bug. The error message tells you that your function gives a
result of the wrong length - that means your function should give a result
with length the same as that of the input argument, x.
Try either of the following
> integrate(function(x) 1 + 0*x, 0, 1)
> integrate(function(x) rep(1, length(x)), 0, 1)
If you spot the message in these it could be the start of a seminal lesson
on vectorization.
Bill Venables
-----Original Message-----
From: tcporco@mathepi.com [mailto:tcporco@mathepi.com]
Sent: Monday, July 08, 2002 10:33 AM
To: r-devel@stat.math.ethz.ch
Cc: R-bugs@biostat.ku.dk
Subject: integrate() (PR#1755)
Full_Name: Travis Porco
Version: 1.5.1 (6/17/2002)
OS: Suse Linux 7.1
Submission from: (NULL) (66.81.124.235)
This happens:
> integrate(function(x)1,0,1)
Error in integrate(function(x) 1, 0, 1) : evaluation of function gave a
result
of wrong length
> integrate(function(x)x^2,0,1)
0.3333333 with absolute error < 3.7e-15
> integrate(function(x){cat(x);1},0,1)
0.5 0.01304674 0.9869533 0.06746832 0.9325317 0.1602952 0.8397048 0.2833023
0.7166977
0.4255628 0.5744372 0.002171418 0.9978286 0.03492125 0.9650787 0.1095911
0.8904089
0.2186214 0.7813786 0.3528036 0.6471964Error in integrate(function(x){ :
evaluation of function gave a result of wrong length
This is clearly incorrect behavior. I included case 2 to show that some
cases
are
working correctly.
Various other conditions produce the error message indicated. Of course,
not
being able to
integrate a constant is not in itself the problem; rather, function(x)1
generates the
same error that occurs in the real problem I'm working on.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._