[R] Error in besselJ(pi/2, 1E-15)?
Leo Mada
|eo@m@d@ @end|ng |rom @yon|c@eu
Mon Dec 29 01:05:16 CET 2025
Dear R-Users,
I suspected it is a catastrophic loss of precision. Unfortunately, it popped up in an unexpected way. I was plotting some curves using the Bessel function , something like this:
curve(besselJ(x, pi/2-x), 0, 2*pi, ylim = c(-2,2), n = 101)
abline(v = pi/2, col = "red", lty = 2)
# n = 101 is the default;
Note that the error is generated for a large set of values of x:
median (besselJ(seq(0, 1, length.out = 1025), 1E-15))
# 9.38233e+14
Sincerely,
Leonard
________________________________
From: Leo Mada <leo.mada using syonic.eu>
Sent: Sunday, December 28, 2025 6:28 PM
To: Leo Mada via R-help <r-help using r-project.org>
Subject: Error in besselJ(pi/2, 1E-15)?
Dear R-Users,
besselJ(pi/2, 0)
# 0.4720012
besselJ(pi/2, 1E-14)
# 0.4720012
besselJ(pi/2, 1E-15)
# 4.720012e+14
There seems to be an error in besselJ(pi/2, eps), where eps is close to 0; although besselJ(pi/2, 0) is well behaved.
I am not an expert in the field - but it doesn't seem right.
Sincerely,
Leonard
[[alternative HTML version deleted]]
More information about the R-help
mailing list