I'd like to solve a simple ODE using Fourier series on $[0,L]$.
$d^2\phi/dx^2=0$, with boundary conditions $\phi(0)=0, \phi(L)=P$.
Simple integration results in $\phi(x) = Px/L$.
The Fourier series on $[0,L]$ of this solution is $\phi(x) = \sum_{n\neq 0} \frac{i P}{2\pi n} e^{i k_n x}$, where $k_n = 2\pi n /L$. (I used $c_n = \frac{1}{L}\int_0^L \frac{Px}{L}e^{-i k_n x} dx$).
This gives a saw tooth like function, as expected. However, I would like to solve it for $c_n$ directly, and that is where I get stuck:
$\phi(x) = c_0 + \sum_{n\neq 0} c_n e^{i k_n x}$, filling in, into the ODE gives $-\sum_n c_n k_n^2 e^{i k_n x}=0$.
Since $e^{i k_n x}$ form a basis (or take $\left<...|e^{i k_m x} \right>=\frac{1}{L}\int_0^L ... e^{-i k_m x} dx$, and $\left<e^{i k_n x}|e^{i k_m x} \right>=\delta_{n,m}$) we know that each term should be zero separately: $c_n k_n^2=0$, in other words $c_n=0$.
To fit the boundary conditions, we use $c_0=0$ for the first one, but $c_0=P$ for the second, impossible.
Did I make a mistake somewhere? I know it can be solved because $c_n = \frac{i P}{2\pi n}$ gives the correct answer.
Yes. you solve the ode through simple integration then take the fourier transform of that solution. These 2 functions are not the same. One is periodic and one is not. Which leads to the fourier series not fufilling the ode.