Fourier series

1. Feb 29, 2008

Niles

[SOLVED] Fourier series

1. The problem statement, all variables and given/known data
Hi.

It is part 1 (finding the Fourier-series for f(x) = |x|) I am having trouble with.

3. The attempt at a solution
Ok, I can write f(x) = |x| for -pi =< x < pi as:

f(x) = x for 0 =< x < pi and
f(x) = -x for -pi =< x =< 0.

The function has period T=2.

I want to find a_n = int[f(x)*cos(n*pi*x)]dx with limits -1 .. 1. I split this integral up in two:

a_0 = int[-x}dx + ... but what are the limits? Are they -pi..0 or -1..0? The way I see it, neither of the limits work since a_0 must be pi.

Last edited: Feb 29, 2008
2. Feb 29, 2008

Niles

Ehh, on wikipedia they define a_n = (1/Pi)*int[f(x)*cos(nx)]dx, but in my book they don't use 1/pi, but 2/T where T is the period?

3. Feb 29, 2008

Niles

Do'h my period is all wrong. It's not 2, but 2*pi.

4. Feb 29, 2008

Niles

Ok, I'm stuck finding a_n. This is the expression for a_n:

(int(-x*cos(n*Pi*x), x = -Pi .. 0))/Pi+(int(x*cos(n*Pi*x), x = 0 .. Pi))/Pi

This I get to be:

(2*(cos(Pi^2*n)+sin(Pi^2*n)*n*Pi^2-1))/(Pi^3*n^2),

which does not make sense at all. Can you guys help?

5. Feb 29, 2008

Niles

Ehh ok, my a_n was wrong!

The correct a_n is:

(2*(cos(n*Pi)+sin(n*Pi)*n*Pi-1))/(Pi*n^2). This is zero for even n. Now I just need to write it as they ask me to. How to do that?

6. Feb 29, 2008

jacobrhcp

okay so you want the fourier coefficients of f(x) = |x|. I haven't read all because I find it difficult to read when it's not in tex. Here's what I would take as plan of campaign though:

what you do is say $$c_{k} = \frac{1}{2\pi} {\int^{\pi}_{-\pi} |x| e^{-ikx} dx$$

this integral is not too hard, I imagine it's either something with partial integration, or else just straightforward, maybe cut something up in two pieces or something ;)

after that you say the fourier series is $$\sum_{k} c_{k} e^{ikx}$$

Last edited: Feb 29, 2008
7. Feb 29, 2008

Niles

I have found this for a_0 = Pi.

I have found this for b_n = 0.

I have found this for a_n = $$2\,{\frac {\cos \left( n\pi \right) +\sin \left( n\pi \right) n\pi - 1}{\pi \,{n}^{2}}}$$.

Now I want to write it as they want to me - with the sum, but I can't see how I should do that?

8. Feb 29, 2008

jacobrhcp

a0 = pi/2

for the other part you should just check your calculations and use wolfram integrator (search google) to see if you did everything correct. Also mathematica if you have it.

It would be as much work for me as you to find the error.

9. Feb 29, 2008

coomast

What is the value of the following functions:

$$sin(n\pi)$$

and

$$cos(n\pi)$$

for n=1,2,3,...

10. Feb 29, 2008

jacobrhcp

the integral gives $$- \frac{2}{\pi} \frac{coskx}{k^{2}}$$

where my k is his 2m

now you take the infinite summation and take back the sum one step :)

11. Feb 29, 2008

coomast

For a_0, it depends on the way you use the Fourier series. There are several ways going around for calculating the coefficients. The formula I use it is the following:

$$f(x)=\frac{a_0}{2}+\sum_{n=1}^{\infty}\left(a_n\cdot cos\left(\frac{2\pi nx}{T} \right) + b_n\cdot sin\left(\frac{2\pi nx}{T} \right) \right)$$

With:

$$a_n=\frac{2}{T}\int_{0}^{T}f(x)\cdot cos\left(\frac{2\pi nx}{T} \right)dx$$
$$b_n=\frac{2}{T}\int_{0}^{T}f(x)\cdot sin\left(\frac{2\pi nx}{T} \right)dx$$

In which T the period of the function. This can be shifted for the interval of the integral. But it is the complete period. Sometimes you see it used as an interval of 0 to 2 pi or -pi to pi, etc. This causes confusion. So, a_o=pi might be correct in your integral. The result in the Fourier series has to be pi/2.

Mmmm, using code for these basic integrals... The result is at -first sight- correct. As I posted before, calculate

$$sin(n\pi)$$

it is always 0 and the cos function needs to be split up in even and odd n. You will arrive at the result you are seeking for.

12. Feb 29, 2008

Niles

I used Maple to find the integrals.

I agree with what you wrote coomast - I used those "versions" as well. For n being even, a_n is 0. When n is odd, a_n is different from 0.

From these things I have to write the sum. This is where I am stuck.

EDIT: I read your post again, and noted what you said about sin(n*pi). I'll look at it and return.

13. Feb 29, 2008

Niles

Ok, since sin(n*Pi) = 0 for all n, I get the expression for a_n:

$$2\,{\frac {\cos \left( \pi \,n \right) -1}{\pi \,{n}^{2}}}$$.

I must multiply this with cos(n*x) (actually it's cos(2xnpi/L), but L=2pi). This gives me the following sum in the Fourier-series:

$$2\,{\frac { \left( \cos \left( \pi \,n \right) -1 \right) \cos \left( {\it nx} \right) }{\pi \,{n}^{2}}}$$.

For n being even a_n = b_n = 0. For n being odd I get:

$$-4\,{\frac {\cos \left( {\it nx} \right) }{\pi \,{n}^{2}}}$$. This isn't quite what we want?

Last edited: Feb 29, 2008
14. Feb 29, 2008

coomast

You are almost at the result. The function:

$$cos(n\pi)-1=0 \qquad \forall n \qquad even$$

For odd this is:

$$cos(n\pi)-1=-2 \qquad \forall n \qquad odd$$

Instead of writing odd and even, you can say that:

$$n \qquad odd \rightarrow n=2k+1 \qquad for \qquad k=0,1,2,...$$

Thus in the fourier series you have only those terms left in n which are odd or if you change n by 2k+1 you get the final result. In case this in unclear please post, I'm going to be online for a while.

15. Feb 29, 2008

Niles

Sorry, but I am a little unclear of what you wrote. I can't see why I should substitute with n = 2k+1? And if I do substitute, the it is cos((2k+1)*x), not cos(2k+1)*x as they want to me get.

Thanks for all your help so far.

EDIT: Oh, I see :-) But still, when substituting, x is inside cos(...) and not outside?

16. Feb 29, 2008

coomast

I think you have it :-)

The x has to be part of the argument of the cos function. This is an error in the use of the brackets. This can also cause a lot of confusion.

best regards, Coomast

17. Mar 1, 2008

Niles

Thanks so much for your patience.

18. Mar 1, 2008

coomast

You're welcome :-)