[Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-03 Thread Ravi Varadhan
Dear All, Hans Borchers and I have been trying to compute exact derivatives in R using the idea of complex-step derivatives that Hans has proposed. This is a really, really cool idea. It gives exact derivatives with only a minimal effort (same as that involved in computing first-order

[Rd] incorrect result (41/10-1/10)%%1 (PR#13863)

2009-08-03 Thread jan . hattendorf
Full_Name: jan hattendorf Version: 2.9.0 OS: XP Submission from: (NULL) (213.3.108.185) I get an incorrect result for (41/10-1/10)%%1 [1] 1 The error did not occur with other numbers than 41 (1, 11, 21, 31, 51, ...) test - rep(NA, 1000) for(i in 1:1000){ test[i] - i/10-1/10 }

Re: [Rd] incorrect result (41/10-1/10)%%1 (PR#13863)

2009-08-03 Thread Peter Dalgaard
jan.hattend...@unibas.ch wrote: Full_Name: jan hattendorf Version: 2.9.0 OS: XP Submission from: (NULL) (213.3.108.185) I get an incorrect result for (41/10-1/10)%%1 [1] 1 The error did not occur with other numbers than 41 (1, 11, 21, 31, 51, ...) test - rep(NA, 1000) for(i

Re: [Rd] incorrect result (41/10-1/10)%%1 (PR#13863)

2009-08-03 Thread Achim Zeileis
Not a bug, just a FAQ (7.31). http://CRAN.R-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f On Sat, 1 Aug 2009, jan.hattend...@unibas.ch wrote: Full_Name: jan hattendorf Version: 2.9.0 OS: XP Submission from: (NULL) (213.3.108.185) I get an incorrect

Re: [Rd] incorrect result (41/10-1/10)%%1 (PR#13863)

2009-08-03 Thread ONKELINX, Thierry
This is not a bug. It is a case of R FAQ 7.34: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-the se-numbers-are-equal_003f ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research

Re: [Rd] incorrect result (41/10-1/10)%%1 (PR#13863)

2009-08-03 Thread Sean O'Riordain
Good morning Jan, Could this be covered off by the following? http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f Kind regards, Sean On Sat, Aug 1, 2009 at 9:05 PM, jan.hattend...@unibas.ch wrote: Full_Name: jan hattendorf Version: 2.9.0 OS: XP

Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-03 Thread Martin Becker
Dear Ravi, the inaccuracy seems to creep in when powers are calculated. Apparently, some quite general function is called to calculate the squares, and one can avoid the error by reformulating the example as follows: rosen - function(x) { n - length(x) x1 - x[2:n] x2 - x[1:(n-1)]

Re: [Rd] incorrect result (41/10-1/10)%%1 (PR#13863)

2009-08-03 Thread Petr Savicky
I get an incorrect result for (41/10-1/10)%%1 [1] 1 Note that due to rounding errors, 41/10-1/10 is formatC(41/10-1/10, digits=20) # [1] 3.9995559 Besides FAQ 7.31, related information may be found also at http://wiki.r-project.org/rwiki/doku.php?id=misc:r_accuracy Petr.

[Rd] debug: mtrace(fun, FALSE) doesn't work for me

2009-08-03 Thread Rune Schjellerup Philosof
Hi tmp - function(t=1) t+1 mtrace(tmp) mtrace(tmp) #Re-applying trace... #Error in `[[-`(`*tmp*`, 1, value = list(t + 1)) : # incompatible types (from list to expression) in [[ assignment I think this used to work on my computer. A month ago I upgraded R from r-base (2.9.0-4intrepid0) to

Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-03 Thread Hans W. Borchers
Thanks for pointing out the weak point in this computation. I tried out your suggestions and they both deliver the correct and accurate result. But as a general solution this approach is not feasible. We want to provide complex-step derivatives as a new method for computing exact gradients, for

Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-03 Thread Martin Maechler
HWB == Hans W Borchers hwborch...@googlemail.com on Mon, 3 Aug 2009 13:15:11 + (UTC) writes: HWB Thanks for pointing out the weak point in this HWB computation. I tried out your suggestions and they both HWB deliver the correct and accurate result. HWB But as a