Impose Neumann Boundary Condition in advection-diffusion equation 1D
when solving the advection equation in 1D that is:
$$ \frac{\partial u}{\partial t} + c\frac{\partial u}{\partial x} = 0 $$ with $ u'(t,0) = 0$ and $u(t,L) = 0$ , $u(0,x) = u_{0} $
one numerical scheme is the FTCS (Forward time-centered space), but this numerical scheme is unstable.
$$\frac{u_{j}^{n+1}-u_{j}^{n}}{ h_{t}} = c \frac{u_{j+1}^{n}-u_{j-1}^{n}}{ 2h_{x}} $$
But when solving
$$ \frac{\partial u}{\partial t} + c\frac{\partial u}{\partial x} = \alpha \frac{\partial^2 u}{\partial x^2} $$ the advection-diffusion equation in 1D with $ u'(t,0) = 0$ and $u(t,L) = 0$ , $u(0,x) = u_{0} $
Since the advection-diffusion equation is a second order equation I'd like to use a second order approximation.
if we define $u_{k}^{n} := u(t_{n},x_{k}) $; $\ \ x_{k} = kh $ and $ \ \ k = 0,1,2,...,N$. $h$ is known as the mesh size or step size.
For the second derivative:
$$ \frac{\partial^2u_{k}^{n}}{\partial x^2} \approx \frac{u_{k+1}^{n}-2u_{k}^{n}+u_{k-1}^{n}}{h^2} = \frac{u_{k-1}^{n}-2u_{k}^{n}+u_{k+1}^{n}}{h^2} $$ for $k=0,1,...,N-1$
Since $u'(t,0) = 0$ and $ u(t_{n},L) = u(t_{n},x_{N}) = u_{N}^{n} = 0 $ we get the following matrix representation of the second derivative operator
\begin{equation} \frac{\partial^2}{\partial x^2} \approx L_{2} = \frac{1}{h^2}\left(\begin{matrix} -2 & 1 & & 0\ 1 & \ddots & \ddots & \ & \ddots & \ddots & 1 \ 0 & & 1 & -2 \end{matrix} \right) \end{equation}
for $k=0$ , we get
$$ \frac{\partial u_{0}^{n}}{\partial x} = \frac{u_{0+1}^{n}-u_{0-1}^{n}}{ 2h} = 0 $$ this implies that $ u_{1}^{n}=u_{-1}^{n} $ and
$$ \frac{\partial^2u_{0}^{n}}{\partial x^2} \approx \frac{u_{0+1}^{n}-2u_{0}^{n}+u_{0-1}^{n}}{h^2} = \frac{u_{0-1}^{n}-2u_{0}^{n}+u_{0+1}^{n}}{h^2} = \frac{-2u_{0}^{n}+2u_{1}^{n}}{h^2} $$
thus we have to modify the entry $1,2$ of $L_{2}$
\begin{equation} L_{2} = \frac{1}{h^2}\left(\begin{matrix} -2 & 2 & & 0\ 1 & \ddots & \ddots & \ & \ddots & \ddots & 1 \ 0 & & 1 & -2 \end{matrix} \right) \end{equation}
What I have done, is $\mathbf{impose \ the \ Neumann \ boundary \ condition}$ in $L_{2}$ . 935