Solve the problem $u_t = c^2 u_{xx} + g(x,t)$, $(x,t) \in (0,L) \times (0,\infty)$ Studying some notes on partial differential equations about the heat equation, I came across the following problem and found it interesting because of its general form:
\begin{equation}
(*)\begin{cases}
u_t = c^2 u_{xx} + g(x,t) \hspace{1.3cm} 0<x<L, \hspace{0.3cm} t>0, \hspace{0.3cm}c>0\\
u(x,0) = f(x) \hspace{2.3cm} 0 \leq x \leq L\\
u(0,t) = 0  \hspace{3.01cm} t \geq 0\\
u(L,t) = 0  \hspace{3cm} t \geq 0
\end{cases}
\end{equation}
I'm trying to solve it, but I have not been able to do it. I tried to do it, first finding a solution of the homogeneous and then proposing a particular solution. However, this method has been too cumbersome because I don't know the $g$ function. As this case did not work for me, then I wanted to analyze a particular case modifying the problem to the following:
\begin{cases}
u_t = c^2 u_{xx} + g(x,t) \hspace{1.3cm} 0<x<L, \hspace{0.3cm} t>0, \hspace{0.3cm}c>0\\
u(x,0) = 0 \hspace{2.9cm} 0 \leq x \leq L\\
u(0,t) = 0  \hspace{3.01cm} t \geq 0\\
u(L,t) = 0  \hspace{3cm} t \geq 0
\end{cases}
supposing that $$g(x,t) = \sum_{n=1}^{\infty}{b_{n}(t)\sin{\frac{n \pi x}{L}}} ,\hspace{0.7cm} (x,t) \in [0,L] \times [0,\infty)$$
of the form $$u(x,t) = \sum_{n=1}^{\infty}{c_{n}\sin{\frac{n \pi x}{L}}}$$
And then look, what happens in the general case described above.
As I have not obtained any results so far, I wanted to post this problem to know its possible solutions. I appreciate any good answers.
 A: You certainly know how to solve the linear homogeneous equation
\begin{cases}
u_t = c^2 u_{xx} \hspace{1.3cm} 0<x<L, \hspace{0.3cm} t>0, \hspace{0.3cm}c>0\\
u(x,0) = f(x) \hspace{2.3cm} 0 \leq x \leq L\\
u(0,t) = 0  \hspace{3.01cm} t \geq 0\\
u(L,t) = 0  \hspace{3cm} t \geq 0
\end{cases}
This other equation :
\begin{cases}
v_t = c^2 v_{xx} + g(x,t) \hspace{1.3cm} 0<x<L, \hspace{0.3cm} t>0, \hspace{0.3cm}c>0\\
v(x,0) = 0 \hspace{2.3cm} 0 \leq x \leq L\\
v(0,t) = 0  \hspace{3.01cm} t \geq 0\\
v(L,t) = 0  \hspace{3cm} t \geq 0
\end{cases}
can be solved using Duhamel formula (write "Duhamel formula heat equation" on google if you need). By linearity, superposition principle gives the solution of your equation : it is simply $u+v$.
A: Making a long story short, inserting your expressions for $g(x,t)$ and $u(x,t)$ in the PDE we obtain the following differential equation for $c_n$:
$$
c_n'=-\frac{n^2\pi^2c^2}{L^2}c_n+b_n(t), \tag{1}
$$
whose solution is
$$
c_n(t)=\alpha_n\exp\left(-\frac{n^2\pi^2c^2}{L^2}t\right)+
\int_0^{t}\exp\left[-\frac{n^2\pi^2c^2}{L^2}(t-t')\right]b_n(t')\,dt'. \tag{2}
$$
The coefficients $\alpha_n$ are determined by the initial condition
$$
u(x,0)=\sum_{n=1}^{\infty}{c_{n}(0)\sin{\frac{n \pi x}{L}}}=
\sum_{n=1}^{\infty}{\alpha_n\sin{\frac{n \pi x}{L}}}=f(x), \tag{3}
$$
and are given by
$$
\alpha_n=\frac{2}{L}\int_0^L f(x)\sin{\frac{n \pi x}{L}}\,dx. \tag{4}
$$
