Skip to content

Problem with integrate(function(x) x^3 / sin(x), -pi/2, pi/2)

1 message · Andrew Simmons

#
`subdivisions` is the maximum number of subintervals. Looking here

https://github.com/wch/r-source/blob/79298c499218846d14500255efd622b5021c10ec/src/appl/integrate.c#L1275

I'm not surprised that changing `subdivisions` has no effect on the
outcome. The integration method from {pracma} might work, maybe it
never calculates the function at 0, maybe it's using some alternate
method. Or maybe it did calculate f(0) and got NaN and just assumed
that the limit converged. Maybe that's a fair assumption, and maybe
it's not.

However:

integrate(function(x) ifelse(x == 0, 0, x^3/sin(x), -pi/2, pi/2)

works perfectly fine and is a better function definition anyway.
`integrate` in the {stats} package is unlikely to change, so use the
alternate function definition or use {pracma}.
On Sat, Jan 7, 2023 at 10:41 PM Leonard Mada <leo.mada at syonic.eu> wrote: