I am having trouble solving the following Partial Differential Equation:
PDE: $$u_t = u_{xx}$$
Boundary Conditions: $$u_x(0,t) = 0$$ and $$u_x(1,t) = 0$$ for $0<t<\infty$
Initial Condition: $$u(x,0) = x$$
When I compute the following IVBP, I am off by a single, constant term. Here is my work: Assume that $u(x,t) = X(x)T(t)$.
Thus, $u_t = X(x)T'(t)$ and $u_{xx} = X''(x)T(t)$. Plugging these two terms back into the PDE yields, $X(x)T'(t) = X''(x)T(t)$ which can then be rearranged into $\frac{T'(t)}{T(t)} = \frac{X''(x)}{X(x)} = -\lambda ^2$ ($\lambda$ is constant since X only depends on x and T only depends on t the ratio must be equal according to the PDE). Solving for each side of the equation yields, $T(t) = e^{(-\lambda ^2)t}$ and $X(x) = A\sin (\lambda x)+ B\cos (\lambda x)$.(I left the constants in this product) Finally the PDE is of the form $$u(x,t) = e^{(-\lambda ^2)t}[A\sin (\lambda x)+B\cos (\lambda x)]$$ Then I solve the equation using the initial conditions,such that $$u_x(x,t) = e^{(-\lambda ^2)t}[A\lambda \cos (\lambda x)-B\lambda \sin (\lambda x)]$$. Thus, $u_x(0,t)= 0 = e^{(-\lambda^2)t}[A\lambda \cos (0)-B \lambda \sin (0)] = A = 0$. Going to the second boundary condition: $u_x(1,t) = e^{(-\lambda ^2)t}[-B\lambda \sin (\lambda)] = \sin (\lambda) = 0$. Consider the nontrivial solution where $B \neq 0$, then $\lambda = n\pi$ where $n$ is in the set of integers greater than 0. Thus the final form of the solution is $$u(x,t) = Be^{(-\lambda ^2)t}\cos (n\pi x)$$ From here I assumed that if there are many $n$ that satisfy the IVBP, then you can sum all of them. Thus $$u(x,t) = \sum b_n e^{(-\lambda ^2)t}\cos (n\pi x) $$ To solve for the amplitude I use the concept of orthogonality of cosines, such that $u(x,0)\cos (m \pi x) = x\cos (m \pi x) = \sum b_n \cos (n \pi x) \cos (m \pi x)$ and since $\int_0^1 \cos (m \pi x)\cos (n \pi x)dx$ is equal to 0 when $m \neq n$ and equal to $\frac{1}{2}$ when $m=n$. Thus I have to solve for $\int_0^1x\cos (m \pi x)dx$ which I got $\frac{-2}{m^2\pi ^2}$ when m is even. On the other side, the end result is: $\int_0^1\cos ^2(n\pi x)dx = \frac{1}{2}$. So then finally putting it all together:$u(x,0)\cos (m \pi x) = x\cos (m \pi x) = \sum b_n \cos (n \pi x) \cos (m \pi x)$ is converted into $\frac{-2}{m^2\pi ^2}= \frac{b_n}{2}$ and thus $b_n = \frac{-4}{m^2\pi ^2}$. For my final result, I got $$u(x,t) = \frac{-4}{n^2\pi ^2}\sum e^{(-n\pi)^2t}\cos (n\pi x)$$. My textbook has a similar but slightly different answer, that is: $$u(x,t) = \frac{1}{2}-\frac{4}{n^2\pi ^2}\sum e^{(-n\pi)^2t}\cos (n\pi x)$$. So what exactly am I not getting??
The general solution is $$ u(x,t) = \sum_{n=0}^{\infty} b_ne^{-n^2\pi^2 t}\cos(n\pi x). $$ The set $\{ 1,\cos(\pi x),\cos(2\pi x),\cos(3\pi x),\cdots\}$ is a complete orthogonal subset of $L^2[0,1]$. So the constants $b_n$ are determined by orthogonality. Multiplying $x=u(x,0)=b_0+b_1\cos(\pi x)+b_2\cos(2\pi x)+\cdots$ by $\cos(n\pi x)$ and integrating over $[0,1]$ gives $$ \int_0^1 x\cos(n\pi x)dx = b_n\int_0^1 \cos^2(n\pi x)dx \\ b_n = \frac{\int_0^1 x\cos(n\pi x)dx}{\int_0^1\cos^2(n\pi x)dx}. $$ For $n=0$, $$ b_0 = \frac{\int_0^1 xdx}{\int_0^1 dx}=\frac{1}{2}. $$ For $n > 0$, \begin{align} b_n &= \frac{\int_0^1 x\cos(n\pi x)dx}{\int_{0}^{1}\cos^2(n\pi x)dx} \\ &=\frac{x\frac{\sin n\pi x}{n\pi}|_{0}^1-\int_0^1\frac{\sin(n\pi x)}{n\pi}dx}{1/2} \\ &=-\frac{2}{n\pi}\int_0^1\sin(n\pi x)dx \\ &=\frac{2}{n^2\pi^2}\cos(n\pi x)|_{x=0}^{1} \\ &=\frac{2}{n^2\pi^2}((-1)^n-1) = \left\{ \begin{array}{cc}-\frac{4}{n^2\pi^2} & n\;\; \mbox{odd}\\ 0 & n\;\; \mbox{even}\end{array}\right. \end{align} Therefore, $$ u(x,t)=\frac{1}{2}-\sum_{k=0}^{\infty}\frac{4}{(2k+1)^2\pi^2}e^{-(2k+1)^2\pi^2 t }\cos((2k+1)\pi x). $$