2
$\begingroup$

I am trying to get a Fourier Transform of a function. However it doesn' work when the variable is 0. I used Mathematica 8.0 on a Windows Server 2008 R2 system. The code is as follows:

Defining parameters and constants:

Rr = Sqrt[0.999*0.95]; 
λ = 0.561*10^-3; 
f = 100;
W = 0.35;

θ = 1.03*π/180 
t = 2.6*1.47;
Δx[n_] := n 2 t Sin[θ]; 
Δz[n_] := n 2 t Cos[θ];

w = (λ*f)/(π*W);
k = 2 Pi/λ;
b =  k w^2/2;
q = I b;
zr = Pi w^2/λ;
F = 100; 
nbeams = 120;

Function definitions:

Beam[x_, y_, n_] := Rr^n*Exp[-(((x - Δx[n])^2 + y^2)/ (w^2))]
Field[x_] := Sum[Beam[x, 0, n], {n, 0, nbeams, 1}];
T1[xf_, yf_, n_] := 
  Exp[-I k Δz[n]] Exp[I k Δz[n] (xf^2 + yf^2)/(2 F^2)] 
   FourierTransform[Beam[x, y, n], {x , y}, {-k xf /F, -k yf/ F}]
T2[xf_, yf_] := Sum[T1[xf, yf, n], {n, 0, nbeams}]

Getting the results:

Table[Abs[T2[xf, 0]]^2, {xf, -1, 1, 0.1}]

The results it gives me is :

{4.8024*10^-14, 1.15696*10^-12, 2.68091*10^-10, 1.64556*10^-10, 
 2.26218*10^-9, 1.50507*10^-7, 3.7152*10^-8, 1.29164*10^-7, 
 8.43299*10^-6, 8.66378*10^-7, 
 Abs[(-0.000614156 - 0.0000682406 I) + (1. + 0. I) FourierTransform[
     1. E^(-384.158 ((0. + x)^2 + y^2)), {x, y}, {0., 0.}]]^2, 
 5.92387*10^-7, 5.05467*10^-6, 5.03941*10^-7, 3.99645*10^-8, 
 6.8095*10^-9, 1.8926*10^-9, 7.41962*10^-10, 1.10782*10^-8, 
 6.31941*10^-12, 8.40441*10^-14}

As you can see, it doesn't compute when x is 0.

However, when I tried the same code with Mathematica 10.3 on a Windows 7 machine, it could compute without any problem. Do you have any idea about why it doesn't compute when x is 0?

$\endgroup$
  • $\begingroup$ Welcome! 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 and check the faqs! 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. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 May 31 '16 at 15:00
2
$\begingroup$

I think the problem your experience stems from trying to calculate the symbolic Fourier transform of Beam after numerical values have been substituted for xf and yf. This fails for $0$, as the variables disappear, and in general may not be accurate.

Instead, pre-calculate the symbolic Fourier transform, then substitute in the numerical values of xf, yf, and n. Here is an example, which uses the rest of your definitions unchanged:

ftbeam[xf_, yf_, n_] = FourierTransform[Beam[x, y, n], {x, y}, {-k xf/F, -k yf/F}];

T1[xf_, yf_, n_] := Exp[-I k Δz[n]] Exp[I k Δz[n] (xf^2 + yf^2)/(2 F^2)] ftbeam[xf, yf, n]

Table[Abs[T2[xf, 0]]^2, {xf, -1, 1, 0.1}]

(* Out:
{4.8024*10^-14, 1.15696*10^-12, 2.68091*10^-10, 1.64556*10^-10, 
 2.26218*10^-9, 1.50507*10^-7, 3.7152*10^-8, 1.29164*10^-7, 
 8.43299*10^-6, 8.66378*10^-7, 4.77163*10^-7, 5.92387*10^-7, 
 5.05467*10^-6, 5.03941*10^-7, 3.99645*10^-8, 6.8095*10^-9, 
 1.8926*10^-9, 7.41962*10^-10, 1.10782*10^-8, 6.31941*10^-12, 
 8.40441*10^-14}
*)
$\endgroup$
  • $\begingroup$ Thank you MarcoB. It really solves the problem. I was struggling on this problem for two days. $\endgroup$ – Charlie May 31 '16 at 17:42
  • $\begingroup$ @Charlie I'm glad I could help! $\endgroup$ – MarcoB May 31 '16 at 18:50

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.