$$ \frac {\partial C}{\partial t} = D \frac {\partial^2 C}{\partial x^2} - w \frac {\partial C}{\partial x} - \lambda C$$

Discretise the equation

$$\frac {C^{t+1}_{x} - C^{t}_{x}}{\Delta t} = \frac {D}{2} \Bigg(\frac {C^{t+1}_{x+1} - 2C^{t+1}_{x} + C^{t+1}_{x-1}}{\Delta x^2} + \frac {C^{t}_{x+1} - 2C^{t}_{x} + C^{t}_{x-1}}{\Delta x^2} \Bigg) -\frac {w}{2} \Bigg( \frac {C^{t+1}_{x+1} - C^{t+1}_{x-1}}{2 \Delta x} + \frac {C^{t}_{x+1} - C^{t}_{x-1}}{2 \Delta x} \Bigg) - \frac{\lambda}{2} \Big( C^{t+1}_{x} + C^t_{x} \Big)$$$$C^{t+1}_{x} = C^{t}_{x} + \frac {D \Delta t}{2 \Delta x^2} \Bigg( C^{t+1}_{x+1} - 2C^{t+1}_{x} + C^{t+1}_{x-1} + C^{t}_{x+1} - 2C^{t}_{x} + C^{t}_{x-1} \Bigg) - \frac {w \Delta t}{4\Delta x} \Bigg(C^{t+1}_{x+1} - C^{t+1}_{x-1} + C^{t}_{x+1} - C^{t}_{x-1} \Bigg) - \frac{\lambda \Delta t}{2} \Big( C^{t+1}_{x} + C^t_{x} \Big)$$

if $\frac {w \Delta t}{4\Delta x} = \sigma$, $\frac {D \Delta t}{2 \Delta x^2} = \rho$ and $\frac{\lambda \Delta t}{2} = \mu$

$$C^{t+1}_{x} = C^{t}_{x} + \rho C^{t+1}_{x+1} - 2\rho C^{t+1}_{x} + \rho C^{t+1}_{x-1} + \rho C^{t}_{x+1} - 2\rho C^{t}_{x} + \rho C^{t}_{x-1} - \sigma C^{t+1}_{x+1} + \sigma C^{t+1}_{x-1} - \sigma C^{t}_{x+1} + \sigma C^{t}_{x-1} - \mu C^{t+1}_{x} - \mu C^t_{x}$$

and rearranging,

$$-(\sigma + \rho)C^{t+1}_{x-1} + (1 + 2\rho + \mu)C^{t+1}_{x} + (\sigma - \rho)C^{t+1}_{x+1} = (\sigma + \rho) C^{t}_{x-1} + (1 - 2\rho - \mu)C^{t}_{x} + (\rho - \sigma) C^{t}_{x+1}$$

gives the discretised equation for $x > 1, x < L$.


In [ ]: