Non homogeneous heat equation How to solve the following PDE?
\begin{align*}
u_t - u_{xx} = tx & \; ; 0<x<\pi, t>0 \\ 
u(x,0)=1 &\; ; 0\le x\le \pi\\ 
u_x(0, t) = u_x(\pi , t)=0&\; ; t> 0 
\end{align*}
For homogenous equation, the solution seems to be constant $u(t,x) = 1$. Book says to consider $u(t,x) = \sum_{k\ge 0} c_k(t) v_k(x)$ where $v_k(x)$ is (spatial) solution of homogeneous problem. But I can't seem to solve it, if I put $v(x) = 1$, I get $u(t,x) = \frac{t^2}{2}x + 1$ which does not fit in the last boundary condition. 
Thanks for you help!!
 A: To solve the heat equation, using the separation of variables and decomposition into Fourier series usually works well.
Consider the homogeneous equation
\begin{align*}
 & u_t-u_{xx}=0\\
 & u_x(0,t)=u_x(\pi,t)=0
\end{align*}
whitout bothering about the initial condition. We wish to find solutions of the form $u(x,t)=c(t)v(x)$. Plugging this into the equation, we get
$$
 c'(t)v(x)-c(t)v''(x)=0.
$$
This equation has to be true for any $x,t$, which means there exists $k\geq0$ such that $c'=\pm k^2 c$ and $v''=\pm k^2 v$. We only seek physically relevant solutions, so we can disregard the case $c'=k^2c$, because it would lead to a diverging solution when $t\to+\infty$. The equation for $v$ becomes $v'+k^2v=0$, and the general solution of this equation is 
$$
 \{x\mapsto A\cos(kx)+B\sin(kx),\;A,B\in\mathbb{R}\}
$$
The condition $u_x(0,t)=u_x(\pi,t)=0$ implies $B=0$ and $k\in\mathbb{N}$. Thus, for $k\in\mathbb{N}$, let
$$
 \boxed{v_k:x\mapsto A_k\cos(kx)}.
$$
Note that this will be very convenient for Fourier series.

Now, what if we plug a function $u_k(x,t)=c_k(t)v_k(t)$, where $c_k$ is to be determined, into $u_t-u_{xx}$? We get
$$
 (c'_k(t)+k^2c_k(t))A_k\cos(kx)
$$
We want to find $u(x,t)=\sum{k\geq0} u_k(x,t)$ such that it verifies the inhomogeneous equation, so we seek $c_k$ such that
$$
 (c'_k(t)+k^2c_k(t))A_k\cos(kx)=tA_k\cos(kx)
$$
which is equivalent, assuming continuity, to
$$
 c'_k(t)+k^2c_k(t)=t
$$
If $k=0$, the solution is $\boxed{c_0(t)=t^2/2+B_0}$.
Assume that $k>0$.
One solution to the homogeneous version of this equation is $\lambda(t)=\exp(-k^2t)$. Using the variation of parameters, $c_k=y\lambda$ with $y'(t)=t\exp(k^2t)$, thus
$$
 \boxed{c_k:t\mapsto\frac{1}{k^4}(tk^2-1)+B_k\exp(-k^2t)}.
$$

Consider $u(x,t)=\sum_{k\geq0}c_k(t)v_k(x)$. We want $u$ to be a solution of the PDE.
$$
 u_t-u_{xx}=\sum_{k\geq0} tA_k\cos(kx)=t\sum_{k\geq0} A_k\cos(kx)=tx
$$
thus
$$
 A_k=\frac{2}{\pi}\int_0^\pi x\cos(kx)\mathrm{d}x=\begin{cases}\pi&\text{if }k=0 \\ \frac{2}{\pi}\frac{(-1)^k-1}{k^2} & \text{if not}\end{cases}
$$
Finally, we need to make sure $u$ verifies the boundary conditions. We already have $u_x(0,t)=u_x(\pi,t)=0$, so the only remaining problem is $u(x,0)=1$.
$$
 u(x,0)=B_0A_0+\sum_{k\geq1}\left(B_k-\frac{1}{k^4}\right)v_k(x).
$$
Therefore, setting
$$
 B_k=\begin{cases}1/A_0=1/\pi & \text{if }k=0 \\ \frac{1}{k^4} &\text{if not}\end{cases}
$$
solves the problem.
