inhomogeneous heat equation with mixed boundary conditons Solve $$U_{t}=U_{xx}+u$$ with mixed boundary conditions $$U_x(0,t)=0, U(l,t)=0$$
and initial condition $$U(x,0)=\varphi(x)$$
I know that I have to use separation of variables and I have an idea of how to do it when its either just Dirichlet or just Neumann but both together and with a source I have no idea any help would be appreciated.
 A: $\newcommand{\angles}[1]{\left\langle\,{#1}\,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\Li}[1]{\,\mathrm{Li}_{#1}}
 \newcommand{\mrm}[1]{\,\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

$\ds{\partiald{\mrm{U}\pars{x,t}}{t} =
     \partiald[2]{\mrm{U}\pars{x,t}}{x} + \mrm{u}\pars{x,t}\,,\qquad
\left\lbrace\begin{array}{rcccl}
\ds{\left.\partiald{\mrm{U}\pars{x,t}}{x}\,\right\vert_{\ x\ =\ 0}} & \ds{=} &
\ds{\mrm{U}\pars{L,t}} & \ds{=} &  \ds{0}
\\[3mm]
\ds{\mrm{U}\pars{x,0}} & \ds{=} & \ds{\varphi\pars{x}}&&
\end{array}\right.}$.


First, we look for a lineal combination $\ds{A\sin\pars{kx} + B\cos\pars{kx}}$ which satisfies the homogeneous boundary conditions at
$\ds{x = 0\ \mbox{and}\ x = L}$.

$\ds{\left.\vphantom{\large A}0 = k\bracks{A\cos\pars{kx} - B\sin{kx}}
\right\vert_{\ x\ =\ 0}\,\,\, =\,\,\, kA}$ is satisfied with $\ds{k = 0}$ or $\ds{A = 0}$. $\ds{k = 0}$ just adds a constant term which vanishes out because $\ds{\mrm{U}\pars{L,t} = 0}$.
$\ds{B\cos\pars{kL} = 0}$ is satisfied whenever
$\ds{k \in W \equiv \braces{\pars{n + \half}\,{\pi \over L}\,,\ n = 0,1,2,\ldots}}$ 

Now, we are ready to write the general solution as
$\ds{\mrm{U}\pars{x,t} =
\sum_{k}A_{k}\pars{t}\cos\pars{kx}}$ where $\ds{k \in W}$. It satisfies:
\begin{equation}
\sum_{k}\totald{A_{k}\pars{t}}{t}\,\cos\pars{kx} =
-\sum_{k}A_{k}\pars{t}k^{2}\cos\pars{kx} + \mrm{u}\pars{x,t}
\end{equation}
Multiply both sides by $\ds{\cos\pars{qx}}$, where $\ds{q \in W}$, and integrate over $\ds{\pars{0,L}}$:
\begin{equation}
\totald{A_{q}\pars{t}}{t} =
-q^{2}A_{q}\pars{t} + \hat{\mrm{u}}_{q}\pars{t}\,,\qquad
\hat{\mrm{u}}_{q}\pars{t} \equiv
{2 \over L}\int_{0}^{L}\mrm{u}\pars{x,t}\cos\pars{qx}\,\dd x\tag{1}
\end{equation}
Also,
\begin{equation}
\varphi\pars{x} = \mrm{U}\pars{x,0} =
\sum_{k}A_{k}\pars{0}\cos\pars{kx}\quad\imp\quad
A_{k}\pars{0} =
{2 \over L}\int_{0}^{L}\varphi\pars{x}\cos\pars{kx}\,\dd x
\tag{2}
\end{equation}

Eqtn. $\ds{\pars{1}}$ is easily solved:
\begin{align}
\totald{\bracks{\exp\pars{q^{2}\, t}A_{q}\pars{t}}}{t} & =
\exp\pars{q^{2}\, t}\hat{\mrm{u}}_{q}\pars{t}\,,\qquad
\pars{~A_{k}\pars{0}\ \mbox{is given by}\ \pars{2}~}
\\[5mm] \imp
A_{q}\pars{t} & =
A_{q}\pars{0}\exp\pars{-q^{2}\, t} +
\int_{0}^{t}\exp\pars{-q^{2}
\pars{t - \tau}}\hat{\mrm{u}}_{q}\pars{\tau}\,\dd\tau
\\
& \hat{\mrm{u}}_{q}\pars{\tau}\ \mbox{is given in}\ \pars{1}.
\end{align}

The $\ds{\underline{final\ solution}}$ which satisfies the conditions at the top is given by:
\begin{align}
\color{#66f}{\mrm{U}\pars{x,t}} & =
\color{#66f}{\sum_{q}\bracks{A_{q}\pars{0}\exp\pars{-q^{2}\, t} +
\int_{0}^{t}\exp\pars{-q^{2}
\pars{t - \tau}}\hat{\mrm{u}}_{q}\pars{\tau}\,\dd\tau}\cos\pars{qx}}\,,\quad
q \in W
\\[5mm]
A_{q}\pars{0} & = {2 \over L}\int_{0}^{L}\varphi\pars{x}\cos\pars{qx}\,\dd x
\,,\qquad
\hat{\mrm{u}}_{q}\pars{t} \equiv
{2 \over L}\int_{0}^{L}\mrm{u}\pars{x,t}\cos\pars{qx}\,\dd x\,,\quad
q \in W
\end{align}
