Skip to content
Back to formatted view

Raw Message

Message-ID: <20230108102705.348ae5c4@Tarkus>
Date: 2023-01-08T07:27:05Z
From: Ivan Krylov
Subject: Problem with integrate(function(x) x^3 / sin(x), -pi/2, pi/2)
In-Reply-To: <9b342177-ce55-b234-0b4f-699b4ca81b20@syonic.eu>

On Sun, 8 Jan 2023 05:24:05 +0200
Leonard Mada via R-help <r-help at 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