Consider the heat equation ut=uxx+uyy. After a long time, the distribution of temperature will stop changing. This steady-state solution must satisfy the PDE uxx+uyy=0, which is our third and final canonical PDE.
The Laplace/Poisson equation is the archetype of an elliptic PDE. All linear, constant-coefficient PDEs with no higher than second derivatives can be classified as either parabolic, hyperbolic, or elliptic. No time variable appears in (13.3.1). Although variable names are arbitrary, elliptic PDEs often do represent systems at steady state.
In order to get a fully specified problem, the Laplace or Poisson equations must be complemented with a boundary condition. Because both x and y are spatial variables, this is our first encounter with a boundary condition that is not imposed simply at a pair of points. We consider only the Dirichlet condition u(x,y)=g(x,y) around the entire boundary.
With the unknown solution represented by its values U=mtx(u) on a rectangular grid, and second-derivative finite-difference or spectral differentiation matrices Dxx and Dyy, the Poisson equation (13.3.1) becomes the discrete equation
where F=mtx(f). Equation (13.3.2), with an unknown matrix U multiplied on the left and right in different terms, is known as a Sylvester equation. We will use a new matrix operation to solve it.
We can use (13.3.4) to express the Sylvester form (13.3.2) of the discrete Poisson equation as an ordinary linear system. First, we pad (13.3.2) with identity matrices,
This is in the form of a standard linear system in (m+1)(n+1) variables.
Boundary conditions of the PDE must yet be applied to modify (13.3.7). As has been our practice for one-dimensional boundary-value problems, we replace the collocation equation for the PDE at each boundary point with an equation that assigns that boundary point its prescribed value. The details are a bit harder to express algebraically in the two-dimensional geometry, though, than in the 1D case.
Say that N=(m+1)(n+1) is the number of entries in the unknown U, and let B be a subset of {1,…,N} such that i∈B if and only if (xi,yi) is on the boundary. Then for each i∈B, we want to replace row i of the system Au=b with the equation
Hence from A we should subtract away its ith row and add eiT back in. When this is done for all i∈B, the result is the replacement of the relevant rows of A with relevant rows of the identity:
where IB is a matrix with zeros everywhere except for ones at (i,i) for all i∈B. A similar expression can be derived for the modification of b. However, rather than implementing a literal interpretation of (13.3.9), the changes to A and b are made more easily through logical indexing. A small example is more illuminating than further description.
We use Demo 13.3.2 as a template: create the linear system, modify it for the boundary conditions, solve it using backslash, and reshape to get a grid function. The matrix is N=(m+1)(n+1) on each side and very sparse, so we take care to use sparse matrices in the code to exploit that structure. There is a small but important change from Demo 13.3.2: the boundary conditions are rescaled to read σu(x,y)=σg(x,y), where σ is the largest element of a row of A. This tweak improves the condition number of the final matrix.
In Function 13.3.1 we used second-order finite differences for the discretization. Let’s simplify the discussion by assuming that m=n. The error in the solution can be expected to be O(n−2).
The matrix A has size N=O(n2). The upper and lower bandwidths of the matrix A are both O(n). It can be shown that the matrix is symmetric and negative definite, so sparse Cholesky factorization can be applied to −A, taking O(n2N)=O(n4) operations.
As n increases, the truncation error decreases while the operation count increases. The growth in operations is faster than the corresponding decrease in error, making it costly to get high accuracy. Suppose we have fixed running time T at our disposal. Then n=O(T1/4), and the convergence is O(1/T). For example, reduction of the error by a factor of 10 requires 100 times the computational effort.
If we chose a Chebyshev spectral discretization instead, the calculus changes. Provided that the solution is smooth, we expect convergence at a rate K−n for some K>1. However, the system matrix is no longer sparse nor symmetric, and solution by LU factorization takes O(N3)=O(n6) flops. Hence as a function of running time T, we expect a convergence rate on the order of K−T1/6. It’s not simple to compare this directly to the finite-difference case. In the long run, the spectral method will be much more efficient, but if the accuracy requirement is undemanding, second-order finite differences may be faster. For the specific case of Poisson’s equation on a rectangle, there are specialized fast solution methods that are beyond the scope of this discussion.
✍ Using general 2×2 matrices, verify identities 4 and 6 in Theorem 13.3.1.
✍ Prove that the matrix A defined in (13.3.7) is symmetric if Dxx and Dyy are symmetric.
⌨ Use Function 13.3.1 to solve the following problems on [0,1]×[0,1] using m=n=50. In each case, make a plot of the solution and a plot of the error.
(a)uxx+uyy=2x2[x2(x−1)+(10x−6)(y2−y)], with u=0 on the boundary.
Solution: u(x,y)=x4(1−x)y(1−y).
(b)uxx+uyy=(16x2+(1−4y)2)sinh(4xy−x), with u=sinh(4xy−x) on the boundary.
Solution: u(x,y)=sin(4πx)).
(c)uxx+uyy=−(20π2)sin(4πx)cos(2πy), with u=sin(4πx)cos(2πy) on the boundary.
Solution: u(x,y)=sin(4πx)cos(2πy).
⌨ For each case in Exercise 3, solve the problem using Function 13.3.1 with m=n=20,30,40,…,120. For each numerical solution compute the maximum absolute error on the grid. On a log-log plot, compare the convergence of the error as a function of n to theoretical second-order accuracy.
⌨ Copy Function 13.3.1 to a new function named poischeb, and modify it to use a Chebyshev discretization rather than finite differences. For each item in Exercise 3, solve the problem using poischeb for m=n=10,15,20,…,40. For each numerical solution compute the maximum absolute error on the grid. Show the convergence of the error as a function of n on a log-linear plot.
⌨ Sometimes boundary conditions are specified using a piecewise definition, with a different formula for each side of the domain. Use Function 13.3.1 with m=n=60 to solve the Laplace equation on [0,1]2 with boundary conditions