This is the problem:
$u_t=c^2 u_{xx}+g(x,t),0<x<l,\text{ and } t>0$
$u(0,t)=0=u(l,t)$, $t\ge 0$
$u(x,0)=f(x)$
I have trouble passing this problem to homogeneous form
This is the problem:
$u_t=c^2 u_{xx}+g(x,t),0<x<l,\text{ and } t>0$
$u(0,t)=0=u(l,t)$, $t\ge 0$
$u(x,0)=f(x)$
I have trouble passing this problem to homogeneous form
Solve $$ v_t-v_{xx}=0,\quad v(0,t)=v(\ell,t)=0,\quad v(x,0)=f(x) $$ and $$ w_t-w_{xx}=g(x,t),\quad w(0,t)=w(\ell,t)=0,\quad w(x,0)=0. $$ The $u=v+w$. Standard separation of variables gives $v$ in the form $$ v(x,t)=\sum_{n=1}^\infty a_n\,e^{-\bigl(\tfrac{k\,\pi}{\ell}\bigr)^2\,t}\,\sin\frac{k\,\pi\,x}{\ell}. $$ To find $w$ develop $g$ in a Fourier series with coefficients depending on $t$: $$ g(x,t)=\sum_{n=1}^\infty g_n(t)\sin\frac{k\,\pi\,x}{\ell} $$ and look for $w$ of the form $$ w(x,t)=\sum_{n=1}^\infty w_n(t)\sin\frac{k\,\pi\,x}{\ell}. $$ This leads to the first order ordinary linear differential equation for $w_n$
$$ w_n'+\Bigl(\frac{k\,\pi}{\ell}\Bigr)^2\,w_n=g_n,\quad w_n(0)=0. $$
In this generality, you can't reduce this to homogeneous. The solution is obtained in the form of a double integral, as explained here. To understand what's going on, imagine the source as being unit mass added at point $x_0$ at time $t_0$: it will contribute $S(x-x_0,t-t_0)$ to the solution for times $t>t_0$. For finitely many such point sources, we would add up the contributions. For a distributed source, this becomes an integral.
In the special case when $g$ is time-independent, one can first find a stationary solution (solve $0=c^2v_{xx}+g(x)$, which is easy) and then look for $u$ in the form $u=v+w$ where $w$ satisfies the homogeneous PDE.
Let $u(x,t)=\sum\limits_{n=1}^\infty C(n,t)\sin\dfrac{n\pi x}{l}$ so that it automatically satisfies $u(0,t)=u(l,t)=0$ ,
Then $\sum\limits_{n=1}^\infty C_t(n,t)\sin\dfrac{n\pi x}{l}=-\sum\limits_{n=1}^\infty\dfrac{n^2\pi^2}{l^2}C(n,t)\sin\dfrac{n\pi x}{l}+g(x,t)$
$\sum\limits_{n=1}^\infty\biggl(C_t(n,t)+\dfrac{n^2\pi^2}{l^2}C(n,t)\biggr)\sin\dfrac{n\pi x}{l}=g(x,t)$
$\sum\limits_{n=1}^\infty\biggl(C_t(n,t)+\dfrac{n^2\pi^2}{l^2}C(n,t)\biggr)\sin\dfrac{n\pi x}{l}=\sum\limits_{n=1}^\infty\dfrac{2}{l}\int_0^lg(x,t)\sin\dfrac{n\pi x}{l}dx~\sin\dfrac{n\pi x}{l}$
$\therefore C_t(n,t)+\dfrac{n^2\pi^2}{l^2}C(n,t)=\dfrac{2}{l}\int_0^lg(x,t)\sin\dfrac{n\pi x}{l}dx$
$\left(e^\frac{n^2\pi^2t}{l^2}C(n,t)\right)_t=\dfrac{2e^\frac{n^2\pi^2t}{l^2}}{l}\int_0^lg(x,t)\sin\dfrac{n\pi x}{l}dx$
$e^\frac{n^2\pi^2t}{l^2}C(n,t)=\dfrac{2}{l}\int e^\frac{n^2\pi^2t}{l^2}\int_0^lg(x,t)\sin\dfrac{n\pi x}{l}dx~dt$
$e^\frac{n^2\pi^2t}{l^2}C(n,t)=A(n)+\dfrac{2}{l}\int_0^te^\frac{n^2\pi^2t}{l^2}\int_0^lg(x,t)\sin\dfrac{n\pi x}{l}dx~dt$
$C(n,t)=A(n)e^{-\frac{n^2\pi^2t}{l^2}}+\dfrac{2e^{-\frac{n^2\pi^2t}{l^2}}}{l}\int_0^te^\frac{n^2\pi^2t}{l^2}\int_0^lg(x,t)\sin\dfrac{n\pi x}{l}dx~dt$
$\therefore u(x,t)=\sum\limits_{n=1}^\infty\biggl(A(n)e^{-\frac{n^2\pi^2t}{l^2}}+\dfrac{2e^{-\frac{n^2\pi^2t}{l^2}}}{l}\int_0^te^\frac{n^2\pi^2t}{l^2}\int_0^lg(x,t)\sin\dfrac{n\pi x}{l}dx~dt\biggr)\sin\dfrac{n\pi x}{l}$
$u(x,0)=f(x)$ :
$\sum\limits_{n=1}^\infty A(n)\sin\dfrac{n\pi x}{l}=f(x)$
$A(n)=\dfrac{2}{l}\int_0^lf(x)\sin\dfrac{n\pi x}{l}dx$
$\therefore u(x,t)=\sum\limits_{n=1}^\infty\biggl(\dfrac{2e^{-\frac{n^2\pi^2t}{l^2}}}{l}\int_0^lf(x)\sin\dfrac{n\pi x}{l}dx+\dfrac{2e^{-\frac{n^2\pi^2t}{l^2}}}{l}\int_0^te^\frac{n^2\pi^2t}{l^2}\int_0^lg(x,t)\sin\dfrac{n\pi x}{l}dx~dt\biggr)\sin\dfrac{n\pi x}{l}$
$u(x,t)=\dfrac{2}{l}\sum\limits_{n=1}^\infty\biggl(\int_0^lf(x)\sin\dfrac{n\pi x}{l}dx+\int_0^te^\frac{n^2\pi^2t}{l^2}\int_0^lg(x,t)\sin\dfrac{n\pi x}{l}dx~dt\biggr)e^{-\frac{n^2\pi^2t}{l^2}}\sin\dfrac{n\pi x}{l}$