The “wave” on my home page is a screenshot of DGraphX, a graphing program I wrote in C. The green text in the corner reads [Seidel Gauss] Size of grid: 74x74, error: 0.55120, number of iterations: 2759: the surface is the numerical solution of a partial differential equation, found by an iterative solver. This page runs the same solvers in your browser.

The equation

DGraphX solves, on the unit square with zero values on the boundary,

\[c\,(-\Delta u) + \bigl(1 + \sin y^2\bigr)\,u = f(x, y), \qquad \Delta u = \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2},\]

an elliptic equation (a screened Poisson equation with a position-dependent potential). On an \(n \times n\) grid with spacing \(h = 1/(n-1)\) the five-point stencil turns it into a linear system: for every interior point

\[\Bigl(4 + \tfrac{h^2}{c}\bigl(1 + \sin y_i^2\bigr)\Bigr) u_{i,j} - u_{i-1,j} - u_{i+1,j} - u_{i,j-1} - u_{i,j+1} = \tfrac{h^2}{c}\, f(x_j, y_i).\]

The original image used \(c = 1\) and \(f(x,y) = 20 \sin(20xy)\) on a \(74\times74\) grid. The solution is a gentle ripple that rises to about 0.36.

The solvers

  • Seidel Gauss: compute the residual \(r = b - Au\) of the current grid, find a correction \(d\) by forward substitution along the grid, \(d_k = (r_k + d_{k-1} + d_{k-m})/\text{diag}_k\), and add it, \(u \leftarrow u + d\). It stops when \(\sum r^2/(n-1) \le 10^{-10}\).
  • Richardson iter: \(u \leftarrow u + \tau_l\, r\) with five relaxation parameters \(\tau_l\) that cycle, chosen from Chebyshev’s formula for a spectrum assumed to lie in \([2, 8]\). Cheap sweeps, no forward substitution.
  • Optionally, the textbook Jacobi, Gauss–Seidel and SOR (over-relaxation) methods on the same equations, for comparison.

With the default settings the output matches the original image exactly: 2759 iterations, error 0.55120. Press Run, or “Solve now” to jump to the end. Tick “Also run the textbook methods” to put Jacobi, Gauss–Seidel and SOR on the same chart.

What such an equation describes

The equation \(c\,(-\Delta u) + q(x, y)\,u = f(x, y)\) with \(c > 0\) and \(q \ge 0\) (here \(q = 1 + \sin y^2\)) is the steady state of a very common balance. Something spreads out (the term \(-c\,\Delta u\)), something is removed in proportion to the amount present (\(q\,u\)), something is supplied (\(f\)), and the edge of the region is held at zero. Depending on what \(u\) is, it describes:

  • Heat. The steady temperature of a thin plate whose edge is kept at 0, heated by a source \(f\) and losing heat to its surroundings at a rate proportional to its temperature (Newton’s law of cooling). The coefficient \(c\) is the conductivity.
  • Diffusion with decay. The steady concentration of a substance, such as a drug in tissue, a pollutant in a lake or a signalling molecule in an embryo, that diffuses with coefficient \(c\), is produced at rate \(f\) and breaks down at rate \(q\,u\). A boundary value of 0 is an absorbing wall.
  • A stretched membrane. The deflection of a drum skin under a load \(f\) when it also rests on an elastic foundation: \(c\) is the tension and \(q\) the stiffness of the foundation.
  • Electrostatics in an electrolyte or plasma. The potential of charges that are screened by the mobile charges around them (Debye–Hückel), which makes it fall off over a finite distance instead of reaching far away.

The coefficient \(c\) sets how far the effect of the source spreads. With \(c = 1\) the diffusion smooths everything into a single gentle hill. Choose \(c = 0.01\) above: diffusion is now weak, so the surface follows the source almost point by point, \(u \approx f/q\), and a thin layer at the edge pulls it down to the prescribed zero. The right-hand side \(20\sin(20xy)\) of the original is a source that oscillates faster and faster towards the far corner, and the solution is the response of the plate to it.

Equations of this type are rarely solved by formula, except on special shapes. They are discretised on a grid, as here, which turns them into a huge sparse linear system, and the system is solved by iteration. The iterations in the demo are the simplest members of that family. Relaxation sweeps of exactly this kind are the “smoothers” inside multigrid solvers, Richardson iteration with Chebyshev parameters is the ancestor of the conjugate-gradient family, and a system with this shape appears again at every time step when a time-dependent heat or diffusion problem is solved implicitly.

The original static image: wave.png (2804 × 1546). Source: DGraphX.