From apjaworski@mmm.com  Mon Jul  8 02:54:18 2002
From: apjaworski@mmm.com (apjaworski@mmm.com)
Date: Sun, 7 Jul 2002 20:54:18 -0500
Subject: integrate() (PR#1755)
Message-ID: <OFE7C3A3BF.88C529CC-ON86256BF0.000954B4@mmm.com>


I think people should read the documentation more carefully before sending
e-mail to R-bugs to make sure that they understand their problem correctly.
If in doubt, the problem should be reported to the R-help list.

I do not think there is anything wrong with integrate.  Here is a relevant
excerpt from the man page:

>      f: An R function taking a numeric first argument and returning a
>         numeric vector the same length. Returning a non-finite
>         element will generate an error.

This simply means that the function has to be properly vectorized.  Your
first example - the constant function - is not.  If you replaced it with
something like

      integrate(function(x) rep(1, length(x)), 0, 1)

integrate would work properly.

Your second function works correctly since x^2 returns a vector result of
the same length as x.  The last one is really strange.  I think integrate
should return an error message in this case.

Andy

__________________________________
Andy Jaworski
Engineering Systems Technology Center
3M Center, 518-1-01
St. Paul, MN 55144-1000
-----
E-mail: apjaworski@mmm.com
Tel:  (651) 733-6092
Fax:  (651) 736-3122


|---------+----------------------------->
|         |           tcporco@mathepi.co|
|         |           m                 |
|         |                             |
|         |           07/07/2002 19:32  |
|         |                             |
|---------+----------------------------->
  >-----------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                             |
  |      To:       r-devel@stat.math.ethz.ch                                                                                    |
  |      cc:       R-bugs@biostat.ku.dk                                                                                         |
  |        (bcc: Andrzej P. Jaworski/US-Corporate/3M/US)                                                                        |
  |      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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


integrate() (PR#1755)
apjaworski@mmm.com