I was trying to integrate the following function from -infinity to infinity. The answer should be 0.2, but R gives a ridiculously small number. What\'s wrong?
While in general the advice in ?integrate to explicitly specify +/-Inf as the limits is valid, it may be wrong in special cases. This is one of them.
> integrate(f, 20, 30)
0.2 with absolute error < 1.9e-06
The basic problem seems to be that your function is not smooth, in that its derivative is discontinuous at x=25. This may be fooling the algorithm, in particular its use of Wynn's epsilon method to speed up convergence. Basically there's no real substitute to knowing what your function is like, and how its behaviour could cause problems. As pointed out in the answers here, R isn't a symbolic mathematical solver so you do have to exercise more care when trying to get numerical results.