Fourier series of a piecewise function

In summary: This is a pretty simple example, but I'm just trying to illustrate a technique that is generally useful when trying to compute Fourier series.In summary, the conversation is about finding the correct graph for a given function and solving a question related to it. The top graph is the correct one as it repeats itself every 2pi. The person also asks for guidance on their working out and receives feedback on some errors and tips on how to simplify the calculations.
  • #1
imsleepy
49
0
JJ6b0.jpg


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 don't 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).
 
Physics news on Phys.org
  • #2
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:

i don't 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?

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.
 
  • #3
ideasrule said:
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.

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
here are given formulae

KIjJQ.png
 
  • #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.

EDIT:
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:
  • #9
firstly, thank you so much for this detailed response!
much much much appreciated and i couldn't've asked for a better response :)

thegreenlaser said:
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).

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

thegreenlaser said:
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.
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.


thegreenlaser said:
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.

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?


thegreenlaser said:
EDIT:
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.

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.
 
  • #10
imsleepy said:
firstly, thank you so much for this detailed response!
much much much appreciated and i couldn't've asked for a better response :)
No problem :smile:

imsleepy said:
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?

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.




imsleepy said:
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.

Yeah, a lot of those properties are actually quite easy to derive just by using the definition.
 
  • #11
thegreenlaser said:
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.

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.
 
  • #12
ok so I've worked out a0, an, and bn again, and I am getting
a0 = 1/2,
an = 0,
bn = [itex]\frac{1 - (-1)n}{n*pi}[/itex]
erm it isn't showing up right for me..

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

is this right?

and then i sub all into f(x)?
 
  • #13
so I am getting

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

is this right?
 

1. What is a Fourier series of a piecewise function?

A Fourier series of a piecewise function is a mathematical representation of a function as an infinite sum of sine and cosine functions. It is used to approximate a piecewise function with a simpler series of trigonometric functions.

2. How is a Fourier series of a piecewise function calculated?

To calculate a Fourier series of a piecewise function, you need to find the coefficients of the sine and cosine terms by solving a system of equations. These coefficients are then used to construct the series, which can be used to approximate the piecewise function.

3. What is the purpose of using a Fourier series for a piecewise function?

The purpose of using a Fourier series for a piecewise function is to simplify the function and make it easier to analyze and manipulate. It allows for the approximation of complex functions with simpler trigonometric functions, making it useful in many areas of mathematics and science.

4. Are there any limitations to using a Fourier series for a piecewise function?

Yes, there are some limitations to using a Fourier series for a piecewise function. One limitation is that the series may not converge for all values of the independent variable. Additionally, the series may only be able to approximate certain types of functions and may not be accurate for more complex functions.

5. How is a Fourier series of a piecewise function used in real-world applications?

A Fourier series of a piecewise function has many real-world applications in fields such as engineering, physics, and signal processing. It is used to analyze and approximate periodic signals, such as sound waves and electrical signals. It is also used in image processing and data compression techniques.

Similar threads

  • Calculus and Beyond Homework Help
Replies
3
Views
279
  • Calculus and Beyond Homework Help
Replies
6
Views
386
  • Calculus and Beyond Homework Help
Replies
3
Views
362
  • Calculus and Beyond Homework Help
Replies
9
Views
812
  • Calculus and Beyond Homework Help
Replies
3
Views
728
  • Calculus and Beyond Homework Help
Replies
6
Views
912
  • Calculus and Beyond Homework Help
Replies
6
Views
425
  • Calculus and Beyond Homework Help
Replies
1
Views
963
  • Calculus and Beyond Homework Help
Replies
7
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
413
Back
Top