Skip to article frontmatterSkip to article content

Differentiation matrices

In Finite differences we used finite differences to turn a discrete collection of function values into an estimate of the derivative of the function at a point. Just as with differentiation in elementary calculus, we can generalize differences at a point into an operation that maps discretized functions to discretized derivatives.

The derivative of a function is a unique result. The same is not true for our finite-dimensional approximation of the derivative, though.

10.3.1Matrices for finite differences

We first discretize the interval x[a,b]x\in[a,b] into equal pieces of length h=(ba)/nh=(b-a)/n, leading to the nodes

xi=a+ih,i=0,,n,h=ban.x_i=a + i h, \quad i=0,\ldots,n, \qquad h=\frac{b-a}{n}.

Note again that our node indexing scheme starts at zero. Our goal is to find a vector g\mathbf{g} such that gif(xi)g_i \approx f'(x_i) for i=0,,ni=0,\ldots,n. Our first try is the forward difference formula (5.4.2),

gi=fi+1fih,t=0,,n1.g_i = \frac{f_{i+1}-f_i}{h}, \qquad t=0,\ldots,n-1.

However, this leaves gng_n undefined, because the formula would refer to the unavailable value fn+1f_{n+1}. For gng_n we could resort to the backward difference

gn=fnfn1h.g_n = \frac{f_{n}-f_{n-1}}{h}.

We can summarize the entire set of formulas by defining

f=[f(x0)f(x1)f(xn1)f(xn)],\mathbf{f} = \begin{bmatrix} f(x_0) \\[1mm] f(x_1) \\[1mm] \vdots \\[1mm] f(x_{n-1}) \\[1mm] f(x_n) \end{bmatrix}, \quad

and then the vector equation

[f(x0)f(x1)f(xn1)f(xn)]Dxf,Dx=1h[11111111].\begin{bmatrix} f'(x_0) \\[1mm] f'(x_1) \\[1mm] \vdots \\[1mm] f'(x_{n-1}) \\[1mm] f'(x_n) \end{bmatrix} \approx \mathbf{D}_x \mathbf{f}, \qquad \mathbf{D}_x = \frac{1}{h} \begin{bmatrix} -1 & 1 & & & \\[1mm] & -1 & 1 & & \\[1mm] & & \ddots & \ddots & \\[1mm] & & & -1 & 1 \\[1mm] & & & -1 & 1 \end{bmatrix}.

The matrix Dx\mathbf{D}_x in (10.3.5) is a finite-difference differentiation matrix. Here as elsewhere, elements of Dx\mathbf{D}_x that are not shown are zero. Each row of Dx\mathbf{D}_x gives the weights of a finite-difference formula being used at one of the nodes.

The differentiation matrix Dx\mathbf{D}_x in (10.3.5) is not a unique choice. In fact, it’s about the least accurate choice possible, as explained in Convergence of finite differences. We are theoretically free to use whatever finite-difference formulas we want in each row, such as those in Table 5.4.1 and Table 5.4.2, although it makes sense to choose rows that are as similar as possible. For instance, using second-order centered differences where possible and second-order one-sided formulas at the boundary points leads to

to be applied to a vector of function values at the nodes (10.3.1).

10.3.2Second derivative

In a TPBVP, we will need to take the second derivative of the unknown solution. One option is to apply a first derivative twice, that is, to multiply the value vector f\mathbf{f} on the left by Dx2\mathbf{D}_x^2. This is usually not the best option, however (see Finite differences). Instead, the following is usually a better choice:

10.3.3Implementation

Together, the matrices (10.3.6) and (10.3.10) give second-order approximations of the first and second derivatives at all nodes. These matrices, as well as the nodes x0,,xnx_0,\ldots,x_n, are returned by Function 10.3.1.

10.3.4Spectral differentiation

Recall that finite-difference formulas are derived in three steps:

  1. Choose a node index set SS near node ii.
  2. Interpolate with a polynomial using the nodes in SS.
  3. Differentiate the interpolant and evaluate at node ii.

We can modify this process by using a global interpolant, either polynomial or trigonometric, as in Chapter 9. Rather than choosing a different index set for each node, we use all the nodes each time.

In a nonperiodic setting, we use Chebyshev second-kind points for stability:

xk=cos(kπn),k=0,,n.x_k = -\cos\left(\frac{k \pi}{n}\right), \qquad k=0,\ldots,n.

Function 10.3.2 returns the matrices from Definition 10.3.4. This function uses a change of variable to transplant the standard [1,1][-1,1] for Chebyshev nodes to any [a,b][a,b]. It also takes a different approach to computing the diagonal elements of Dx\mathbf{D}_x than the formulas in (10.3.12) (see Exercise 10.3.5).

According to Theorem 9.3.1, the convergence of polynomial interpolation to ff using Chebyshev nodes is spectral if ff is analytic (at least having infinitely many derivatives) on the interval. The derivatives of ff are also approximated with spectral accuracy.

10.3.5Exercises

References
  1. Trefethen, L. N. (2000). Spectral Methods in MATLAB. SIAM.