# Fourier series

1. May 27, 2010

### rayman123

1. The problem statement, all variables and given/known data[/b
expand the function in Fourier series$$f(x)= x^2+xcosx$$
I divided the function in separate part and try to expand it in Fourier series separately
i have started with
$$x^2$$
$$a_{0}= \frac{1}{2\pi}\int_{-\infty}^{\infty}x^2dx=\frac{\pi^2}{3}$$

$$a_{n}= \frac{2}{\pi}\int_{0}^{\pi}x^2cosnxdx=\frac{2}{\pi}[\frac{x^2}{n}sinnx-2\int_{0}^{\pi}x\frac{sinx}{n}]dx=\frac{2}{\pi}[\frac{2\pi(-1)^n}{n^2}]=4\cdot\frac{(-1)^n}{n^2}\Rightarrow x^2= 4 \sum_{n=1}^{\infty}\frac{(-1)^n}{n^2}cosnx$$
$$x^2$$ if even function then$$b_{n}=0$$

function f(x)=x is an odd function $$a_{n}= 0$$
$$b_{n}= \frac{2}{\pi}\int_{0}^{\pi}xsinnxdx=\frac{2}{\pi}[-\frac{x}{n}cosnx+\frac{1}{n}\int_{0}^{\pi}cosnxdx]=\frac{2}{\pi}[-\frac{\pi}{n}(-1)^n]=2 \sum_{n=1}^{\infty}\frac{(-1)^{n+1}}{n}sinnx$$
is this correct so far?
can someone help me and show me how to calculate the rest? I mean how to connect everything together with cosx?

2. Relevant equations

3. The attempt at a solution
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution

Last edited: May 27, 2010
2. May 27, 2010

### Cyosis

It would be handy if you tell us what the period of that function needs to be. From the looks of it you want it to have a period of $2\pi$.

You're integrating the wrong function in every integral. You're supposed to integrate $f(x)=x^2+x\cos x$. Secondly some of your integrands are odd, therefore you can't just say that evaluating the integral between -pi and pi is the same as 2 times the integral between 0 and pi.

3. May 27, 2010

### rayman123

for $$|x|<\pi$$
my teacher did it in almost the same way but at the end he did something else with the xcosx part......

4. May 27, 2010

### Cyosis

It doesn't matter what your teacher did. What does matter is that you're doing it wrong. I suspect that your teacher makes good use of his knowledge how even and odd functions behave when integrated over a symmetrical interval. It is not smart to try and copy a method that you don't understand.

For example you get the correct answer for $a_0$ by pure coincidence. In fact your integral for $a_0$ doesn't even converge.

This is the integral you should have calculated:

$$a_0=\frac{1}{2 \pi}\int_{-\pi}^\pi f(x)dx$$

5. May 27, 2010

### rayman123

well i calculated this integral once again and i get $$\frac{\pi^2}{3}$$

6. May 27, 2010

### Cyosis

That is correct, but you calculated a different integral in your OP, which had the same answer by coincidence.

This is why it gave the same answer.

\begin{align*} a_0 & =\frac{1}{2 \pi}\int_{-\pi}^\pi x^2+x \cos x dx \\ & = \underbrace{\frac{1}{2 \pi} \int_{-\pi}^\pi x^2 dx}_\text{even integrand}+\underbrace{\frac{1}{2 \pi}\int_{-\pi}^\pi x \cos x dx}_\text{odd integrand} \end{align*}

The second integral goes to zero.

Last edited: May 27, 2010
7. May 27, 2010

### rayman123

okej, i see it now.
but how to calculate coefficients $$a_{n} , b_{n}$$ then?
the problem is that i am not able to say whether the function is odd or even.....$$x^2$$ is even but $$xcosx$$ is odd.....but the whole function?

8. May 27, 2010

### Cyosis

You can calculate the other coefficients in a similar way. Read post #6 again, because I just fixed the latex.

If a function is even then $f(-x)=f(x)$. If a function is odd then $f(-x)=-f(x)$. You can use this to check that f(x) is neither even nor odd.

Last edited: May 27, 2010
9. May 27, 2010

### rayman123

okej
so i started with $$a_{n}=\frac{1}{\pi}\int_{-\pi}^{\pi}x^2cos(nx)dx+\frac{1}{\pi}\int_{-\pi}^{\pi}xcosxcos(nx)dx$$

the first integral gave me
$$\frac{2}{n^2}[xcos(nx)]_{-\pi}^{\pi}]=\frac{4\pi}{n^2}(-1)^n$$ hope its correct
how would you calculate the second one?

10. May 27, 2010

### Cyosis

The $\pi$ shouldn't be there. As for the second integral. Is the integral even or odd?

11. May 27, 2010

### rayman123

i would say the second integral is odd, should it give 0 then?
is the final substitution wrong in the first integral? whe $$\pi$$ should not be there?

12. May 27, 2010

### Cyosis

Correct. The integrand is odd, and the integration interval is symmetric therefore the integral is 0. You have a $\pi$ in there because you forgot the factor $1/ \pi$ in front of the integral.

Notice how you got the same answer again, this time however without luck.

13. May 27, 2010

### rayman123

oh....again, right

$$\frac{2}{n^2}[xcos(nx)]_{-\pi}^{\pi}]=\frac{4\pi}{n^2}(-1)^n$$

$$a_{n}=\frac{4}{n^2}(-1)^ncosnx$$

$$b_{n}= \frac{1}{\pi}\int_{-\pi}^{\pi}x^2sin(nx)dx+ \frac{1}{\pi}\int_{-\pi}^{\pi}xsin(nx)cos(nx)= \frac{1}{\pi}[-\frac{x^2}{n}cosnx+\frac{2x}{n^2}sinnx+\frac{2}{n^3}cosnx]_{-\pi}^{\pi}$$
is this correct so far?
i get from the first integral 0.......the second integrand is even so it will give 0

Last edited: May 27, 2010
14. May 27, 2010

### Cyosis

Why did you suddenly put a cosine in your expression for $a_n$? It shouldn't be there.

The first integral is zero yes, why? The second integral is even yes, but that does not mean the integral is zero.

15. May 27, 2010

### rayman123

okej, I just got quite confused....I must admit that I am a real beginner when it comes to Fourier analysis...all this is quite difficult;)
i just calculated the value for the first integral
$$b_{n}= \frac{1}{\pi}[-\frac{x^2}{n}cosnx+\frac{2x}{n^2}sinnx+\frac{2}{n^ 3}cosnx]_{-\pi}^{\pi}=\frac{1}{\pi}[-\frac{\pi^2}{n}(-1)^n+\frac{2}{n^3}(-1)^n-(-\frac{\pi^2}{n}(-1)^n+\frac{2}{n^3}(-1)^n)]=}[-\frac{\pi^2}{n}(-1)^n+\frac{2}{n^3}(-1)^n+\frac{\pi^2}{n}(-1)^n-\frac{2}{n^3}(-1)^n=0$$

you are right with the second integral, i mixed it up with an odd function and I assumpted it should give 0....
however i do not have any clue how do solve the 2nd integral...

16. May 27, 2010

### Cyosis

The first integral is odd so you could have set it to zero saving you a lot of trouble.

For the second integral use the well known double angle formula $\sin 2x=2\sin x \cos x$.

Last edited: May 27, 2010
17. May 27, 2010

### rayman123

okej, i used it and i got
$$\frac{1}{2\pi}\int_{-\pi}^{\pi}xsin(2nx)dx=\frac{1}{2\pi}[-\frac{x}{2n}cos(2nx)+\frac{1}{4n^2}sin(2nx)]_{-\pi}^{\pi}=\frac{1}{2\pi}[-\frac{\pi}{2n}(1)^n-\frac{\pi}{2n}(-1)^n]$$

18. May 27, 2010

### Cyosis

You're almost there.

$$\frac{1}{2\pi}\int_{-\pi}^{\pi}xsin(2nx)dx = \underbrace{\frac{1}{2\pi}[-\frac{x}{2n}cos(2nx)+\frac{1}{4n^2}sin(2nx)]_{-\pi}^{\pi}}_\text{correct} =\underbrace{\frac{1}{2\pi}[-\frac{\pi}{2n}(1)^n}_\text{missing a factor}-\underbrace{\frac{\pi}{2n}(-1)^n}_\text{wrong}]$$

Also $1^n=...$?

19. May 27, 2010

### rayman123

should it be $$2n$$
hm....the term with sin2nx will give 0 right?
for the rest i get :
$${\frac{1}{2\pi}[-\frac{\pi}{2n}(1)^{2n}+\frac{\pi}{2n}(-1)^{2n}]$$
but according to what you have written it is still wrong,

20. May 27, 2010

### Cyosis

You found the correct primitive. Now all you have to do is plug in the limits of integration. You're nearly there, but don't get sloppy with simple arithmetic.

Yes the $\sin 2 n \pi$ term is zero for every $n \in \mathbb{Z}$. Don't forget to answer my question in post #18.

Last edited: May 27, 2010