2
ExptoTrig[FourierSeries[Piecewise[{{-Pi,-2Pi<x<=0},{Pi,0<x<=2Pi}}],x,3]]

You can see, the function goes from $(-2\pi,2\pi]$

But Wolfram Alpha gives a wrong answer to this, because she computes it as if the function would go from $-\pi$ to $\pi$.

(The right answer should be $4\sin(\frac{x}{2}) + ..$.)

So, how can I use this command when the function's period T is not 2$\pi$ exactly?

Filkor
  • 133
  • 6

2 Answers2

4
f[x_] = Piecewise[{{-Pi, -2 Pi < x <= 0}, {Pi, 0 < x <= 2 Pi}}];
T = 4 \[Pi];
fr = FourierTrigSeries[f[x], x, 3, FourierParameters -> {1, 2 \[Pi]/T}]
(* 4 Sin[x/2] + 4/3 Sin[(3 x)/2] *)

enter image description here

1

Thanks @rewi. I just write down the Wolfram Alpha version, (based on his answer). So I can remember.

FourierTrigSeries[Piecewise[{{-Pi, -2 Pi < x <= 0}, {Pi, 0 < x <= 2 Pi}}], x, 3, FourierParameters -> {1, 1/2}]

where FourierParameters' second parameter is $\omega = \frac{2\pi}{T}$

Filkor
  • 133
  • 6