5
$\begingroup$

I know similar questions have been asked before about bugs in Integrate, but I'm not sure what the particular problem is here (and whether or not there is indeed a bug). When I perform the integral:

Integrate[Sin[k/2]*Exp[-n*Sin[k/2]], {k, 0, Pi}]

I get the answer:

π (-BesselI[1, n] + StruveL[-1, n])

From the following plot, however, one can see that this differs strongly from the numerical result for approximately $n>37$:

DiscretePlot[{π (-BesselI[1, n] + StruveL[-1, n]),   
NIntegrate[Sin[k/2]*Exp[-n*Sin[k/2]], {k, 0, Pi}]}, {n, 1, 50}]

I believe the numerical answer is correct in this case by inspecting the area under the following plot:

Manipulate[  Plot[Sin[k/2]*Exp[-n*Sin[k/2]], {k, 0, Pi}, PlotRange ->
All], {n, 1,    50}]

Any ideas about what is going on here (and how I can get a correct symbolic result)? Thanks!

$\endgroup$
2
  • 3
    $\begingroup$ It's a precision issue, meaning that machine precision is giving incorrect results. Give the DiscretePlot the option WorkingPrecision->16 to see a correct result. $\endgroup$
    – Carl Woll
    Commented Aug 31, 2018 at 18:56
  • 1
    $\begingroup$ Could you please update title to reflect real pb $\endgroup$
    – chris
    Commented Sep 2, 2018 at 9:30

1 Answer 1

9
$\begingroup$

It's a precision issue. Machine precision computations have no precision tracking, so computations using machine precision can be completely wrong. If you use arbitrary precision numbers, than Mathematica will track the numbers and produce results whose precision is validated. So, give DiscretePlot the WorkingPrecision option to work with arbitrary precision numbers:

DiscretePlot[
    {
    π (-BesselI[1,n]+StruveL[-1,n]),
    NIntegrate[Sin[k/2]Exp[-n Sin[k/2]],{k,0,Pi}]
    },
    {n,1,50},
    WorkingPrecision->10
]

enter image description here

$\endgroup$

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.