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

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Sun Jan 8 08:27:05 CET 2023


On Sun, 8 Jan 2023 05:24:05 +0200
Leonard Mada via R-help <r-help using r-project.org> wrote:

> pracma::integral(function(x) x^3 / sin(x), -pi/2, pi/2 )
> # 3.385985

Note that at least one implementation used by pracma::integral has the
same problem:

pracma::integral(function(x) x^3/sin(x), -pi/2, pi/2, no_intervals=7)
# [1] NaN
# Warning:
# In .gkadpt(f, a, b, tol = tol) : Infinite or NA function value
# encountered.

You just have to be less lucky to have it evaluate the function at 0.
By default, the subdivision strategy used by pracma::integral combined
with the default number of intervals leaves the special point on the
edge of the interval, where the function happens not to be evaluated.

-- 
Best regards,
Ivan



More information about the R-help mailing list