Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fourier series of a piecewise function

  1. Jul 5, 2011 #1

    i'm going through this question.
    firstly how would the graph look like?
    at first i thought it would be http://i.imgur.com/XfVCK.png the top graph drawn, but then i thought maybe it's the bottom one.
    if it was the bottom one then it'd be easier for me to do the question, since it'd be an odd function, and i dont quite understand how i can substitute a value into the x for that f(x + 2pi) = f(x) line and from that, draw the -f(x) component, though i believe that means that the function repeats itself every 2pi interval?

    so is it the top graph or the bottom graph? i think it's top, since it'd have to repeat itself every 2pi.

    i'll continue the question and post up my working out so someone can validate if i'm doing it right (thanks).
  2. jcsd
  3. Jul 5, 2011 #2


    User Avatar
    Homework Helper

    It's the top graph, for the reason you mentioned: the top graph repeats itself every 2pi. I don't understand what you mean by this:

    If I want to know what the value of f(x) is for any x, I would keep on subtracting 2pi until x is between 0 and 2pi, since f(x+2pi)=f(x). I could then read the value off the function's definition.
  4. Jul 6, 2011 #3
    this answers my question lol, thanks.

    i'll post up my working out once i've done the question (or as much as i can).
  5. Jul 6, 2011 #4
  6. Jul 6, 2011 #5
    here are given formulae

  7. Jul 6, 2011 #6
  8. Jul 8, 2011 #7
  9. Jul 9, 2011 #8
    Okay, it looks mostly good, except for a couple things. First of all, in the a0 calculation, I'm not understanding where you said:
    [tex]\displaystyle \frac{1}{2L} \int_{-L}^{L} f(x) dx = \frac{1}{4L} \int_{-L}^{0} f(x) dx + \frac{1}{4L} \int_{0}^{L} f(x) dx [/tex]

    That should be [tex]\displaystyle \frac{1}{2L} \int_{-L}^{L} f(x) dx = \frac{1}{2L} \int_{-L}^{0} f(x) dx + \frac{1}{2L} \int_{0}^{L} f(x) dx [/tex]
    You already cut the limits of integration in half (going from -L to 0 instead of -L to L) so you don't need to cut the coefficient in half as well. It seems like that's what you did, because you did it again in the an and bn calculations. That error threw your answer off by a factor of (1/2).

    The only other error I see is in the second and third last lines of the bn calculations. You're saying that cos(nx) evaluated at x=0 is 0, which is isn't, cos(0)=1. Always be careful to actually evaluate the function at the integration limits, and don't just drop the x=0 terms. They're often zero, but not always. Especially in fourier calculations, they're very often not zero. It looks like you did the same thing with the an calculation, although it did turn out to be right since sin(0)=0.

    One last thing, which I guess isn't technically an error, but I wouldn't be surprised if you lost marks for it. At the end of your an and bn calculations (and it carried through to your final answer), you ended up with some terms like cos(n*pi) and sin(n*pi). Instead of leaving them as they are, why not evaluate them, since trig functions tend to be nice at integer multiples of pi? What are the values of those two functions when n is even? What about odd? If you do that correctly, you should find that one of them drops out entirely, and the other is only non-zero when n is odd. This simplifies your answer a lot. Since you're asked for the first four non-zero terms, not doing this would actually make your final answer incorrect.

    Hope that helps.

    I noticed you mentioned that if the function was odd (I think you meant even), it would be easier to evaluate. There are tricks you can use to make a function 'nicer.' They can cut down your work quite a bit, though they might not. For example, with this function, you could shift f(x) to the left by (pi/2) and make it an even function. You could also shift it (the original function, not the even function I just mentioned) down by (1/2) and make it into an odd function. Both of those shifts will affect the fourier series in a predictable way, so that if you can find the fourier series for the shifted function, you can easily convert to the fourier series of the original function. In this case, shifting the function down by (1/2) makes the calculation a heck of a lot easier. It turns your function into an odd function, so you know an is 0 for the fourier series of the shifted function, and you only have to find a0 and bn for the shifted function. But then, a constant amplitude shift like that only changes the a0 term. So all you'll have to do to get back to the fourier series of the original function is either add or subtract (1/2) to the value of a0 you found, and you're done! That saves a lot of work (especially for more complicated problems), and leaves less places for you to make errors.
    Last edited: Jul 9, 2011
  10. Jul 9, 2011 #9
    firstly, thank you so much for this detailed response!
    much much much appreciated and i couldn't've asked for a better response :)

    yeah for some reason i thought if i split up the integral i have to half the coefficient -_-
    but thats not required.

    ughhh silly mistake, i did another fourier question and THAT time yes i made cos(nx) at x=0 equal to 1, must've forgotten during this q.

    yeah i know with sin(n*pi) i can just replace that with 0 for any value of n, but what about cos(n*pi)? For every odd value of n, cos(n*pi) = -1, and for every even value of n, cos(n*pi) = 1, so... should i should just leave cos(n*pi) as it is, right?

    hm, i might try this. i haven't heard of this method before, but i understand how it works.
    i'll give it a go.
  11. Jul 9, 2011 #10
    No problem :smile:

    If you fix the cos(0)=1 issue, you should find that all the even terms become zero. Then you can drop the cos term completely and just add a qualifier that says 'n is odd' or something. It simplifies your answer a lot. In this case in particular, the question asks for the first 4 non-zero terms, so only writing the n=0,1,2,3 terms would actually be incorrect since the n=2 term is zero.

    Even if it wasn't the case that the evens were zero, I would personally still split it into even and odd terms. In that case you have to split it into two sums, but I think it still makes it nicer to work with because you just have a positive or negative rather than a whole cosine term. You can also use the fact that for integer values of n, cos(n*pi)=(-1)n. That's a little more of a personal preference thing though, and it depends what you find easier to work with.

    Yeah, a lot of those properties are actually quite easy to derive just by using the definition.
  12. Jul 9, 2011 #11
    ohh the bolded bit i've seen before but i never actually understood what the lecturer was doing.
    i think i'll understand this better if i do the question again but without halving the coefficients lol.
  13. Jul 10, 2011 #12
    ok so ive worked out a0, an, and bn again, and im getting
    a0 = 1/2,
    an = 0,
    bn = [itex]\frac{1 - (-1)n}{n*pi}[/itex]
    erm it isnt showing up right for me..

    bn = [1 - (-1)n] / (n*pi)

    is this right?

    and then i sub all into f(x)?
  14. Jul 10, 2011 #13
    so im getting

    f(x) = 2 + [itex]\frac{2}{Pi}[/itex]*sin(x) + [itex]\frac{2}{Pi}[/itex]*sin(3x)

    is this right?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook