1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Graphing Infinite Series (Mathematica)

  1. Apr 18, 2014 #1
    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

    With 2 successive integration by parts; I arrive at:

    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. jcsd
  3. Apr 18, 2014 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    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.
  4. Apr 20, 2014 #3
    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}];


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

    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
  5. Apr 23, 2014 #4
    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}]

    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}]

    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
  6. Apr 23, 2014 #5


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    Your first line has a few errors. Use s[n_, x_] := ((Pi^2)/3) + Sum[((4 Cos[k x])/(k^2)), {k, 1, n}]
  7. Apr 24, 2014 #6
    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)
  8. Apr 24, 2014 #7
    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted