I am doing a calculation which involves the numerical evaluation of the following function:


where $I_{\nu}(x)$ and $K_{\nu}(x)$ are the modified Bessel functions. By the asymptotic expansion quoted in DLMF, I expect the following leading-order asymptotic expansion:

$$\left.f(x)\right._{x\rightarrow\infty}\sim \frac{1}{4x^3}$$

However when I plot this function, I get strange sporadic behavior around $x\in(725,742)$. As far as I can tell, I get no such error anywhere else. This is almost certainly numerical error.

enter image description here

Question(s): What exactly is this? Is there any way to avoid it?

  • $\begingroup$ In version 11, I am unable to reproduce the plot you gave, even tho what Bill said about subtractive cancellation is correct. $\endgroup$ Nov 13, 2019 at 6:53
  • $\begingroup$ I'm using version 12.0. Are you saying that you have no errors, even without manually changing the working precision? $\endgroup$ Nov 13, 2019 at 20:35
  • $\begingroup$ Here is a screenshot from the computer I am currently borrowing. Now that I have tried the version in the cloud, I can see that the disastrous subtractive cancellation is now at play. $\endgroup$ Nov 13, 2019 at 22:01

1 Answer 1






If you are curious about why this might be happening then you could inspect


and see the magnitudes of numbers that you are subtracting and getting results near 10^-9 when you have only a handful of digits using the default MachinePrecision.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.