# Fourier Series for a piecewise function help

1. Apr 24, 2013

### dinospamoni

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

I'm trying to find a Fourier series for the piecewise function where f(x)=

$0 \in -\pi \leq x \leq 0$
$-1 \in 0 \leq x \leq \frac{\pi}{2}$
$1 \in \frac{\pi}{2} \leq x \leq \pi$

2. Relevant equations

$$a_{n} = \frac{1}{\pi} \int_{0}^{2\pi}\cos(nx)y(x)\,dx$$
$$b_{n} = \frac{1}{\pi} \int_{0}^{2\pi}\sin(nx)y(x)\,dx$$

3. The attempt at a solution

I found the pattern that every even a is 0, so that becomes
$$a_{m} = \sum_{m=1}^{\infty}\frac{(-1)^{m}2}{(2m-1)\pi}$$

and the b coefficients are 0 when n is odd and 0 for every other even n, so that becomes
$$b_{m} = \sum_{m=1}^{\infty}\frac{-2}{\frac{4m-2}{2}\pi}$$

however when I plot this, the plot between -pi and -pi/2 is switched with the plot between pi/2 and pi

I attached a picture for reference along with a plot of f(x)

Any ideas of where i went wrong?

#### Attached Files:

File size:
17.6 KB
Views:
60
• ###### Screen capture00000000000000000 2013-04-24 at 4.02.58 PM.JPG
File size:
10 KB
Views:
56
Last edited: Apr 24, 2013
2. Apr 24, 2013

### vela

Staff Emeritus

3. Apr 24, 2013

### dinospamoni

Whoops sorry, I forgot I didn't do this all in mathematica:

$a_{0} = 0$

$a_{1} = \frac{-2}{\pi}$

$a_{2} = 0$

$a_{3} = \frac{2}{3\pi}$

$a_{4} = 0$

$a_{5} = \frac{-2}{5\pi}$

$a_{6} = 0$

$b_{1} = 0$

$b_{2} = \frac{-2}{\pi}$

$b_{3} = 0$

$b_{4} = 0$

$b_{5} = 0$

$b_{6} =\frac{-2}{3\pi}$

$b_{7} = 0$

$b_{8} = 0$

$b_{9} = 0$

$b_{10} =\frac{-2}{5\pi}$

$b_{11} = 0$

$b_{12} = 0$

$b_{13} = 0$

$b_{14} = \frac{-2}{7\pi}$

Last edited: Apr 24, 2013
4. Apr 24, 2013

### dinospamoni

And I figured out the summations from just looking at these in terms of n:

$a_{n} = \sum\frac{(-1)^{n}2}{n\pi}$

$b_{n} = \sum\frac{-2}{\frac{n}{2}\pi}$

and then to get rid of the 0s I made it in terms of m:

$a_{m} = \sum\frac{(-1)^{m}2}{(2m-1)\pi}$

$b_{m} = \sum\frac{-2}{\frac{4m-2}{2}\pi}$

The function is then:

$$g(x) = \sum_{m=1}^{\infty} a_m Cos((2m-1)x) + \sum_{m=1}^{\infty} b_m Sin((2m-1)x)$$

Last edited: Apr 24, 2013
5. Apr 24, 2013

### dinospamoni

I figured out what I did wrong, but thanks!