As mentioned in the previous section, this scheme is basically the average of both the explicit and implicit FTCS schemes. This gives us a diffusion equation in matrix form as
![]() |
(3.39) |
| (3.40) | ||
| (3.41) |
We can implement this equation straight away in the code that we
already have implemented for the matrix form for the explicit FTCS
scheme, it now just being a matter of taking one matrix inverse and a
couple of matrix multiplications to create the
matrix and
then, again, just run the following code in the main loop:
Just to reiterate, this is stable, accurate, easy to understand where all of the parts come from, and very simple to alter the differential equation that we are attempting to model without large changes in code. Other schemes can have handy properties as well, which is why we also study the FFT method, also known as the spectral method in the next section.
Paul Cochrane 2002-04-18