1
$\begingroup$

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<x<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?

$\endgroup$
10
  • $\begingroup$ what's the definition of a in the plotRange attribute? $\endgroup$ – Alucard Jan 18 '20 at 15:48
  • $\begingroup$ $a=1$ ($1>x>-1$) $\endgroup$ – George Jan 18 '20 at 15:50
  • $\begingroup$ ah yes, i didn't realize it. $\endgroup$ – Alucard Jan 18 '20 at 15:53
  • $\begingroup$ can you help me? $\endgroup$ – George Jan 18 '20 at 15:54
  • 1
    $\begingroup$ Just a guess. N is a built-in symbol name, try using a different name. $\endgroup$ – Rohit Namjoshi Jan 18 '20 at 16:17
1
$\begingroup$
ClearAll[g];
ClearAll[uff];
uff[a_, b_] := (FourierSinSeries[(1 - t^2)^2, t, b] + 
    FourierCosSeries[(1 - t^2)^2, t, b] ) /. t -> a
fun = Table[uff[a, i] , {i, 5, 15, 5}];
Plot[fun, {a, -1, 1}]

enter image description here

g[ x_ /; -1 <= x <= 1, n_] := Abs[(1 - x^2)^2 - uff[x, n]]
ListPlot[Table[N@g[x, 5], {x, -1, 1, 2/10}] ]

enter image description here

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