Consider the normalized
heat equation in one dimension, with homogeneous
Dirichlet boundary conditions \begin{cases} U_t = U_{xx} \\ U(0,t) = U(1,t) = 0 & \text{(boundary condition)} \\ U(x,0) = U_0(x) & \text{(initial condition)} \end{cases} One way to numerically solve this equation is to approximate all the derivatives by finite differences. First partition the domain in space using a mesh x_0, \dots, x_J and in time using a mesh t_0, \dots, t_N . Assume a uniform partition both in space and in time, so the difference between two consecutive space points will be
h and between two consecutive time points will be
k. The points u(x_j,t_n) = u_{j}^n will represent the numerical approximation of u(x_j, t_n).
Explicit method for the most common explicit method for the heat equation. Using a
forward difference at time t_n and a second-order
central difference for the space derivative at position x_j (
FTCS) gives the recurrence equation: \frac{u_{j}^{n+1} - u_{j}^{n}}{k} = \frac{u_{j+1}^n - 2u_{j}^n + u_{j-1}^n}{h^2}. This is an
explicit method for solving the one-dimensional
heat equation. One can obtain u_j^{n+1} from the other values this way: u_{j}^{n+1} = (1-2r)u_{j}^{n} + ru_{j-1}^{n} + ru_{j+1}^{n} where r=k/h^2. So, with this recurrence relation, and knowing the values at time
n, one can obtain the corresponding values at time
n+1. u_0^n and u_J^n must be replaced by the boundary conditions, in this example they are both 0. This explicit method is known to be
numerically stable and
convergent whenever r\le 1/2 . The numerical errors are proportional to the time step and the square of the space step: \Delta u = O(k)+O(h^2)
Implicit method Using the
backward difference at time t_{n+1} and a second-order central difference for the space derivative at position x_j (The Backward Time, Centered Space Method "BTCS") gives the recurrence equation: \frac{u_{j}^{n+1} - u_{j}^{n}}{ k } =\frac{u_{j+1}^{n+1} - 2u_{j}^{n+1} + u_{j-1}^{n+1}}{h^2}. This is an
implicit method for solving the one-dimensional
heat equation. One can obtain u_j^{n+1} from solving a system of linear equations: (1+2r)u_j^{n+1} - r u_{j-1}^{n+1} - ru_{j+1}^{n+1}= u_j^n The scheme is always
numerically stable and convergent but usually more numerically intensive than the explicit method as it requires solving a system of numerical equations on each time step. The errors are linear over the time step and quadratic over the space step: \Delta u = O(k)+O(h^2).
Crank–Nicolson method Finally, using the central difference at time t_{n+1/2} and a second-order central difference for the space derivative at position x_j ("CTCS") gives the recurrence equation: \frac{u_j^{n+1} - u_j^{n}}{ k } = \frac{1}{2} \left(\frac{u_{j+1}^{n+1} - 2u_j^{n+1} + u_{j-1}^{n+1}}{h^2}+\frac{u_{j+1}^{n} - 2u_j^{n} + u_{j-1}^{n}}{h^2}\right). This formula is known as the
Crank–Nicolson method. One can obtain u_j^{n+1} from solving a system of linear equations: (2+2r)u_j^{n+1} - ru_{j-1}^{n+1} - ru_{j+1}^{n+1}= (2-2r)u_j^n + ru_{j-1}^n + ru_{j+1}^n The scheme is always
numerically stable and convergent but usually more numerically intensive as it requires solving a system of numerical equations on each time step. The errors are quadratic over both the time step and the space step: \Delta u = O(k^2)+O(h^2).
Comparison To summarize, usually the
Crank–Nicolson scheme is the most accurate scheme for small time steps. For larger time steps, the implicit scheme works better since it is less computationally demanding. The explicit scheme is the least accurate and can be unstable, but is also the easiest to implement and the least numerically intensive. Here is an example. The figures below present the solutions given by the above methods to approximate the heat equation U_t = \alpha U_{xx}, \quad \alpha = \frac{1}{\pi^2}, with the boundary condition U(0, t) = U(1, t) = 0. The exact solution is U(x, t) = \frac{1}{\pi^2}e^{-t}\sin(\pi x). == Example: The Laplace operator ==