0
$\begingroup$

I have a two-dimensional integral that I'd like to evaluate numerically. I would like to be able to do this as quickly as possible (as I have to calculate many similar integrals). It takes the form $$ \int_{0}^{1}\int_{0}^{1}f(x,y)H_{0}^{(1)}(\sqrt{4(cos(x)-cos(y))^{2}+(sin(x)-sin(y))^{2}})dxdy $$ where $H_{0}^{(1)}(z)$ is the zero order Hankel function of the first kind and $f(x,y)$ is bounded, but is quite complicated itself: $$ f(x,y)=\left(-i\sqrt{4sin^{2}(x)+cos^{2}(x)}+\frac{3cos(x)sin(x)}{\sqrt{4sin^{2}(x)+cos^{2}(x)}}\right)\left(i\sqrt{4sin^{2}(y)+cos^{2}(y)}+\frac{3cos(y)sin(y)}{\sqrt{4sin^{2}(y)+cos^{2}(y)}}\right)e^{-ix}e^{iy} $$ The Hankel function has a logarithmic singularity for small values of its argument. The singularity lies along the line $y=x$ of the integrand. I start from the NIntegrate command as follows:

NIntegrate[f[x,y] HankelH1[0,Sqrt[4(Cos[x]-Cos[y])^2+(Sin[x]-Sin[y])^2]],{x,0,1},{y,0,1}]

How should I modify this to evaluate the integral most efficiently? i.e. what settings associated with NIntegrate should I use? All the examples I've read about online apply to slightly different problems. As it stands the integral takes too long and complains of errors about convergence being too slow. Thanks in advance for any help.

$\endgroup$
1
  • 2
    $\begingroup$ Post all Mathematica code no LaTex? Where is:f[x,y] ?.It's impolite of you to expect an answer without providing the code to reproduce. $\endgroup$ Jul 7, 2020 at 16:49

1 Answer 1

3
$\begingroup$

Update: If we tell Mathematica about the singularity along $y=x$ it's much faster and the convergence issues go away with the default method:

NIntegrate[
  f[x, y] HankelH1[0, 
    Sqrt[4 (Cos[x] - Cos[y])^2 + (Sin[x] - Sin[y])^2]],
  {x, 0, 1}, {y, 0, 1}, Exclusions -> (y == x)] // Timing
(* result: {0.375, 2.08433 - 1.89171 I} *)

The "LocalAdaptive" method is a bit faster than the "GlobalAdaptive" it chooses by default:

g[a_?NumericQ, b_?NumericQ] := Sqrt[4 Sin[a]^2 + Cos[b]^2]
h[a_?NumericQ, b_?NumericQ] := 3 Cos[a] Sin[b]
f[x_?NumericQ, y_?NumericQ] :=
 (-I g[x, x] + h[x, x]/g[x, x]) (I g[y, y] + h[y, y]/g[y, y]) Exp[I y - I x]

NIntegrate[
 f[x, y] HankelH1[0, 
   Sqrt[4 (Cos[x] - Cos[y])^2 + (Sin[x] - Sin[y])^2]],
   {x, 0, 1}, {y, 0, 1}, Method -> "LocalAdaptive"]//Timing
(* result: {22.75, 2.08433 - 1.89169 I} *)

If you need quick and rough estimates try "AdaptiveQuasiMonteCarlo" which completes in under half a second:

(* result: {0.390625, 2.08553 - 1.88752 I} *)

You may want to take a look at all the options available: http://reference.wolfram.com/language/tutorial/NIntegrateIntegrationStrategies.html

$\endgroup$
4
  • $\begingroup$ The integral of f[x, y] HankelH1[0, Sqrt[4 (Cos[x] - Cos[y])^2 + (Sin[x] - Sin[y])^2]] over the square is an improper double integral. I don't know any numeric method to calculate it. The work of the Exclusions option is not explained in reference.wolfram.com/language/tutorial/… . $\endgroup$
    – user64494
    Jul 7, 2020 at 19:55
  • $\begingroup$ @user64494 sorry, 1) who are you? Are you @Chris? 2) There's nothing wrong with the integral, 3) It is explained - it's literally right there: wolfram.com/xid/0far7me5ywb23ren50sgk-bs9aib $\endgroup$
    – flinty
    Jul 7, 2020 at 19:58
  • $\begingroup$ This is not an improper integral. Series shows, the integrand goes with I Log[x-y] towards the singularity. This can be integrated regularily Integrate[I Log[x - y], {x, 0, 1}, {y, 0, 1}] . $\endgroup$
    – Akku14
    Jul 8, 2020 at 6:30
  • $\begingroup$ Ha, I'm certainly not user64494. The integral is not improper. $\endgroup$
    – Chris
    Jul 8, 2020 at 6:58

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.