# Find the Fourier series

1. Aug 22, 2011

### Nallyfish

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

The function f has period 4 and is such that
f(x)=2+x, -2<x$\leq0$
f(x)=2, 0<x<2

Sketch the graph of f for x∈[−4, 4] and obtain its Fourier series.

2. Relevant equations

3. The attempt at a solution

Okay so I've pretty much sketched the graph, but I've been thrown by the 2+x and I'm not sure what to do from this point onwards.

So a0=$\frac{1}{2}$$\int^{2}_{0}2dx$=2

an=$\frac{1}{2}$$\int^{2}_{0}2*cosnxdx$

So
an=$\frac{sin2n}{n}$

And
bn=$\frac{-(cos(2n)-1)}{n}$

Am I on the right lines...?

Last edited: Aug 22, 2011
2. Aug 22, 2011

### LCKurtz

No, you aren't. You are given one period of a function whose period is 4. That is a two piece function defined on (-2,2). If you have graphed it you will know that it is neither even nor odd so you may not use the half-range formulas for the coefficients. The formula for an in this problem is

$$a_n = \frac{1}{2}\int_{-2}^{2}f(x)\cos(\frac{n\pi}{2}x)\, dx$$

and similarly for bn. You have to break these intgrals up into (-2,0) and (0,2) and use the appropriate formula for f(x) in each.

3. Aug 22, 2011

### Nallyfish

Oh god, I'm an idiot. Thank you for that! Can't believe I did that.

So I now have

an=$\frac{1}{2}$$\int^{0}_{-2}(2+x)cos(\frac{n\pi}{2})xdx$+$\frac{1}{2}$$\int^{2}_{0}2cos(\frac{n\pi}{2})xdx$

= $\frac{4sin(n\pi)}{n\pi}$

and bn= $\frac{-2(ncos(n\pi))(\pi-sin(n\pi))}{n2\pi2}$

4. Aug 22, 2011

### Nallyfish

Sorry, I forgot to take the sines and cosines out

an=$\frac{2}{n^{2}\pi^{2}}$

and

bn= 0

Is what I've got which I HOPE is correct.
This would make the Fourier series

f(x)=$\frac{3}{2}$*$\sum^{\infty}_{n=1}\frac{2}{n^{2}\pi^{2}}cos(\frac{(n\pi)x}{2})$

5. Aug 22, 2011

### LCKurtz

That can't be correct because your original f(x) is neither even nor odd, and this answer is an even function. You can't have all the bn be zero.

6. Aug 23, 2011

### Nallyfish

I keep reaching different answers for my an and bn

an= $\frac{2(n+1)}{n^{2}\pi^{2}}$

and

bn= $\frac{2(n\pi^{2}+\pi^{2}-1)}{n\pi}$

7. Aug 23, 2011

### LCKurtz

Those are both wrong and you haven't calculated a0. Here's what you should get for your constants:

$$a_n=\frac{(-1)^{n+1}+1}{\pi n^2}$$
$$b_n=\frac{(-1)^{n+1}}{n}$$
$$a_0=2-\frac{\pi}{4}$$

Keep trying.

8. Aug 23, 2011

### vela

Staff Emeritus
Those aren't correct. You should get
\begin{align*}
a_n &= (1+(-1)^{n+1})\frac{2}{n^2\pi^2} \\
b_n &= (-1)^{n+1}\frac{2}{n\pi}
\end{align*}
I think you dropped a factor of pi somewhere, LCKurtz.

9. Aug 23, 2011

### Nallyfish

I got a0= $\frac{3}{2}$

Because I thought the formula was

$\frac{1}{2L}$$\int^{L}_{-L}f(x)dx$

and L is 2 so

a0= $\frac{1}{4}$[$\int^{0}_{-2}(2+x) dx + \int^{2}_{0}2 dx]$

Which would give $\frac{3}{2}$

10. Aug 23, 2011

### LCKurtz

Yes, 3/2 is correct for a0. Vela's formulas for the coefficients are correct. I inadvertently used L = pi instead of L = 2 when I calculated the coefficients.