The last equation to be examined is the diffusion equation. The derivative terms are the same as the Schrödinger equation, so the FTCS algorithm becomes
![]()
This algorithm is stable only if
, the so
called Courant-Friedrichs-Lewy (CFL) condition. The more robust
DuFort-Frankel algorithm [6] uses a time centered first derivative
The factor of two comes about because we are interpolating the rate of
change over two time steps; the middle term in the second derivative
expansion has also been replaced by a temporal average.
eq:DFFeq must, of course, be solved for
before it can be
implemented. It is stable for all values of
and is the
algorithm used by the program. The algorithm requires the values of u
at two times,
and
, in order to compute the next step.
These values are stored in yVec
and yPrevVec
.
Although finite-difference methods are a respectable starting point for
the solution of differential equations, they can become unstable for
even modest values of
, and may therefore be computationally
inefficient. The interested reader may want to study the techniques
used by other CUPS authors such as the implicit Crank-Nicholson method
used by Dan Styer in his QMTIME program and the relaxation method used
by Bob Ehrlich and Jarek Tuszynski in their LAPLACE program, as well as
more specialized books on numerical methods.[13]