Finite Difference Approximation
Using a one-sided first-order approximation for the time derivative (linking $f_j^n$ and $f_j^{n+1}$) and second-order centered approximations for the spatial derivatives \[ \left.\frac{\partial f}{\partial t}\right)_j^n \approx \frac{f_j^{n+1} - f_j^n}{\Delta t}; \quad \left.\frac{\partial f}{\partial x}\right)_j^n \approx \frac{f_{j+1} - f_{j-1}}{2\Delta x}; \quad \left.\frac{\partial^2 f}{\partial x^2}\right)_j^n \approx \frac{f_{j+1} - 2f_j + f_{j-1}}{\Delta x^2} \]
The discrete approximation of the advection-diffusion equation becomes $$ \frac{f_j^{n+1} - f_j^n}{\Delta t} + U \left(\frac{f_{j+1}^n - f_{j-1}^n}{2\Delta x}\right) = D \left(\frac{f_{j+1}^n - 2 f_j^n + f_{j-1}^n}{\Delta x^2}\right) $$ Given the discrete values of $f$ at one time ($\ldots, f_{j-1}^n, f_j^n, f_{j+1}^n, \ldots$), this equation allows us to update all the $f$’s by computing $f_j^{n+1}$ as a linear combination of $f_{j-1}^n, f_j^n,$ and $f_{j+1}^n$