-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide relative tolerances for besselj1(x) and besselj0(x) near zeros #22
Comments
It looks like this issue is limited to the asymptotic expansions for large arguments. |
yeah. Accuracy near zeros of the function is somewhat fundamentally hard. I think the best answer might be to detect whether |
Hmmm well we can approximate their zeros fairly quickly.... x - pi/4 - evalpoly(inv(x)^2, (-1/8, 25/384, -1073/5120, 375733/229376, -55384775/2359296, 24713030909/46137344, -7780757249041/436207616)) = (m-1/2)*pi Where |
Looking at this a bit more. It is probably best to absorb the This problem can then be reduced to simply computing An example close to a root is (x, xn) = (46.341188371661815, -0.002696731212363751) So then julia> (cos(x) * (cos(xn) + sin(xn)) + sin(x)*(cos(xn) - sin(xn)))
-1.2212453270876722e-15 |
Or more simply we must calculate cos(x + xn) + sin(x + xn) more accurately. Near roots |
Isn't this just |
I've been trying to reconcile why the SpecialFunctions.jl implementation is better near the zeros. They suggest using this version. https://github.com/JuliaMath/openlibm/blob/0edf8d6929efc09c33e1e3342483a33dcd7517d1/src/e_j0f.c#L116-L124 But yes essentially we want to compute |
So for our code replacing these lines with a = SQ2OPI(T) * sqrt(xinv) * p
xn = xinv * q
b = 0.7071067811865475 * (Float64(cos(BigFloat(x) + BigFloat(xn)) + sin(BigFloat(x) + BigFloat(xn)))) fixes this issue but obviously that's cheating 😄 |
This is improved by #88. Which I think closes this issue. |
besselj0(x)
andbesselj1(x)
are less accurate than in some cases compared to SpecialFunctions. It is necessary to have as high as accuracy as possible here to use in recurrence.A particularly egregious example is...
besselj0 error
besselj1 error
The text was updated successfully, but these errors were encountered: