can someone help by checking my working and perhaps explain where i'm going wrong?
solve the following problem with insulated boundaries $$\text{PDE: }~u_t=u_{xx}$$ $$ \text{BCs: }~u_x(0,1) = 0~\&~ u_x(1,t)=0$$ $$ \text{IC: }~u(x,0)=x$$
we start with solving the PDE by substituting $$u(x,t)=X(x)T(t)$$ into the above this gives $$u(x,t) = \sum_{n=1}^\infty A_n e^{(-n\pi)^2t}\cos{n\pi x}$$ where $$A_n = 2 \int_{0}^{1} x\cos{n\pi x}$$
then i make $$A_n = 2* \left[ \frac{x\sin{n \pi x}}{n \pi}|_{0}^{1} - \frac{\cos{n \pi x}}{n^2 \pi^2} |_{0}^{1}\right] = -\frac{\cos{n \pi} - 1}{n^2 \pi^2} = \frac{1-(-1)^{n}}{n^2 \pi^2}$$ which alternates between 0 and 2 so letting $n = 2k+1$ $$A_k = \frac{4}{(2k+1)^2 \pi^2}$$ substituting back in and changing the index gives $$u(x,t) = A_0 + \sum_{k=1}^\infty \frac{4}{(2k+1)^2 \pi^2} e^{(-(2k+1)\pi)^2t}\cos{(2k+1)\pi x}$$ $$u(x,t) = \frac{4}{\pi^2} + \frac{4}{\pi^2}\sum_{k=1}^\infty \frac{e^{-((2k+1)\pi)^2t}}{(2k+1)^2}\cos{(2k+1)\pi x} $$
which is different from their solution of
$$u(x,t) = \frac{1}{2} - \frac{4}{\pi^2} \sum_{n=1}^{\infty} \frac{1}{n^2}e^{-(n\pi)^2t} \cos{n\pi x}$$
any ideas where i went wrong? cheers
First of all, you're missing the constant eigen-function, so the full solution is
$$ u(x,t) = A_0 + \sum_{n=1}^\infty A_n e^{-n^2\pi^2t}\cos(n\pi x) $$
The constant is given by
$$ A_0 = \frac{\int_0^1 x\ dx}{\int_0^1 1^2 dx} = \frac12 $$
For the remaining coefficients
$$ A_n = \frac{\int_0^1 x \cos(n\pi x)\ dx}{\int_0^1 \cos^2(n\pi x)\ dx} = 2\int_0^1x\cos(n\pi x)\ dx $$
You made a small sign error at this point. Integration by parts gives
\begin{align} A_n &= \frac{2x\sin(n\pi x)}{n\pi}\Bigg|_0^1 - \int_0^1 \frac{2\sin(n\pi x)}{n\pi}\ dx \\ &= \frac{2\cos(n\pi x)}{n^2\pi^2}\Bigg|_0^1 \\ &= \frac{2}{n^2\pi^2}(\cos(n\pi)-1) \\ &= \frac{2}{n^2\pi^2}((-1)^n-1) \end{align}
which equals $0$ when $n$ is even and $-\frac{4}{n^2\pi^2}$ when $n$ is odd, so the final solution is
$$ u(x,t) = \frac12 - \sum_{n=2k+1,k=0}^\infty\frac{4}{n^2\pi^2} e^{-n^2\pi^2t}\cos(n\pi x) $$
The answer key probably forgot to say that $n$ needs to be odd.