I'm just playing around with separation of variables for a simple 1D diffusion equation for $c(x,t)$, of the form $c_{t} = Dc_{xx}$ where $D$ is a diffusion constant. At some initial time, concentration of a drug is$f(x) = 10e^{-kx}$. Now, if the 1D line is of length $L$, then my understanding is to confine the drug to that length, I should use Neumann boundary conditions so that $c_{x}(0,t) = c_{x}(L,t) = 0 $ to denote there is no flow through the boundaries.
Using a separation of variables on this, I get a general solution of the form
$$c = A_{n} e^{-\frac{Dn^2\pi^2 t}{L^2}}\cos\left(\frac{n\pi x}{L}\right)$$.
If I remember correctly, I can use a fourier sine series to express $A_{n}$ from the initial condition, and I then get
$$A_{n} = \frac{2}{L}\int_{0}^L \sin{\frac{n\pi x}{L}}10e^{-kx} = \frac{20n\pi(1 + e^{-kL})}{k^2l^2 + n^2 \pi^2 }$$
So my specific solution should be (If I've done everything right)
$$c(x,t) = \sum_{n=1}^{\infty} \frac{20n\pi(1 + e^{-kL})}{k^2l^2 + n^2 \pi^2}e^{-\frac{Dn^2\pi^2 t}{L^2}}\cos\left(\frac{n\pi x}{L}\right) $$
I'm currently trying to plot this, and getting some strange results. My physical interpretation is that initially where is high concentration at $x=0$ which diffuses along the length, eventually reaching some equilibrium concentration; I could have thought the no-flux boundary conditions mean that net amount is trapped in the length of the tube? Is this correct?
If this is correct, is my use of sine series to find $A_{n}$ appropriate? It's been a long time since I've seen it and my logic on how this step is justified is kind of hazy, so would be grateful if anyone could set me right..
The solution will be $$ c = A_0+\sum_{n=1}^\infty A_{n} e^{-\tfrac{Dn^2\pi^2 t}{L^2}}\cos\frac{n\pi x}{L}. $$ At $t=0$ you want $$ f(x)=10\,e^{-kx}=A_0+\sum_{n=1}^\infty A_{n} \cos\frac{n\pi x}{L},\quad 0\le x\le L. $$ The coefficients are given by $$\begin{align} A_0&=\frac1L\int_0^Lf(x)\,dx\\ A_n&=\frac{2}{L}\int_{0}^L f(x)\,\cos\frac{n\pi x}{L}\,dx,\quad n>0. \end{align}$$ Observe that we use $\cos$ and not $\sin$.