Skip to main content
3 of 3
deleted 20 characters in body
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Plotting Partial Sums of Fourier Series

I'd like 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 π) Sum[(6 (-1)^k)/(k π) 
                Cos[(k π x)/2] + (16 (-1)^k + 13)/(π k) 
                Sin[(k π 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 about the best method to tackle something like this?

night owl
  • 1.7k
  • 3
  • 15
  • 27