This post is my first in this Mathematica community. Thanks to all in advance who contribute to this site's success and to its users' learning experiences.

My problem is such that plotting a function is taking a painfully long time (and I have multiple plots for similar functions). I am hoping someone can offer suggestions to speed things up. Currently the plot takes more than 1 hour to finish. The image below is clipped from Mathematica.

Fk = Re[HankelH2[1, k]/(HankelH2[1, k] + I HankelH2[0, k])]


I was thinking about using a Taylor Series expansion for Sin[k s], which would sacrifice exactness for speed. However my gut tells me that it's the Hankel funtions that are slowing down the plot calculations. What can I do?

  • $\begingroup$ Assuming[k > 0, FullSimplify[FunctionExpand[Re[HankelH2[1, k]/(HankelH2[1, k] + I HankelH2[0, k])]]]] converts your function entirely in terms of Bessel functions. $\endgroup$ Oct 2, 2016 at 3:46

1 Answer 1


Notice that your analytic integration using Integrate didn't produce an analytic result, so I see no reason why not to NIntegrate:

ϕ[s_] := 2/π NIntegrate[Fk/k Sin[k s], {k, 0, Infinity}]

plot = Plot[ϕ[s], {s, 0, 25}]; // AbsoluteTiming

{0.720724, Null}


enter image description here

  • $\begingroup$ Great, thank you. Yes I did specify that it takes more than an hour, and your answer is so much faster. $\endgroup$
    – Engenuity
    Oct 1, 2016 at 22:50
  • $\begingroup$ Sir, I'm having trouble again with another function: CGk = Ck (BesselJ[0, k] - I BesselJ[1, k]) + I BesselJ[1, k];FGk = Re[CGk];GGk = Im[CGk]; \[Psi] = 2/Pi NIntegrate[((FGk - GGk )/k Sin[k] Sin[k s]), {k, 0, Infinity}];\[Psi]plot = Plot[\[Psi], {s, 0, 25}, PlotRange -> {{0, 25}, {0, 1}} ] Any tips? $\endgroup$
    – Engenuity
    Oct 2, 2016 at 2:43

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.