Crank-Nicolson scheme

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

$\displaystyle \mbf{A}^{n+1} = \mbf{A}^n + \frac{\kappa \Delta t}{\Delta x^2} \mbf{D}\Biggl( \frac{\mbf{A}^{n+1} + \mbf{A}^n}{2} \Biggr),$ (3.39)

where we have used the average of the current $ \mbf{A}$ vector (explicit part) and the future $ \mbf{A}$ vector (implicit part). Solving this for $ \mbf{A}^{n+1}$ gives

$\displaystyle \mbf{A}^{n+1}$ $\displaystyle = \Bigl( \mbf{I}- \frac{\kappa \Delta t}{2 \Delta x^2} \mbf{D}\Bi...
...} \Bigl( \mbf{I}+ \frac{\kappa \Delta t}{2 \Delta x^2} \mbf{D}\Bigr) \mbf{A}^n,$ (3.40)
$\displaystyle \mbf{A}^{n+1}$ $\displaystyle = \mbf{M}\mbf{A}^n,$ (3.41)

where again we have wrapped up the $ \mbf{D}$ matrix containing terms into the matrix $ \mbf{M}$.

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 $ \mbf{M}$ matrix and then, again, just run the following code in the main loop:

A = M*A;
and that's it!

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