Skip to article frontmatterSkip to article content

The method of lines

Our strategy in Black–Scholes equation was to discretize both the time and space derivatives using finite differences, then rearrange so that we could march the solution forward through time. It was partially effective, but as Example 11.1.3 shows, not a sure thing, for reasons we look into starting in the next section.

First, though, we want to look at a broader version of the discretization approach. To introduce ideas, let’s use the simpler heat equation, ut=uxxu_t = u_{xx}, as a model. Because boundaries always complicate things, we will start by doing the next best thing to having no boundaries at all: periodic end conditions. Specifically, we will solve the PDE over 0x<10\le x < 1 and require at all times that

u(x+1,t)=u(x,t)for all x.u(x+1,t)=u(x,t) \quad \text{for all $x$}.

This is a little different from simply u(1,t)=u(0,t)u(1,t)=u(0,t), as Figure 11.2.1 illustrates.

periodic function illustration

Figure 11.2.1:Left: A function whose values are the same at the endpoints of an interval does not necessarily extend to a smooth periodic function. Right: For a truly periodic function, the function values and all derivatives match at the endpoints of one period.

11.2.1Semidiscretization

As a reminder, we use u^\hat{u} when we specifically refer to the exact solution of the PDE. In order to avoid carrying along redundant information about the function, we use xi=ihx_i = ih only for i=0,,m1i=0,\ldots,m-1, where h=1/mh=1/m, and it’s understood that a reference to xmx_m is silently translated to one at x0x_0. More generally, we have the identity

u^(xi,t)=u^(x(imodm),t) \hat{u}(x_i,t) = \hat{u}\bigl(x_{(i \bmod{m})},t \bigr)

for the exact solution u^\hat{u} at any value of ii.

Next we define a vector u\mathbf{u} by

u(t)=[u0(t)u1(t)un(t)].\mathbf{u}(t) = \begin{bmatrix} u_0(t) \\ u_1(t) \\ \vdots \\ u_n(t) \end{bmatrix}.

This step is called semidiscretization, since space is discretized but time is not. As in Chapter 10, we will replace uxxu_{xx} with multiplication of u\mathbf{u} by a differentiation matrix Dxx\mathbf{D}_{xx}. The canonical choice is the three-point finite-difference formula (5.4.9), which in light of the periodicity (11.2.2) leads to

Dxx=1h2[211121121112].\mathbf{D}_{xx} = \frac{1}{h^2} \begin{bmatrix} -2 & 1 & & & 1 \\ 1 & -2 & 1 & & \\ & \ddots & \ddots & \ddots & \\ & & 1 & -2 & 1 \\ 1 & & & 1 & -2 \end{bmatrix}.

Note well how the first and last rows have elements that “wrap around” from one end of the domain to the other by periodicity. Because we will be using this matrix quite a lot, we create Function 11.2.1 to compute it, as well as the corresponding second-order first derivative matrix Dx\mathbf{D}_x for periodic end conditions.

The PDE ut=uxxu_t=u_{xx} is now approximated by the semidiscrete problem

du(t)dt=Dxxu(t), \frac{d \mathbf{u}(t)}{d t} = \mathbf{D}_{xx} \mathbf{u}(t),

which is simply a linear, constant-coefficient system of ordinary differential equations. Given the initial values u(0)\mathbf{u}(0) obtained from u(xi,0)u(x_i,0), we have an initial-value problem that we already know how to solve!

Semidiscretization is often called the method of lines. Despite the name, it is not exactly a single method because both space and time discretizations have to be specified in order to get a concrete algorithm. The key concept is the separation of those two discretizations, and in that way, it’s related to separation of variables in analytic methods for the heat equation.

The method in Example 11.2.1 and Example 11.2.2 is essentially the same one we used for the Black–Scholes equation in Black–Scholes equation. By changing the time integrator, we can get much better results.

Example 11.2.4 suggests that implicit time stepping methods have an important role in diffusion. We will analyze the reason in the next few sections.

11.2.2Black-box IVP solvers

Instead of coding one of the Runge–Kutta or multistep formulas directly for a method of lines solution, we could use any of the IVP solvers from Chapter 6, or a solver from the DifferentialEquations package, to solve the ODE initial-value problem (11.2.5).

The adaptive time integrators can all produce solutions. But, as seen in Example 11.2.5, they are not equivalent in every important sense. Whether we choose to implement a method directly with a fixed step size, or automatically with adaptation, there is something crucial to understand about the semidiscrete problem (11.2.5) that will occupy our attention in the next two sections.

11.2.3Exercises