Partial sums and Fourier series approach

I am trying to plot the partial sums for $$N=5,10,15,20$$ of the Fourier series of $$f(x)=(1-x^2)^2$$ and $$-1 I have:

f[x_] = If[1 > x > -1, (1-x^2)^2];
L = 2;
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_, N_] :=
a[0] + Sum[a[n]*Cos[2 n*Pi*x/L] + b[n]*Sin[2 n*Pi*x/L], {n, 1, N}]
Table[F[x, N], {N, 5, 20, 5}]
p[N_, a_] :=
Plot[Evaluate[F[x, N]], {x, -a, a}, PlotRange -> All,
PlotPoints -> 200]
a[n]
a[0]
b[n]
Table[p[N, 1], {N, 5, 20, 5}]
g[x_, N_] := Abs[f[x] - F[x, N]]
Table[g[x, 7], {x, -1, 1, 2/10}]


Something is getting wrong. What should I do? Then, how could I use FourierTrigSeries, FourierParameters and FourierCoefficient?

• what's the definition of a in the plotRange attribute? – Alucard Jan 18 '20 at 15:48
• $a=1$ ($1>x>-1$) – George Jan 18 '20 at 15:50
• ah yes, i didn't realize it. – Alucard Jan 18 '20 at 15:53
• can you help me? – George Jan 18 '20 at 15:54
• Just a guess. N is a built-in symbol name, try using a different name. – Rohit Namjoshi Jan 18 '20 at 16:17

ClearAll[g];

g[ x_ /; -1 <= x <= 1, n_] := Abs[(1 - x^2)^2 - uff[x, n]]