Semi-infinite heat/diffusion equation with time-dependent B.C. at x=0 I have a problem in which I need to solve the diffusion equation:
$$
\frac{\partial u}{\partial t}=\frac{\partial^2 u}{\partial x^2}
$$
on a semi-infinite domain from $x=0$ to $x=\infty$. The initial condition and boundary conditions are:
$$
u(x,t=0)=0\\
u(x=0,t)=g(t)\\
u(x=\infty,t)=0
$$
Specifically, I need an expression for:
$$
\left.\frac{\partial u}{\partial x}\right|_{x=0}(t)
$$
Is this possible?
The general solution for this problem (from Wikipedia):
$$
u(x,t) =1+ \int_0^t\left( \frac{x}{\sqrt{4\pi (t - t^\prime)^3}}\exp\left[-\frac{x^2}{4(t-t^\prime)}\right]g(t^\prime)\right)\textrm{d}t^\prime\:\: \forall x>0
$$
is invalid in $x=0$. 
Is this intrinsic to this problem, since $g(t)$ can be any (discontinuous) solution? In my case, $g(t)$ is continuous and smooth, is there a way to express $\left.\frac{\partial u}{\partial x}\right|_{x=0}(t)$ assuming $f(x)$, $g(t)$ are known?
 A: So the problem is, given 
$$\frac{\partial u}{\partial t} = \frac{\partial^2 u}{\partial x^2}$$
$$u(x,0)=0$$
$$u(0,t) = g(t)$$
$$\lim_{x \to \infty} u(x,t) = 0$$
for $x \gt 0$, find 
$$\left [ \frac{\partial u}{\partial x}\right]_{x=0}$$
which is the temperature gradient at the end of the bar (related to heat flow). 
To find this, I will take a Laplace transform approach.  That is, define
$$\hat{u}(x,s) = \int_0^{\infty} dt \, u(x,t) \, e^{-s t}$$
Note that 
$$\int_0^{\infty} dt \, \frac{\partial u}{\partial t} \, e^{-s t} = \left [ u(x,t) e^{-s t}\right ]_0^{\infty} + s \int_0^{\infty} dt \, u(x,t) \, e^{-s t} = s \, \hat{u}(x,s)$$
because of the initial condition.  Therefore our equation becomes
$$\frac{\partial^2 \hat{u}}{\partial x^2} - s \hat{u} = 0$$
$$\hat{u}(0,s) = \int_0^{\infty} dt \, g(t) \, e^{-s t} = \hat{g}(s)$$
$$\lim_{x \to \infty} \hat{u}(x,s) = 0$$
The solution to this equation is simply
$$\hat{u}(x,s) = \hat{g}(s) e^{-x \sqrt{s}}$$
from which we may take the inverse Laplace transform to find that
$$u(x,t) = \frac{1}{i 2 \pi} \int_{c-i \infty}^{c+i \infty} ds \, \hat{g}(s) \, e^{-\sqrt{s} x} \, e^{s t}$$
and therefore
$$\left [ \frac{\partial u}{\partial x}\right]_{x=0} = -\frac{1}{i 2 \pi} \int_{c-i \infty}^{c+i \infty} ds \, \sqrt{s}\, \hat{g}(s)\, e^{s t}$$
Now we will need to end the story there, as the convolution theorem does not apply (the ILT of $\sqrt{s}$ is ill-defined).  Rather, we will need to evaluate the ILT above to get the correct gradient.  As an example, consider the case in which the bar at $x=0$ is held at a fixed value $u_0$.  Then $\hat{g}(s) = u_0/s$ and we have
$$\left [ \frac{\partial u}{\partial x}\right]_{x=0} = -\frac{u_0}{i 2 \pi} \int_{c-i \infty}^{c+i \infty} ds \, s^{-1/2}\, e^{s t}$$
This integral may be attacked with the residue theorem, but not the usual way for these inverse Laplace transforms.  Basically, the Bromwich contour needs to not include the branch point at the origin.  The result is then a keyhole contour that goes up and back around the negative real axis and encircles the origin from $\arg{s}=\pi$ to $\arg{s}=-\pi$.  
Consider
$$\oint_C ds \frac{e^{s t}}{\sqrt{s}}$$
where $C$ is the above-described contour.  By the residue theorem (or Cauchy's integral theorem), this integral is zero because there are no poles within $C$.  $C$, however, has $5$ pieces: the original integral along $\Re{s}=a$, a circular arc of large radius $R$, a section that goes in a positive direction just above the negative real axis, a circular arc of small radius $r$ around the origin, and another section just below the negative real axis in a negative direction.  In the limit as $R \rightarrow \infty$ and $ r \rightarrow 0$, the integrals along the circular arcs vanish.  This leaves
$$ \int_{c-i\infty}^{c+i\infty} ds \frac{e^{s t}}{\sqrt{s}}+e^{i \pi} \int_{\infty}^0 dx \frac{e^{-x t}}{i \sqrt{x}} + \int_0^{\infty} dx \frac{e^{-x t}}{-i \sqrt{x}}=0$$
A little rearranging produces
$$ \frac{1}{i 2 \pi} \int_{c-i\infty}^{c+i\infty} ds \frac{e^{s t}}{\sqrt{s}} = \frac{1}{ \pi}  \int_0^{\infty} dx \frac{e^{-x t}}{\sqrt{x}}$$
Substitute $y=\sqrt{x}$ into the integral on the RHS and finally get
$$ \frac{1}{i 2 \pi} \int_{c-i\infty}^{c+i\infty} ds \frac{e^{s t}}{\sqrt{s}} =  \frac{2}{ \pi}  \int_0^{\infty} dy \; e^{-t y^2}=\frac{1}{\sqrt{\pi t}}$$
and therefore the gradient is
$$\left [ \frac{\partial u}{\partial x}\right]_{x=0} = -\frac{u_0}{\sqrt{\pi}} t^{-1/2}$$
ADDENDUM
We can, in fact, apply the convolution theorem to $u(x,t)$ directly.  To do that, we need to find the ILT of $e^{-b \sqrt{s}}$, where we will eventually see that $b \gt 0$ is our $x$ above.  (I will need $x$ below for another purpose, please forgive the notational shuffle.)  I will state the final result up front:
$$u(x,t) = \frac{x}{2 \sqrt{\pi}} \int_0^t dt' \, g(t') (t-t')^{-3/2} \, e^{-x^2/(4 (t-t'))}$$
which implies that
$$\left [ \frac{\partial u}{\partial x}\right]_{x=0} = \frac{1}{2 \sqrt{\pi}} \int_0^t dt' \, g(t') (t-t')^{-3/2}$$
(which, ironically, is what you get when you formally apply the convolution theorem to the above expression for the gradient).
You can use a contour integration without that substitution as follows by deforming the Bromwich contour about the negative real axis and exploiting a branch cut of $\sqrt{z}$ about that axis.  So, consider the integral
$$\oint_C dz \: e^{-b \sqrt{z}} e^{z t}$$
where $C$ is a keyhole contour about the negative real axis, as pictured below.

We will define $\text{Arg}{z} \in (-\pi,\pi]$, so the branch is the negative real axis.  There are $6$ pieces to this contour, $C_k$, $k \in \{1,2,3,4,5,6\}$, as follows.
$C_1$ is the contour along the line $z \in [c-i R,c+i R]$ for some large value of $R$.
$C_2$ is the contour along a circular arc of radius $R$ from the top of $C_1$ to just above the negative real axis.
$C_3$ is the contour along a line just above the negative real axis between $[-R, -\epsilon]$ for some small $\epsilon$.
$C_4$ is the contour along a circular arc of radius $\epsilon$ about the origin.
$C_5$ is the contour along a line just below the negative real axis between $[-\epsilon,-R]$.
$C_6$ is the contour along the circular arc of radius $R$ from just below the negative real axis to the bottom of $C_1$.
We will show that the integral along $C_2$,$C_4$, and $C_6$ vanish in the limits of $R \rightarrow \infty$ and $\epsilon \rightarrow 0$.
On $C_2$, the real part of the argument of the exponential is
$$R t \cos{\theta} - b \sqrt{R} \cos{\frac{\theta}{2}}$$
where $\theta \in [\pi/2,\pi)$.  Clearly, $\cos{\theta} < 0$ and $\cos{\frac{\theta}{2}} > 0$, so that the integrand exponentially decays as $R \rightarrow \infty$ and therefore the integral vanishes along $C_2$.
On $C_6$, we have the same thing, but now $\theta \in (-\pi,-\pi/2]$.  This means that, due to the evenness of cosine, the integrand exponentially decays again as $R \rightarrow \infty$ and therefore the integral also vanishes along $C_6$.
On $C_4$, the integral vanishes as $\epsilon$ in the limit $\epsilon \rightarrow 0$.  Thus, we are left with the following by Cauchy's integral theorem (i.e., no poles inside $C$):
$$\left [ \int_{C_1} + \int_{C_3} + \int_{C_5}\right] dz \: e^{-b \sqrt{z}} e^{z t} = 0$$
On $C_3$, we parametrize by $z=e^{i \pi} x$ and the integral along $C_3$ becomes
$$\int_{C_3} dz \: e^{-b \sqrt{z}} e^{z t} = e^{i \pi} \int_{\infty}^0 dx \: e^{-i b \sqrt{x}} e^{-x t}$$
On $C_5$, however, we parametrize by $z=e^{-i \pi} x$ and the integral along $C_5$ becomes
$$\int_{C_5} dz \: e^{-b \sqrt{z}} e^{z t} = e^{-i \pi} \int_0^{\infty} dx \: e^{i b \sqrt{x}} e^{-x t}$$
We may now write
$$-\frac{1}{i 2 \pi} \int_0^{\infty} dx \: e^{- x t} \left ( e^{i b \sqrt{x}} - e^{-i b \sqrt{x}} \right ) + \frac{1}{i 2 \pi} \int_{c-i \infty}^{c+i \infty} ds \: e^{-b \sqrt{s}} e^{s t} = 0$$
Therefore, the ILT of $\hat{f}(s) = e^{-b \sqrt{s}}$ is given by
$$\begin{align}\frac{1}{i 2 \pi} \int_{c-i \infty}^{c+i \infty} ds \: e^{-b \sqrt{s}} e^{s t} &= \frac{1}{i 2 \pi} \int_0^{\infty} dx \: e^{- x t} \left ( e^{i b \sqrt{x}} - e^{-i b \sqrt{x}} \right )\\ &= \frac{1}{\pi} \int_{-\infty}^{\infty} du\: u \,e^{-t u^2} \sin{b u}\end{align}$$
The last step involved substituting $x=u^2$ and exploiting the evenness of the integrand.  This integral may be evaluated as follows:
$$\begin{align}\frac{1}{\pi} \int_{-\infty}^{\infty} du\: u \,e^{-t u^2} \sin{b u} &= \frac{1}{\pi} \Im{\left [\int_{-\infty}^{\infty} du\:u\, e^{-t u^2} e^{i b u} \right]}\\ &= \frac{1}{\pi} \Im{\left [\int_{-\infty}^{\infty} du\:u\, e^{-t (u-i b/(2 t))^2} e^{-b^2/(4 t)}\right ]}\\ &= \frac{1}{\pi} e^{-b^2/(4 t)} \Im{\left [\int_{-\infty}^{\infty} dv \: \left ( v + \frac{i b}{2 t} \right ) e^{-t v^2} \right]}\\ &= \frac{1}{\pi} e^{-b^2/(4 t)}  \frac{b}{2 t} \sqrt{\frac{\pi}{t}} \end{align}$$
Therefore (putting back $b=x$) the result is that
$$\mathcal{L}^{-1}[e^{-x \sqrt{s}}](t) = \frac{1}{i 2 \pi} \int_{c-i \infty}^{c+i \infty} ds \: e^{-\sqrt{s}} e^{s t} = \frac{x}{2 \sqrt{\pi}} t^{-3/2} e^{-\frac{x^2}{4 t}}$$
A: I just bumped into this problem and after ~6 years of the OP's question I think it is still worth adding one thing to Ron Gordon's (otherwise correct) solution, the Heaviside function in the ILT.
So the solution is obtained by Laplace transform as
$$
u(x,t)=\int_{c-i\infty}^{c+i\infty}\frac{ds}{2\pi i}\hat{g}(s)e^{-\sqrt{s}x}e^{st},
\qquad (x\ge0,\,t\ge0),
$$
where $c>0$ guarantees that the Bromwich contour runs in the $\Re(s)>0$ half-space where the integrand is holomorphic. Substituting the definition of $\hat{g}(s)$ and changing the order of integrations yields
$$
\begin{align}
u(x,t)&=\int_0^\infty dt'g(t')
\int_{c-i\infty}^{c+i\infty}\frac{ds}{2\pi i}e^{-\sqrt{s}x}e^{s(t-t')}\\
&=\int_0^\infty dt'g(t')\mathcal{L}^{-1}[e^{-\sqrt{s}x}](t-t').
\end{align}
$$
This is a convolution. The task is now reduced to compute the inverse Laplace transform of $e^{-\sqrt{s}x}$ at $t-t'$. The computation is slightly different depending on the sign of $t-t'$ but in general it is about extending/moving the contour of integration and use Cauchy's theorem.


*

*For $t-t'>0$ the convenient choice is to fold the Bromwich contour onto the negative real axis, see Ron's solution. Because the real part of the exponent
$$
R(t-t')\cos\theta-x\sqrt{R}\cos\frac{\theta}{2}
$$
is negative for all $\theta$ on $C_2$ and $C_6$ the arcs give zero contribution.

*For $t-t'<0$ the very same exponent will be negative for all $\theta$ if the $C_2$ and $C_6$ arcs are on the right half-plane. Thus, extending the Bromwich contour to a large half-circle on the right half-plane, using the Cauchy theorem and the fact that the integrand is analytic there, the whole integral becomes zero.
Putting the two cases together we finally have
$$
\mathcal{L}^{-1}[e^{-\sqrt{s}x}](t-t')=\Theta(t-t')\frac{x}{2\sqrt{\pi}}
(t-t')^{-3/2}e^{-\frac{x^2}{4(t-t')}}.
$$
This is exactly what Ron found, but this time the Heaviside function explicitly included. With this the convolution is
$$
\begin{align}
u(x,t)&=\frac{x}{2\sqrt{\pi}}\int_0^t dt'g(t')(t-t')^{-3/2}e^{-\frac{x^2}{4(t-t')}}\\
&=\frac{x}{2\sqrt{\pi}}\int_0^t dt' g(t-t')t'^{-3/2}e^{-\frac{x^2}{4t'}}
\qquad (x\ge0,\,t\ge0).
\end{align}
$$
