# Integration (with singularity) of Hankel functions

I need to calculate an integral like

B[a_, t_] :=  1/(2 I) (t)^(9/2) NIntegrate[ x^(1/2) (HankelH1[a, x]^3 HankelH2[a, t]^3 -  HankelH2[a, x]^3 HankelH1[a, t]^3), {x, t, 2}, WorkingPrecision -> 40,  MinRecursion -> 10,  MaxRecursion -> 20] // N


$t$ ranges from Exp[-60] to 1. $a$ ranges from 0 to 1.5. Notice that $t$ appears in the lower integration limit, in the argument of Hankel functions and as $t^{9/2}$. Moreover, the integrand is purely imaginary. The integrand diverges in the limit $t\rightarrow 0$. For $a\equiv1.5$, the analytical result predicts a logarithmic divergence for $t\rightarrow 0$. The problem is that

B[1.5,Exp[-20]]=5.5
B[1.5,Exp[-30]]=-5.89145*10^22


I have tried to increase the precision, but results do not change. I suspect that the Hankel functions are evaluated with too low precision and hence I get wrong results. You can see the (analytical) logarithmic divergence plotting

G[x_, a_, t_] := (t)^(9/2) Im[x^(1/2) (HankelH1[a, x]^3 HankelH2[a, t]^3-HankelH2[a, x]^3 HankelH1[a, t]^3)]
LogLinearPlot[{G[x, 1.5, Exp[-20]], 1/x}, {x, Exp[-10], 2}, PlotRange -> {{0, Exp[-10]}, {0, 100}}, PlotPoints -> 10000]


I am interested in the behavior of the function both for fixed $a$ and for fixed $t$ (but the former is more important).

How can I evaluate this integral? Thanks in advance to those who will try to help me.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Aug 2 '16 at 16:42

Clear[B]

Add an optional third argument to control the WorkingPrecision

B[a_?NumericQ, t_?NumericQ, wp_:40] :=
1/(2 I) (t)^(9/2) NIntegrate[
x^(1/2) (HankelH1[a, x]^3 HankelH2[a, t]^3 -
HankelH2[a, x]^3 HankelH1[a, t]^3), {x, t, 2}, WorkingPrecision -> wp,
MinRecursion -> 10, MaxRecursion -> 20] // N


If you provide input values with $MachinePrecision then the calculation will be done with $MachinePrecision. Either input exact numbers

B[3/2, Exp[-20]]

(*  5.46327  *)


or high arbitrary precision numbers (EDIT: see Precision: "Numbers entered in the form digitsp are taken to have precision p.")

B[1.545, Exp[-20]]

(*  5.46327  *)

B[3/2, Exp[-30]]

(*  8.0434  *)

B[1.560, Exp[-30], 50]

(*  8.0434  *)

• Thank you very much! This solves my issues. I admit, I'm a newbie. – Xepto Aug 2 '16 at 19:12
• I have a question about your answer. The introduction of "?NumericQ" makes the calculation more efficient? – Xepto Aug 2 '16 at 19:16
• @Xepto - because the definition of B uses a numerical technique (NIntegrate`), it can only be successfully evaluated for numeric inputs. The inputs are restricted to being numeric to avoid attempting a symbolic evaluation. – Bob Hanlon Aug 2 '16 at 19:23