Diffusion equation in a semi-finite closed tube A semi finite closed tube contains a liquid. I am not sure what semifinite in this context means, but this is what the exercise says.  In this tube, there is a color substance with concentration u(x,t) at time $t>0, x\geq0$. At time $t=0$ the concentration is:
\begin{equation}
u(x,0)=
\begin{cases}
2 \ \ \ \ 0\leq x \leq 1,\\
0 \ \ \ \ x>1
\end{cases}
\end{equation}
The total amount of color substance in the tube does not change with time. Determine the boundary conditions in the closed en of the tube, and solve the one-dimensional diffusion equation where the diffusion constant is D=1/4. The error function can be part of the answer.
My attempt:
I consider the diffusion problem of the color substance as spreading across the length of the tube, L at the given rate:
\begin{equation}
u_{xx}=\frac{1}{4}u_t
\end{equation}
The solutions by separation  of variables are identified as:
\begin{equation}
\begin{array}
Fu_{xx}=\frac{1}{4}u_t\rightarrow u(x,t)=X(x)T(t)\\
4X_{xx}T=T_tX\\
4\frac{X_{xx}}{X}=\frac{T_t}{T}=k^2 \\
4\frac{X_{xx}}{X}=k^2 , \frac{T_t}{T}=k^2 \\
\frac{T_t}{T}=k^2 \rightarrow T_{t}-k^2T=0 \rightarrow \frac{dT}{dt}=k^2T\rightarrow \frac{dT}{T}=k^2dt\rightarrow T(t)=Ce^{k^2t}
\end{array}
\end{equation}
For the spatial function, we have three cases of interest:
\begin{equation}
\begin{array}
xX_{xx}=0 \ \ \ (k=0) \\
X_{xx}-\frac{1}{4}k^2X=0 \ \ \ (k<0)\\
X_{xx}+\frac{1}{4}k^2X \ \ \ \ (k>0)
\end{array}
\end{equation}
We solve each case:
k=0
\begin{equation}
\begin{array}
xX_{xx}=0 \ \ \ (k=0) \\
X(x)=Ax+B \ \ \  I.C.: u(x,0)= 2, u(x,0)=0 \rightarrow \\
0=Ax+B \rightarrow A,B=0
\end{array}
\end{equation}
k>0
\begin{equation}
\begin{array}
xX_{xx}+\frac{1}{4}k^2X=0 \ \ \ \\
X(x)=e^{-\frac{1}{16}ikx}+e^{\frac{1}{16}ikx}\\
X(x)=A\sin(\frac{1}{16}kx)+B\cos(\frac{1}{16}kx) 
\end{array}
\end{equation}
This solution  gives an exponential growth of the color agent as time goes to infinity, however the total amount of tube does not change over time, so $k>0$ is not an allowed solution.
Solving for k<0
\begin{equation}
\begin{array}
xX_{xx}-\frac{1}{4}k^2X=0 \ \ \ \\
X(x)=e^{\frac{1}{16}kx}+e^{\frac{1}{16}kx}\\
X(x)=A\cosh(\frac{1}{16}kx) \ \ \ 
\end{array}
\end{equation}
With $u(x,0)=0$,
$u(L,0)=A(e^{\frac{1}{16}kx}+e^{\frac{1}{16}kx})e^{-k^2t}\rightarrow A\cosh(\frac{1}{16}kx)=0 \rightarrow \cosh(\frac{1}{16}kx)=i\bigg(n\pi-\frac{\pi}{2}\bigg) \rightarrow (\frac{1}{16}kL)=i\bigg(n\pi-\frac{\pi}{2}\bigg) \rightarrow k= \frac{16i(n\pi-\frac{\pi}{2})}{L}$
Set   $\alpha=\frac{16i(n\pi-\frac{\pi}{2})}{L} $
Finding A:
\begin{equation}
\int_0^L (e^{\frac{1}{16}\alpha x}+e^{\frac{1}{16}\alpha x})\cos(\alpha x)=?
\end{equation}
But I was tought that we should find a Fourier coefficient in this regard, but how?
Thanks
 A: I suspect that your 4 is in the wrong place. The equation is probably
$$
             u_t = \frac{1}{4}u_{xx}.
$$
The idea of the diffusion equation is that $u$ is a mass density so that mass in $a \le x \le b$ is given by
$$
         \mbox{TotalMass}(a \le x \le b)=     \int_{a}^{b}u(x,t)dx.
$$
The change in total mass for $a \le x \le x$ due to diffusion is
\begin{align}
        \frac{d}{dt}\int_a^b u(x,t)dx &= \int_a^b u_{t}(x,t)dx \\&= \frac{1}{4}\int_a^b u_{xx}(x,t)dx \\&=\frac{1}{4}\left(u_{x}(b,t)-u_{x}(a,t)\right).
\end{align}
So the rate of change of mass in $a \le x \le b$ is controlled by the spatial derivative of the mass distribution, which makes sense: the higher the local spatial mass imbalance, the faster the transfer of mass. The exact rate of mass exchange is then proportional to this spatial derivative of the mass distribution and a constant of mass conductance.
Spatially you are working in $0 \le x < \infty$. After separating variables $u(x,t)=X(x)T(t)$, you have
$$
             \frac{T'}{T}=\frac{1}{4}\frac{X''}{X}.
$$
The left side depends only on $t$, while the right side depends only on $x$. So there must be a separation constant $\lambda$ such that
$$
       \frac{T'}{T}=-\lambda,\;\; -\lambda=\frac{1}{4}\frac{X''}{X}.
$$
I prefer to move the $4$ to the time side, just for convenience:
$$
                4\frac{T'}{T}=-\lambda,\;\; -\lambda=\frac{X''}{X}
$$
I chose the negative sign in order to keep $\lambda \ge 0$ in general. The separated solutions are
$$
              T(t)=Ce^{-\lambda t/4},\;\; X(x)=A\cos(\sqrt{\lambda}x)+B\sin(\sqrt{\lambda}x)
$$
Because this is posed on an infinite interval $[0,\infty)$, there are no discrete modes of the system. The spatial distribution must be written in terms of Fourier cosine and/or sin transforms on $[0,\infty)$. You want the derivative in $x$ at $x=0$ to be $0$ in order to keep mass contained within $[0,\infty)$. So the constant $B$ must be $0$. The final, general solution, is a Fourier integral on $[0,\infty)$:
$$
    u(x,t)= \int_{0}^{\infty}A(\lambda)\cos(\lambda x)e^{-\lambda^2 t/4}d\lambda
$$
The coefficient function $A(\lambda)$ is determined by a Fourier cos transform of the initial mass distribution:
$$
        u(x,0)=\int_{0}^{\infty}A(\lambda)\cos(\lambda x)d\lambda \\
     \implies A(\lambda)=\frac{2}{\pi}\int_{0}^{\infty}u(x,0)\cos(\lambda x)dx.
$$
Therefore, your solution is
\begin{align}
    u(x,t)&=\int_0^{\infty}\left(\frac{2}{\pi}\int_0^{\infty}u(x',0)\cos(\lambda x')dx'\right)\cos(\lambda x)e^{-\lambda^2 t/4}d\lambda \\
    &=\int_0^{\infty}\left(\frac{2}{\pi}\int_0^12\cos(\lambda x')dx'\right)\cos(\lambda x)e^{-\lambda^2 t/4}d\lambda \\
    &=\frac{4}{\pi}\int_0^{\infty}\frac{\sin{\lambda}}{\lambda}\cos(\lambda x)e^{-\lambda^2 t/4}d\lambda
\end{align}
