It is given the following periodic function $$f(x)=x-x^3, \quad -1<x<1$$ This is an odd function, so the coefficients $a_n,a_0$ of the Fourier Series are zero.
Usually, I face function with two branches so I tried to code it on Mathematica as follows:
f[x_] := Which[-1 < x <= 0, x - x^3, 0 < x < 1, x - x^3]
Plot[f[x], {x, -1, 1}]
Edited
a[n_] := (2/L)*Integrate[f[x]*Cos[2 n*Pi*x/L], {x, -L/2, L/2}]
a[0] := (1/L)*Integrate[f[x], {x, -L/2, L/2}]
b[n_] := (2/L)*Integrate[f[x]*Sin[2 n*Pi*x/L], {x, -L/2, L/2}]
F[x_, Nmax_] :=
a[0] + Sum[a[n]*Cos[2 n*Pi*x/L] + b[n]*Sin[2 n*Pi*x/L], {n, 1, N}]
p[Nmax_, a_] :=
Plot[Evaluate[F[x, Nmax]], {x, -a, a}, PlotRange -> All,
PlotPoints -> 200]
L = 2;
f[x_] := If[x > 0, x - x^3, x - x^3];
a[n]
a[0]
b[n]
Simplify[b[n], n \[Element] Integers]
Integrate[f[x]^2, {x, -L, L}]
(a[0]^2)/2 + Sum[(a[n]^2 + b[n]^2), {n, 1, Infinity}] <=
Integrate[f[x]^2, {x, -L, L}]
Is my consideration correct? I can realize that the two plots are the same and for this reason seems weird.







f[x_] := Which[-1 < x <= 0, x - x^3, 0 < x < 1, x - x^3]is equivalent to:f[x_]:= x - x^3– Daniel Huber Jan 19 '23 at 10:29Nas variable. Also, please clarify what is your question more clearly. Are you asking if your Fourier series manual calculations correct or not? – Nasser Jan 19 '23 at 10:30Mathematicaare built-in symbols. If you don't remember which ones, don't use any. For example you could have writtenNNinstead ofNas your variable. You can test. Try?? Nand see what you get. To avoid this test here's a simple mnemonic. Don't useONE DICK; shameless advertising seehereand thelinked one– bmf Jan 19 '23 at 10:52