I've been trying to solve the following equation
$$u_t - a^2 u_{xx} = tx, \ \ \ x \in (0, \pi), \ \ t>0$$ $$u_x(0,t)=u_x(\pi, t) = 0, \ \ \ t \ge 0$$ $$u(x, 0) = 1 \ \ \ x \in (0, \pi)$$
So I put $u(x, t) = T(t)X(x)$ and solve the homogeneous equation:
$$\frac{T'}{T} = \frac{X''}{X}= - \lambda$$
$$T(t) = D e^{-\lambda t}$$
$$X(x) = C_1 \sin(\sqrt{\lambda}\cdot x)) + C_2 \cos(\sqrt{\lambda} \cdot x))$$ Next, $$X'(x)= C_1 \sqrt{\lambda} \cos(\sqrt{\lambda} x) - C_2 \sqrt{\lambda} \sin(\sqrt{\lambda} x)$$
So $$X'(0) = C_1 \sqrt{\lambda} = 0 \implies C_1=0$$ $$X'(\pi) = - C_2 \sqrt{\lambda} \sin (\sqrt{\lambda} x) = 0 \implies \sqrt{\lambda} = k, \ k \in \mathbb{Z}$$
$$X(x) = C_2 \cos(\sqrt{\lambda} x) \implies X_n(x) = C_n \cos(nx)$$
And $T_n(t) = D_n e^{-n^2t}$
Now, $u(x, 0) = \sum_{n=1}^{\infty} C_n(0) \cos (nx)=1$
And the Fourier series coefficients for $1$ with cosines seem to be $C_n(0) = \frac{1}{\pi } \int_{-\pi}^{\pi} \cos (nx)dx$ But this is zero!
Is that correct? Is there a mistake somewhere in my solution?
Seek a solution of the form $$u(x,t)=\sum_{\lambda}C_{\lambda}(t)X_{\lambda}$$ where $X_{\lambda}$ are eigenfunctions of the operator $\frac{d^2}{dx^2}$ with homogeneous Neumann boundary conditions. We know the eigenfunctions are $1$ and $\cos(nx)$, $n \in \mathbb{N}$. Thus, we have
$$u(x,t)=\sum_{n=0}^{\infty}C_n(t)\cos(nx)$$
Substituting the trial solution into the PDE gives
$$\sum_{n=0}^{\infty}\left \{\left[C'_n(t)+n^2a^2C_n(t)\right]\cos(nx)\right \}=tx$$
By orthogonality of the eigenfunctions $\cos(nx)$ for different eigenvalues, we know that for $n \neq 0$
$$C'_n(t)+n^2a^2C_n(t)=\frac{2}{\pi}\int_{0}^{\pi}tx\cos(nx)dx$$
$$C_n'(t)+n^2a^2C_n(t)=\frac{2t}{\pi n^2}[(-1)^n-1]$$
Given the initial condition, we require $C_n(0)=0$ for $n \neq 0$ and $C_0(0)=1$. From this, we can construct the Green function for this ODE. The solution to the homogeneous ODE is
$$C_n(t)=Ce^{-n^2a^2t}$$
So the Green function is
$$G(t,\xi)=\begin{cases} Ae^{-n^2a^2t} & t<\xi \\ Be^{-n^2a^2t} & t>\xi \end{cases}$$
The initial condition gives $A=0$ and the requirement $G(\xi^+,\xi)-G(\xi^-,\xi)=1$ gives $B=1$. Thus,
$$G(t,\xi)=H(t-\xi)e^{-n^2a^2t}$$
where $H$ is the Heaviside function. So
$$C_n(t)=\int_{0}^{\infty}\frac{2\xi}{\pi n^2}[(-1)^n-1]H(t-\xi)e^{-n^2a^2t}d\xi$$
Thus, the solution to the PDE is
$$u(x,t)=1+\sum_{n=1}^{\infty}\left \{ \left[\int_{0}^{\infty}\frac{2\xi}{\pi n^2}[(-1)^n-1]H(t-\xi)e^{-n^2a^2t}d\xi\right]\cos(nx) \right \}$$