Finding the Fourier series

85 Views Asked by At

I am trying to write the Fourier series for the following function

$$f(x) = \left\{\begin{aligned} &0 && -\pi<x<0\\ &e^{-x} && 0<x<\pi \end{aligned} \right.$$

I used all the same formulas I always use, but the coefficients I got look a bit strange to me

\begin{aligned} a_0 = \frac{1}{\pi}\int_0^\pi e^{-x}dx = \frac{1-e^{-\pi}}{\pi} \end{aligned}

\begin{aligned} a_n = \frac{1}{\pi}\int_0^\pi e^{-x} \cos(nx)dx = \frac{1}{\pi}\int_0^\pi e^{-x}\frac{e^{inx}+e^{-inx}}{2} = \frac{1-e^{-\pi}(-1)^n}{\pi(1+n^2)} \end{aligned}

\begin{aligned} b_n = \frac{1}{\pi}\int_0^\pi e^{-x} \sin(nx)dx = \frac{1}{\pi}\int_0^\pi e^{-x}\frac{e^{inx}-e^{-inx}}{2i} = \frac{n-ne^{-\pi}(-1)^n}{\pi(1+n^2)} \end{aligned}

...and my final solution for the series is

\begin{aligned} F(x) = \frac{1-e^{-\pi}}{2\pi} + \sum_{n=1}^\infty \frac{1-e^{-\pi}(-1)^n}{\pi(1+n^2)} \cos(nx) + \sum_{n=1}^\infty \frac{n-ne^{-\pi}(-1)^n}{\pi(1+n^2)} \sin(nx) \end{aligned}

I tried plotting $F(x)$ and it looked nothing like my function. My other method of checking the solution is to evaluate $F(x)$ at e.g. $x=0$ and see if I get the right sum, but I had no luck doing that either.

I'd be very grateful if anybody could tell me if there's something wrong with my math.

2

There are 2 best solutions below

3
On

Since I cannot comment, here's the plot of your Fourier transform: enter image description here

Your solution is correct. If you're interested this code was used to calculate the function(in Matlab):

 function [ y ] = Untitled2( x)
suma = (1-exp(-pi))./(2 * pi);
for n = 1:1000
   suma = suma + cos(n.*x).*(1- exp(-pi).*((-1).^n))./(pi.*(1 + n^2)); 
   suma = suma + sin(n.*x).*(n- n.*exp(-pi).*((-1).^n))./(pi.*(1 + n^2));
end
y = suma;
end
0
On

The approach suggested by @user1949350 is correct and will work most of the time but I may have found something. It MUST be changed so that it incorporates the idea of convergence within a particular tolerance level. So I am just gonna take his code and extend it to include that part too.

function [ y ] = abc(x,tol)
    suma = (1-exp(-pi))/(2 * pi) * ones(1,length(x));
    sumb = Inf(1,length(x));
    n = 1;

    while(max(abs(sumb-suma)) > tol)
       disp(n);
       sumb = suma;
       suma = suma + cos(n.*x).*(1- exp(-pi).*((-1).^n))./(pi.*(1 + n^2)); 
       suma = suma + sin(n.*x).*(n- n.*exp(-pi).*((-1).^n))./(pi.*(1 + n^2));
       n = n+1;
    end
    y = suma;
end

When I set tol = $10^{-4}$, it took about 3000 iterations to converge to that tolerance. So, 1000 terms is a pretty good approximation for this function, but it doesn't lie within $10^{-4}$ tolerance. The plot of the Fourier series looks pretty much the same:

enter image description here

Cheers!