Consider the following code:


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

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

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

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...!

  • 2
    $\begingroup$ use SetDelayed (:=) when you define fourier1D? $\endgroup$
    – kglr
    Feb 10, 2020 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, 2020 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, 2020 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, 2020 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, 2020 at 22:05

1 Answer 1


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  *)

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.