Skip to main content
1 of 3
night owl
  • 1.7k
  • 3
  • 15
  • 27

Plotting Partial Sums of Fourier Series

I am wanting to plot some partial sums for a Fourier Series problem, but I am not sure if the output I am getting is correct. I want to be able to plot the partial sums and the function on the same graph. Here is something that I attempted.

s[n_, x_] :=  8/4 + 3/(9 \[Pi]) Sum[(6 (-1)^k)/(k \[Pi]) 
                Cos[(k \[Pi] x)/2] + (16 (-1)^k + 13)/(\[Pi] k) 
                Sin[(k \[Pi] x)/2],{k, 0, n}]
partialsums = Table[s[n, x], {n, 1, 5}];
f[x_] = Piecewise[{{-x^3-2x,-2 < x < 0},{-1+x,0<= x <= 2}}]
Plot[Evaluate[partialsums], {x, -4 Pi, 4 Pi}]

Any ideas of the best method to tackle something like this.

night owl
  • 1.7k
  • 3
  • 15
  • 27