0
$\begingroup$

I have a complicated integral function that I'm trying to evaluate, which will have to be done numerically. I wanted to try a simpler one first, one that has an analytic form, because I could check the answer.

The version FT I defined with Integrate works fine.

w0 = Sqrt[2*Pi*zR/(Pi*k)];
zR = 1;
k = 2*Pi/(532*10^-9);
w[z_] := Sqrt[w0^2*(1 + (z/zR)^2)]
f[x_, y_, z_] := Sqrt[2/Pi]*1/w[z]*Exp[-(x^2 + y^2)/(w[z]^2)]

FT[kx_, ky_, z_] := 
  1/(2*Pi)*Integrate[f[x, y, z]*Exp[-I*kx*x - I*ky*y], {x, -∞, ∞}, {y, -∞, ∞}]
FT[1, 1, 1]

However, when I use NIntegrate in place of Integrate, I get an error and no answer.

FT[kx_, ky_, z_] :=  
  1/(2*Pi)*NIntegrate[f[x, y, z]*Exp[-I*kx*x - I*ky*y], {x, -∞, ∞}, {y, -∞, ∞}]    
FT[1, 1, 1]

Anyone know what the problem is?

$\endgroup$
4
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) 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, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Aug 23, 2015 at 23:17
  • 1
    $\begingroup$ What error does it give? (Include it in the question, so others searching the site with the same problem might benefit.) $\endgroup$
    – Michael E2
    Aug 24, 2015 at 1:29
  • 2
    $\begingroup$ The "problem" might be... read the docs? In any case, among many ways to resolve this, using MinRecursion -> 5 in the NIntegrate and Chop on the result gets the same end result... $\endgroup$
    – ciao
    Aug 24, 2015 at 2:53
  • $\begingroup$ As noted by @ciao, FT[kx_, ky_, z_] := 1/(2*Pi)*NIntegrate[ f[x, y, z] *Exp[-I*kx*x - I*ky*y], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, MinRecursion -> 4] // Chop gives the same numerical value as the symbolic solution, 0.00023217. $\endgroup$
    – bbgodfrey
    Aug 24, 2015 at 3:50

1 Answer 1

1
$\begingroup$

Modifying your second definition of FT to

FT[kx_, ky_, z_] := 
  1/(2*Pi)*
    NIntegrate[
      f[x, y, z]*Exp[-I*kx*x - I*ky*y], {x, -∞, ∞}, {y, -∞, ∞}, 
      MinRecursion -> 4] // Chop

solves your problem.

$\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.