TITLE: PDE: Heat equation problem
QUESTION [5 upvotes]: I'm trying this PDE: $$u_t = u_{xx} + g(x);\quad x\in[0,\pi]$$
With boundary conditions: $$u_x (0,t)=u_x(\pi,t)=0$$
And initial condition: $$u(x,0)=f(x)$$
I think variable separation proposing a u(x,t)= X(x)T(t) could be a good approach but: $$Let\quad u(x,t)=X(x)T(t)$$ $$\Rightarrow X(x)T'(t)=X''(x)T(t)+g(x)$$
Then trying to separate I get: $$\frac {T'(t)}{T(t)}=\frac {X''(x)}{X(x)}+ \frac {g(x)}{X(x)T(t)}$$
I don't know how to make that last last function just dependant of one variable. Any ideas or am I taking the wrong path?

REPLY [2 votes]: If $u$ is a solution of the given problem, then
$$
v(x,t)=u(x,t)+\int_{0}^{x}\int_{0}^{x'}g(x'')dx''dx'-\frac{1}{\pi}\int_{0}^{\pi}g(y)dy\, (t+x^{2}/2).
$$
is a solution of
\begin{align}
v_{t} &= u_{t}-\frac{1}{\pi}\int_{0}^{\pi}g(y)dy=u_{xx}+g-\frac{1}{\pi}\int_{0}^{\pi}g(y)dy=v_{xx} \\
v_{x}(0,t) &= u_{x}(0,t) = 0, \\
v_{x}(\pi,t) &= u_{x}(\pi,t)+\int_{0}^{\pi}g(x'')dx''-\frac{\pi}{\pi}\int_{0}^{\pi}g(y)dy = u_{x}(\pi,t)=0. \\
v(x,0) &= u(x,0)+\int_{0}^{x}\int_{0}^{x'}g(x'')dx''dx'-\frac{x^{2}}{2\pi}\int_{0}^{\pi}g(y)dy
\end{align}
So the inhomogeneous problem is reduced to the equivalent homogeneous problem
\begin{align}
v_{t} &= v_{xx}, \\
v_{x}(0,t) &= 0,\hspace{5mm} v_{x}(\pi,t) = 0,\\
v(x,0) &= f(x)+\int_{0}^{x}\int_{0}^{x'}g(x'')dx''dx'-\frac{x^{2}}{2\pi}\int_{0}^{\pi}g(y)dy.
\end{align}