Fourier's Heat PDE with time dependent heat source I have a PDE for $x\in [0,L]$:
$$u_t=\alpha u_{xx}+f(t)$$
BCs and IC:
$$u(0,t)=u(L,t)=0\text{ and }u(x,0)=f(x)$$
My first 'instinct' is to solve the homogeneous PDE.
$$\alpha u_{xx}+f(t)=0$$
$$\alpha u_E''(x)=-f(t)$$
$$u_E(x)=-\frac12 f(t)x^2+c_1 x+c_2$$
With the BCs:
$$c_2=0$$
$$c_1=\frac12 f(t)L$$
Then, with  the superposition principle, we look for a new function $v(x,t)$:
$$u(x,t)=v(x,t)+u_E(x)$$
$$u_t=v_t$$
$$u_x=v_{xx}$$
The latter solves easily to:
$$v\left( {x,t} \right) = \sum\limits_{n = 1}^\infty  {{A_n}\sin \left( {\frac{{n\pi x}}{L}} \right){{\bf{e}}^{ - \alpha{{\left( {\frac{{n\pi }}{L}} \right)}^2}\,t}}}$$
At $t=0$:
$$v(x,0)=f(x)-u_E(x)$$
$$v(x,0)=f(x)-\left[\frac12 f(0)\left(L-x^2\right)\right]$$
Using the Fourier series:
$${A_n} = \frac{2}{L}\int_{{\,0}}^{{\,L}}{{\left( {f\left( x \right) - \left[\frac12 f(0)\left(L-x^2\right)\right]\left( x \right)} \right)\sin \left( {\frac{{n\,\pi x}}{L}} \right)\,dx}}\,\,\,\,\,\,\,\hspace{0.25in}n = 1,2,3, \ldots$$
However, I have a niggling doubt in that $u_E(x)$, where the heat source is of the kind $F(x)$, is the steady state (or Equilibrium) function and it is free of time $t$. That is not the case here.
So is this derivation correct or not?
 A: Here is the approach outlined in the comments.
Solving the homogenous equation is straight forward and gives the solution
$$u_h(x,t) = \sum a_n \sin\left(\frac{n\pi x}{L}\right)e^{-\alpha n^2\pi^2 t/L^2}$$
where $a_n$ is determined by the initial condition $u(x,0)$. Taking $u = u_h + u_p$ we see that $u_p$ satisfy the same PDE with the same boundary conditions but with initial conditions $u_p(x,0) = 0$.
Now how do we find $u_p$? To be able to not mess up the boundary conditions the basis functions for $x$ should remain the same, i.e. we want to find a solution as a series in terms of $\sin\left(\frac{n\pi x}{L}\right)$. Thus we want to find a solution on the form
$$u_p(x,t) = \sum \sin\left(\frac{n\pi x}{L}\right) T_n(t)$$
for some functions $T_n$ to be determined. Inserting it into the PDE we get
$$\sum \sin\left(\frac{n\pi x}{L}\right)\left[T_n'(t) + \alpha\frac{n^2\pi^2}{L^2}T_n(t)\right] = f$$
Thus we see that if we could expand $f$ in a Fourier sin series then we can extract an ODE for $T_n(t)$. To do so lets extend $f$ to be an odd function (such that it has a Fourier sin series), i.e. we take
$f(x,t) = f(t)$ for $x>0$ and $-f(t)$ for $x<0$. In other words we consider the source to be $f(t)H(x)$ where $H$ is the step function. We are only interested in the source for $x>0$ so this is just a trick to be able to write down the Fourier series. This is
$$H(x) = \sum c_n \sin\left(\frac{n\pi x}{L}\right)\sin\left(\frac{n\pi x}{L}\right)$$
where $c_n = \frac{2}{n\pi}(1 - (-1)^n)$. In our equation this becomes
$$\sum \sin\left(\frac{n\pi x}{L}\right)\left[T_n'(t) + \alpha\frac{n^2\pi^2}{L^2}T_n(t) - c_n f(t)\right] = 0$$
which is only possible (the Fourier series is unique) if
$$T_n'(t) + \alpha\frac{n^2\pi^2}{L^2}T_n(t) - c_n f(t) = 0$$
Solve this ODE with initial conditions $T_n(0) = 0$ (recall $u_p(x,0)=0$) and you will find the solution. Adding in the homogenous solution gives you the total solution.
A: So, thanks to @Winther, for the original problem:
$$u_t=\alpha u_{xx}+f(t)$$
$$u(0,t)=u(L,t)=0\text{ and }u(x,0)=f(x)$$
Assume:
$$u(x,t)=v(x,t)+F(t)$$
where:
$$F'(t)=f(t)$$
Thus:
$$u_t=v_t+f(x)$$
$$u_{xx}=v_{xx}$$
$$\Rightarrow v_t=\alpha v_{xx}\tag{1}$$
The originally homogeneous BCs are now time-dependent:
$$u(0,t)=v(0,t)+F(t)\Rightarrow v(0,t)=-F(t)$$
$$u(L,t)=v(L,t)+F(t)\Rightarrow v(L,t)=-F(t)$$

I'll now complete the answer using the method linked to be @Winther.
The homogeneous PDE $(1)$ solves to:
$$u(x,t)=\sum_{n=1}^\infty u_n(t)\sin(\sqrt{\lambda_n}\,x)\quad\text{where}\quad u_n(t)={2\over L}\int_0^L u(x,t)\sin(\sqrt{\lambda_n}\,x)\,dx$$
$$\lambda_n=(n\pi/L)^2\text{ for }n=1,2,3,...$$
$$G(t)=-\lambda_nu_n(t)-\underbrace{{2\sqrt{\lambda_n}\over L}F(t)\left[1+(-1)^{n+1}\right]}_{G(t)}$$
So that:
\begin{align}
{du_n\over dt}+\alpha \lambda_nu_n(t)&=-\alpha G(t),\\
u_n(0)&={2\over L}\int_0^L f(x)\sin(\sqrt{\lambda_n}\,x)\,dx,
\end{align}
