One thing that can be problematic is to use functions that can deal only (or better) with numerical input values as arguments (the limits to NIntegrate
in this example) to functions that do symbolic manipulations of their inputs (like Plot
).
What helps most of the time is to wrap things like taking numerical integrals in a function that only evaluates if their inputs are numerical but stay unevaluated for symbolic inputs.
For your example you can e.g. try something like this:
f[s_?NumericQ] = Piecewise[{{Exp[-1/(1 - s^2)], -1 < s < 1}}];
fintegral[t_?NumericQ] := NIntegrate[f[s], {s, 0, t},
AccuracyGoal -> 5,
Method -> {"GlobalAdaptive", Method -> "GaussKronrodRule"}
];
Plot[fintegral[t], {t, -2, 2}]
Needs["FourierSeries`"];
fintegralfourier[\[Omega]_?NumericQ] := NFourierTransform[fint[t], t, \[Omega],
AccuracyGoal -> 5]
Off[NIntegrate::deoncon, NIntegrate::deondiv, NIntegrate::deorel]
Plot[Im@fintegralfourier[\[Omega]], {\[Omega], -20, 20},
MaxRecursion -> 0, PlotPoints -> 10, PlotRange -> All
]

Here i used ?NumericQ
in the definition of the helper functions to let them stay unevaluated for symbolic input. This makes fintegral more safe to use as in Plot
and NFourierTransform
. Also i used a cheaper method as option for NIntegrate
since we know that our integrand is very smooth and easy to integrate.
Now the next problem is, that since NFourierTransform
internally also uses numerical integration, we do nested NIntegrate
calls, which is very slow.
The third problem is that the function fint
is similar to a step function, where we know that the fourier transform has a pole at zero. See for example
g = Piecewise[{{3 x - 4 x^3, -1/2 < x < 1/2}}, Sign[x]]
Plot[g, {x, -1, 1}]

where FourierTransform
knows the exact transform result
gfourier=FourierTransform[Piecewise[{{3 x - 4 x^3, -1/2 < x < 1/2}}, Sign[x]], x, \[Omega]]

which has a pole at zero:
Plot[Im@gfourier, {\[Omega], -10, 10}]

So now it's understandable that NFourierTransform
will have problems with numerical integrations near $\omega\approx 0$.
Fourier
? $\endgroup$Plot[FourierSequenceTransform[ NIntegrate[ Piecewise[{{Exp[-1/(1 - s^2)], Abs[s] < 1}, {0, Abs[s] >= 1}}], {s, 0, n*0.1}, AccuracyGoal -> 20], {n, -20, 20}, \[Omega]], {\[Omega], -20, 20}]
, thenn
is not in theFourierSequenceTransform
argument. $\endgroup$I NFourierTransform[Piecewise[{{Exp[-1/(1 - s^2)], -1 < s < 1}}], s, ω]/ω
. $\endgroup$