1
$\begingroup$

Have defined a periodic function in a recursive way. When doing Fourier series I get a function with different period. Can someone spot the mistake?

enter code here
ClearAll;
T=20;
f[x_] := Which[x >= T/2, f[x - T],
           x <= -T/2, f[x + T],
          -T < x < T, Exp[-x^2]];
Plot[f[x],{x,-30,30},PlotRange->All]
FourierCosSeries[f[x],x,6]
(*FourierSeries[f[x],x,1]*)
Plot[%,{x,-30,30}]
$\endgroup$

1 Answer 1

5
$\begingroup$

It is because of the period. Fourier series assumes, as default, that period is $2\pi$

So to tell it the period is $T=20$, you can use FourierParameters otherwise it has no idea.

ClearAll;
T = 20;
f[x_] := Which[x >= T/2, f[x - T], x <= -T/2, f[x + T], -T < x < T, 
   Exp[-x^2]];
Plot[f[x], {x, -30, 30}, PlotRange -> All, Exclusions -> None]

Mathematica graphics

sol = FourierSeries[f[x], x, 10, FourierParameters -> {1, 2 Pi/T}];
Plot[Evaluate[sol], {x, -30, 30}, PlotRange -> All, 
 Exclusions -> None, PlotStyle -> Red]

Mathematica graphics

And now it matches. Same for

sol = FourierCosSeries[f[x], x, 10, FourierParameters -> {1, 2 Pi/T}];
Plot[Evaluate[sol], {x, -30, 30}, PlotRange -> All, 
 Exclusions -> None, PlotStyle -> Red]

Mathematica graphics

$\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.