0
$\begingroup$

Consider the following code:

func1[x_]:=Sinc[x];

    fourier1D[n_,Lperiodization_]=FourierCoefficient[func1[x],x, n,FourierParameters->{1,2*Pi/Lperiodization}];
    L=10;

    N[fourier1D[0, L]]
    0.624146 + 0. I

    N[FourierCoefficient[func1[x], x, 0, 
      FourierParameters -> {1, 2*Pi/L}]]
    0.309986

Why when I call the function fourier1D it returns me a different result than when I call directly what is inside my function ?

All parameters are absolutely identical in the two different call. Where is the problem ?

I guess it is something obvious but I'm stuck on it for hours now...!

$\endgroup$
7
  • 2
    $\begingroup$ use SetDelayed (:=) when you define fourier1D? $\endgroup$ – kglr Feb 10 '20 at 21:54
  • 1
    $\begingroup$ = is not the same as := in fourier1D. What's happening is that that line is first evaluating the FourierCoefficient expression and then substituting in the values for n and Lperiodization. Apparently that gets a different branch cut than doing it directly? $\endgroup$ – eyorble Feb 10 '20 at 21:54
  • $\begingroup$ @kglr the problem is that I really want to pre-compute the result so that the rest of my script is faster. What is the problem with the "=" here ? I don't see why this pre-affectation causes problem ? $\endgroup$ – StarBucK Feb 10 '20 at 22:01
  • 3
    $\begingroup$ @StarBucK Because without exact values of n and L, FourierCoefficient can't pick smart branch cuts for your problem. Thus, it tries to generalize, but if you then apply the substitution and accidentally cross a discontinuity, the answer could be completely wrong. I'd trust the 0.309986 much more than the 0.624146 here. Using := prevents the pre-computation from making assumptions that later turn out to be unworkable. Save result after substitution, don't save it before. $\endgroup$ – eyorble Feb 10 '20 at 22:03
  • $\begingroup$ @eyorble hmmm I see what you mean. The "problem" I have is that it saves me a lot of computational time to pre compute via the "=". Is there a way to tell mathematica to not do any assumption (like he reasons with Piecewise to avoid branchcutting as you say) ? I hope I am clear in my asking $\endgroup$ – StarBucK Feb 10 '20 at 22:05
1
$\begingroup$

Try Integrate:

fc = Abs[b/(2*Pi)]^((a + 1)/2)*
   Integrate[func1[t]/E^(I*b*n*t), {t, -(Pi/Abs@b), Pi/Abs@b}];
Block[{a, b, n = 0},
 {a, b} = {1, 2*Pi/L};
 fc // N
 ]
(*  0.309986  *)
$\endgroup$

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.