Dear S-plus list,
I have come
across a problem with the function "integrate".
As demonstrated
in the example below the tolerance level in one call
to integrate can
be affected by another (nested) call to the same
function. I have
been in contact with S-plus support at Insightful
and I got the
following reply:
"Yes, I can
reproduce this behavior. It shouldn't be like that. It's a bug
relating to
object in the global scope that is retained when abs.tol or
rel.tol are being
used. I am forwarding this to our headquarters.
I have been unable
to fix the problem myself. I have tried, for example,
to work with two
versions of integrate: the original plus a copy where I
renamed all (named)
arguments in integrate - just to try to avoid partiel
matching problems
as reported by others on this list. I have also tried
to rename some of
the key variables and functions within integrate.
Essentially, I
cannot identify where the assignment to the "object in
the global scope"
takes place. Any help with this matter will be
greatly
appreciated.
- Claus
System: S-plus
7.0 on PC with windows XP
#-------------------------------------------------------
# EXAMPLE
#-------------------------------------------------------
# Integrate
tolerance "crosstalk"
func.plain <-
function(x){
sin(1/x)
}
func2 <-
function(x){
junk <-
integrate(function(tttt){tttt^4},1,2)
sin(1/x)
}
func3 <-
function(x){
junk <-
integrate(function(tttt){tttt^4},1,2, abs.tol=1000, rel.tol=1)
sin(1/x)
}
F1 <-
integrate(func.plain,0.01,1)[1:4]
F2 <-
integrate(func2 ,0.01,1)[1:4]
F3 <-
integrate(func3 ,0.01,1)[1:4]
F4 <-
integrate(func.plain,0.01,1)[1:4]
rbind(F1,F2,F3,F4)
# Output:
# integral
abs.error subdivisions message
#F1 0.5039819
0.0000822048 14 normal termination
#F2 0.5039819
0.0000822048 14 normal termination
#F3 0.5273663
0.2707368 2 normal termination
#F4 0.5039819
0.0000822048 14 normal termination
# PROBLEM: F3 is
different from F1, F2 and F4
# Q: Why?
# A: Because
func3 includes a call to integrate with new
# parameters for
abs.tol and rel.tol
#-------------------------------------------------------
----------------------------------------
Claus E. Andersen
Risoe National
Laboratory
Radiation
Research Department
Building 201
DK-4000 Roskilde,
Denmark
Phone: +45 4677
4912 (direct)
Fax: +45 4677
4959
e-mail:
claus.andersen@risoe.dk <mailto:claus.andersen@risoe.dk>
web: http://www.risoe.dk/nuk/nuk-clan.htm
-----------------------------------------