How to find the cosine series when solving a PDE with Dirichlet conditions? Suppose I have to solve
$\sum_{n=0}^{\infty} A_n \cos(\frac{(n+1/2)\pi x}{L}) = x $ from $0$ to $L$.
If I we want to find $A_n$ my professor uses the formula for a cosine series:
$$\frac{2}{L}\int_{0}^{L} x \cos \left(\frac{(n+1/2)\pi x}{L}\right) dx= A_n$$
But this doesn't make any sense to me. I know this procedure works when the trig functions have an argument whose form is $\frac{n\pi x}{L}$ not $\frac{(n+1/2)\pi x}{L}$. 
Why does this procedure work?
 A: Let $\phi_n(x) = \cos\left(\frac{(n+1/2)\pi x}{L}\right)$. Observe that $\phi_n'(0)=0$ and $\phi_n(L)=0$. This, of course, is not a random observation: the functions $\phi_n$ were chosen specifically to fit these boundary conditions. That, and they are eigenfunctions of the second-derivative operator, meaning $\phi_n'' = \lambda_n \phi_n$ with  eigenvalue $\lambda_n=-\left(\frac{(n+1/2)\pi }{L}\right)^2$.
The above properties ensure that $\phi_n$ are mutually orthogonal: that is, $\int_0^L \phi_n(x)\phi_m(x)\,dx=0$ whenever $n\ne m$. No need to mess with trigonometric identities: just integrate by parts twice.
$$
\int_0^L \phi_n(x)\phi_m(x)\,dx=
\frac{1}{\lambda_m}   \int_0^L \phi_n(x)\phi_m''(x)\,dx 
= -\frac{1}{\lambda_m}   \int_0^L \phi_n'(x)\phi_m'(x)\,dx
\\=  \frac{1}{\lambda_m}   \int_0^L \phi_n''(x)\phi_m(x)\,dx
=\frac{\lambda_n}{\lambda_m}   \int_0^L \phi_n(x)\phi_m(x)\,dx$$
(The boundary terms are all zero, thanks to the boundary conditions.) Since $\frac{\lambda_n}{\lambda_m} \ne 1$, the integral is zero.
So, whenever  we need $\sum A_m \phi_m =f$, multiplying both sides by $\phi_n$ and integrating gives
$$A_n=\frac{\int_0^L f(x)\phi_n(x)\,dx}{\int_0^L  \phi_n(x)^2 \,dx}$$
which is the stated formula.
