# Graphing Infinite Series (Mathematica)

1. Apr 18, 2014

### Eruditee

1. The problem statement, all variables and given/known data
I just have to graph this function to see where the "Gibbs phenomenon" occurs in its Fourier Series representation. I am pretty sure I integrated correctly.

2. Relevant equations
Fourier Series

3. The attempt at a solution
$a_{0}=\frac{1}{\pi}\int_{-pi}^{pi}f(x)dx=\int_{-\pi}^{\pi}x^{2}dx=\frac{x^{3}}{3}|_{-\pi}^{\pi}=\frac{x^{3}}{3}|_{-\pi}^{-\frac{\pi}{2}}+\frac{x^{3}}{3}|_{-\frac{\pi}{2}}^{0}+\frac{x^{3}}{3}|_{0}^{\frac{\pi}{2}}+\frac{x^{3}}{3}|_{-\frac{\pi}{2}}^{\pi}==\frac{1}{\pi}(\frac{16\pi^{3}}{24})=\frac{2\pi^{2}}{3}$

With 2 successive integration by parts; I arrive at:
$Fourier=\frac{\pi^{2}}{3}+4\overset{\infty}{\underset{1}{\sum}}\frac{cos(nx)}{n^{2}};cosine=even=\frac{\pi^{2}}{3}+4\overset{\infty}{\underset{1}{\sum}}\frac{(-1)^{n}}{n^{2}}$

I do not know how to graph the first 5, 20, 400 etc terms. I have tried Mathematica, using
ListPlot[Table[{n, 4pi(-1)^n/(n^2)},{n,0,500}] but I get a blank graph. The problem is done; I just don't get how to graph this? I'd like to graph it from x= 0 to x= 4pi

Last edited by a moderator: Apr 18, 2014
2. Apr 18, 2014

### vela

Staff Emeritus
You don't want to plot $a_n$; you want to plot the approximations to f(x) using a finite number of terms to see Gibbs phenomenon.

Two reason you're getting a blank graph: First, you're dividing by zero. Second, Mathematica doesn't know what "pi" means. The case matters here. If you want the constant $\pi$, you have to use Pi.

3. Apr 20, 2014

### Eruditee

Yes, I used Pi. I was just showing the actual forumula. Why would I not be able to plot 4cos(nx)/n^2 as (-1)/n^2, since I am asked to graph from 0 to 4 pi (cos 5pi = cos pi). It seems easier to keep it like the latter, in terms of n. I shound't start at zero, however; that's outside my series sum.

This is still blank"
ListPlot[Table[{n, x, (Pi)^2/(3)+ (4*cos (nx))/(n^2)}, {n, 1, 10}, {x, 0, 4 Pi}]]

Found this online; I need to default to youtube quicker,

I instead used the sum feature, like this

down vote accepted

If you define

f[x_, t_, nm_] := 1/2 + Sum[(1/n/ Pi) ((-1)^n - 1) Sin[n x] Exp[-t n^2], {n, 1, nm}];

then

Plot[Table[f[x, t, 150], {t, {0, 0.01, 0.1, 0.5, 1, 10}}] // Release, {x, -Pi, Pi}]

with
f[x_, nm_] := ((Pi^2)/3) + Sum[(4 cos (nx)/(n^2)), {n, 1, nm}];
Plot[f[x_, nm_], {x, 0, 4 Pi}]
Manipulate[Plot[f[x_, nm_], {x, 0, 4 Pi}], {n, 1, 100}]

Not working. Oh well. Next. It's not really a major part of the exercise as the calculation. This is harder than C IMO with all you have to know of it to make it servicable :-/. Thanx

Last edited by a moderator: Sep 25, 2014
4. Apr 23, 2014

### Eruditee

Does anyone else know what's going on? I have tried this several times, and am using a stackexchange dialog in which the following was adapted:

s[n_, x_] := ((Pi^2)/3) + Sum[((4 cos (kx))/(k^2)), {k, 1, n}]
partialsums = Table[s[n, x], {n, 1, 5}];
Plot[Evaluate[partialsums], {x, 0, 4 Pi}]

from
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, 1, n}]

partialsums = Table[s[n, x], {n, 1, 5}];
Plot[Evaluate[partialsums], {x, -4, 4}]
http://mathematica.stackexchange.com/questions/2537/plotting-partial-sums-of-fourier-series

I still get a blank graph? Any help is appreciated as I do not have but a trial version of this software and like to finish this and my diff eq section.

Fixed **Spacing issue**

Last edited: Apr 23, 2014
5. Apr 23, 2014

### vela

Staff Emeritus
Your first line has a few errors. Use s[n_, x_] := ((Pi^2)/3) + Sum[((4 Cos[k x])/(k^2)), {k, 1, n}]

6. Apr 24, 2014

### Bill Simpson

Whenever I cannot get a Plot the first thing I do is to look at the result of Table instead.

You already have the Table in partialsums. Look at that to see any clues for what went wrong.
With the previous hint about capitalization and with inserting a space or an * in the right place
I then get a plot that might be what you are looking for. I didn't even need the Evaluate.
(I think that using * instead of space probably saves time in the long run by avoiding errors)

7. Apr 24, 2014

### Eruditee

Thank you both! I'm sorry I didn't make it more clear in the post: I had figured out it was a spacing issue. I haven't used that program in about 5 years, so I was a bit rusty.