I have to solve the following initial and boundary value problem: $$u_t=u_{xx}, 0<x<L, t>0$$ $$u(0,t)=u_x(L,t)=0, t>0$$ $$u(x,0)=x, 0<x<L$$
I have done the following:
Using the method of Separation of Variables, the solution is of the form: $u(x,t)=X(x) \cdot T(t)$ Replacing this at $(1)$, we get the following two problems: $$\left.\begin{matrix} X''+\lambda X=0, 0<x<L\\ X(0)=X'(L)=0 \end{matrix}\right\}(2)$$ and $$\left.\begin{matrix} T'+ \lambda T=0, t>0 \end{matrix}\right\}(3)$$
$$u(x,0)=X(x)T(0)=x$$
Solving the problem $(2)$ we get: $$X_n(x)=\sin{(\frac{(2n+1) \pi x}{2L})}, n=0,1,2,3, \dots$$ and solving the problem $(3)$ we get: $$T_n(t)=A_n e^{-(\frac{(2n+1) \pi}{2L})^2t}, n=0,1,2,3, \dots$$ The solution is of the form: $$u(x,t)=\sum_{n=0}^{\infty}{A_n \sin{(\frac{(2n+1) \pi x}{2L})} e^{-(\frac{(2n+1) \pi}{2L})^2t}}$$ $$u(x,0)=x \Rightarrow x=\sum_{n=0}^{\infty}{A_n \sin{(\frac{(2n+1) \pi x}{2L})}}$$
Is this correct so far?
How can I calculate the coefficients $A_n$?
Here we find $A_n$ by:
$A_n=\frac{2}{L}\int_0^Lx\sin(\frac{(2n+1)\pi x}{2L})dx$
$=\frac{2}{L}(-\frac{2L}{(2n+1)\pi})[x\cos(\frac{(2n+1)\pi x}{2L})|^L_0]+\frac{2}{L}(\frac{2L}{(2n+1)\pi})\int_0^L\cos(\frac{(2n+1)\pi x}{2L})dx$
$=\frac{2}{L}(\frac{2L}{(2n+1)\pi})(-L\cos(\frac{(2n+1)\pi}{2}))+\frac{2}{L}(\frac{2L}{(2n+1)\pi})^2(\sin(\frac{(2n+1)\pi x}{2L})|^L_0)$
$=-\frac{4L}{(2n+1)\pi}\cos(\frac{(2n+1)\pi}{2})+\frac{2}{L}(\frac{2L}{(2n+1)\pi})^2\sin(\frac{(2n+1)\pi}{2})$
$=(-1)^n\frac{2}{L}(\frac{2L}{(2n+1)\pi})^2$