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)$$$$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)$$if $\frac {w \Delta t}{4\Delta x} = \sigma$ and $\frac {D \Delta t}{2 \Delta x^2} = \lambda$
$$C^{t+1}_{x} = C^{t}_{x} + \lambda C^{t+1}_{x+1} - 2\lambda C^{t+1}_{x} + \lambda C^{t+1}_{x-1} + \lambda C^{t}_{x+1} - 2\lambda C^{t}_{x} + \lambda 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}$$and rearranging,
$$-(\sigma + \lambda)C^{t+1}_{x-1} + (1 + 2\lambda)C^{t+1}_{x} + (\sigma - \lambda)C^{t+1}_{x+1} = (\sigma + \lambda) C^{t}_{x-1} + (1 - 2\lambda)C^{t}_{x} + (\lambda - \sigma) C^{t}_{x+1}$$gives the discretised equation for $x > 1, x < L$.
In [ ]: