1
$\begingroup$

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

$$f(x)=I_0(x)K_0(x)-I_1(x)K_1(x)$$

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?

$\endgroup$
  • $\begingroup$ In version 11, I am unable to reproduce the plot you gave, even tho what Bill said about subtractive cancellation is correct. $\endgroup$ – J. M. will be back soon Nov 13 '19 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$ – Arturo don Juan Nov 13 '19 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$ – J. M. will be back soon Nov 13 '19 at 22:01
6
$\begingroup$

Compare

Plot[BesselI[0,x]BesselK[0,x]-BesselI[1,x]BesselK[1,x],{x,725,742}]

versus

Plot[BesselI[0,x]BesselK[0,x]-BesselI[1,x]BesselK[1,x],{x,725,742},WorkingPrecision->64]

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

Table[{BesselI[0,x],BesselK[0,x],BesselI[1,x],BesselK[1,x]},{x,725.,742.}]

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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