I'm quite puzzled by Mathematica lack of precision with Fourier and InverseFourier. I tried the following code
x = Table[Sin[n], {n, 20}];
X = Fourier[x];
x1 = InverseFourier[X]
x - Abs[x1]
And this is the output
{0.841471 - 7.88128*10^-19 I, 0.909297 - 1.9237*10^-17 I,
0.14112 - 6.60657*10^-18 I, -0.756802 +
3.35168*10^-17 I, -0.958924 + 3.82771*10^-17 I, -0.279415 +
1.49703*10^-16 I, 0.656987 + 4.01726*10^-17 I,
0.989358 + 1.91002*10^-17 I,
0.412118 + 4.61974*10^-17 I, -0.544021 -
2.58484*10^-17 I, -0.99999 + 6.82983*10^-18 I, -0.536573 -
1.51056*10^-16 I, 0.420167 - 2.67625*10^-17 I,
0.990607 - 5.50323*10^-17 I,
0.650288 + 2.48665*10^-17 I, -0.287903 +
3.78263*10^-17 I, -0.961397 - 7.97744*10^-17 I, -0.750987 +
1.02483*10^-16 I, 0.149877 - 3.62319*10^-17 I,
0.912945 - 9.76356*10^-17 I}
{-1.11022*10^-16, -1.11022*10^-16, 0., -1.5136, -1.91785, -0.558831, \
-1.11022*10^-16,
2.22045*10^-16, 0., -1.08804, -1.99998, -1.07315, 0., \
-2.22045*10^-16, -1.11022*10^-16, -0.575807, -1.92279, -1.50197,
3.05311*10^-16, 1.11022*10^-16}
Am I doing something wrong?
x - Chop[x1]
to remove the small imaginary components rather than taking the magnitude, discarding the sign ofx1
! $\endgroup$Chop[x1 - Abs[x1]]
gives{0, 0, 0, -1.5136, -1.91785, -0.558831, 0, 0, 0, -1.08804, -1.99998, -1.07315, 0, 0, 0, -0.575807, -1.92279, -1.50197, 0, 0}
$\endgroup$