How to solve heat equation Solve the Heat-Eqn.
$$u_t=ku_{xx}$$ where $x,t>0$ and
$u_x(0,t) =0$ and $u(x,0)=\begin{cases} 
      1, & 0 < x <2 \\
      0, &  2\leq x  
   \end{cases}
$
What are the solution methods?


*

*Separation of variables?

*Fourier Transform?
I can' t solve it by the separation of variables since $u_x(L,t)$ is ungiven and since $u(x,0)$ is a piecewise function. 
Or can we solve by the Fourier Transform? It is a difficult question for me. Please help me.
My attempt:
Using separation of variables, we have
$X''(x)-\lambda X(x)=0$ and $T'(t)-\lambda T(t)=0$. 
If we select $\lambda=-\mu^2$, we get
$X(x)=Acos\mu x+B sin \mu x$ and $T(t)=C e^{-kt(\dfrac{n \pi}{L})^2}$
 A: For $0<x<2$ , the PDE has conditions $u_x(0,t)=0$ and $u(x,0)=1$ only.
Let $u(x,t)=X(x)T(t)$ ,
Then $X(x)T'(t)=kX''(x)T(t)$
$\dfrac{T'(t)}{kT(t)}=\dfrac{X''(x)}{X(x)}=-s^2$
$\begin{cases}\dfrac{T'(t)}{kT(t)}=-s^2\\X''(x)+s^2X(x)=0\end{cases}$
$\begin{cases}T(t)=c_3(s)e^{-kts^2}\\X(x)=\begin{cases}c_1(s)\sin xs+c_2(s)\cos xs&\text{when}~s\neq0\\c_1x+c_2&\text{when}~s=0\end{cases}\end{cases}$
$\therefore u(x,t)=\int_0^\infty C_1(s)e^{-kts^2}\sin xs~ds+\int_0^\infty C_2(s)e^{-kts^2}\cos xs~ds$
$u_x(x,t)=\int_0^\infty sC_1(s)e^{-kts^2}\cos xs~ds-\int_0^\infty sC_2(s)e^{-kts^2}\sin xs~ds$
$u_x(0,t)=0$ :
$\int_0^\infty sC_1(s)e^{-kts^2}~ds=0$
$C_1(s)=0$
$\therefore u(x,t)=\int_0^\infty C_2(s)e^{-kts^2}\cos xs~ds$
$u(x,0)=1$ :
$\int_0^\infty C_2(s)\cos xs~ds=1$
$C_2(s)=\delta(s)$
$\therefore u(x,t)=\int_0^\infty\delta(s)e^{-kts^2}\cos xs~ds=1$
$u(2,t)=1$
Now for $x\geq2$ , the PDE has conditions $u(2,t)=1$ and $u(x,0)=0$ only.
Similarly, $u(x,t)=\int_0^\infty C_3(s)e^{-kts^2}\sin((x-2)s)~ds+\int_0^\infty C_4(s)e^{-kts^2}\cos((x-2)s)~ds$
$u(2,t)=1$ :
$\int_0^\infty C_4(s)e^{-kts^2}~ds=1$
$C_4(s)=\delta(s)$
$\therefore u(x,t)=\int_0^\infty C_3(s)e^{-kts^2}\sin((x-2)s)~ds+\int_0^\infty \delta(s)e^{-kts^2}\cos((x-2)s)~ds=1+\int_0^\infty C_3(s)e^{-kts^2}\sin((x-2)s)~ds$
$u(x,0)=0$ :
$\int_0^\infty C_3(s)\sin((x-2)s)~ds=-1$
$\mathcal{F}_{s,s\to x-2}\{C_3(s)\}=-1$
$C_3(s)=\mathcal{F}^{-1}_{s,x-2\to s}\{-1\}=-\dfrac{2}{\pi s}$
$\therefore u(x,t)=1-\dfrac{2}{\pi}\int_0^\infty\dfrac{e^{-kts^2}\sin((x-2)s)}{s}~ds=\text{erfc}\left(\dfrac{x-2}{2\sqrt{kt}}\right)$
