PDE: Heat equation problem 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?
 A: 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}
A: The short answer is you cannot assume, in general, separation of variables in a non-homogenous problem. Since your boundary conditions are homogenous, solve the alternative problem $\theta_t = \theta_{xx}$ with the same boundary conditions (no matter the initial condition) and then expand:
$$ u(x,t) = \sum_n T_n(t) X_n(x), $$ where $X_n(x)$ are the eigenfunctions of the homogenous problem (I think they are $X_n(x) = \cos{n x}$). Since the functions $X_n$ form a complete basis on $0 \leq x \leq \pi$, any smooth function can be approximated/represented according to the series above.
Plug the series in the original PDE and use the orthogonality properties of $X_n$ to find the coefficients $T_n(t)$, which will satisfy a first order differential equation. The initial condition for $T$ can be extracted from the initial condition of $u$ using, again, orthogonality.
I think this is often referred to as Fredholm's alternative.
Hope this helps!
