MTH3007b Lecture 10

Me, in the lecture

zzzzz…

This session moves from 1D time-dependent PDEs to a 2D steady-state problem: the Laplace equation. We solve it iteratively using Liebmann’s method (Gauss-Seidel applied to PDEs) and cover the Python array/matrix tools needed to implement it.

The 2D Laplace Equation

The 2D Laplace equation is the steady-state condition applied to the 2D diffusion equation:

Finite Difference Discretisation

Applying the centred second-derivative stencil in both and on a uniform grid with spacing :

When , this simplifies to the Laplacian difference equation:

Rearranging gives the update rule for each interior point:

Liebmann’s Method

Liebmann’s method is Gauss-Seidel iteration applied to the 2D Laplace equation. Starting from an initial guess (e.g. all zeros at interior points, with boundary values fixed), we repeatedly update each interior point using the formula above until the solution converges.

Convergence Criterion

Iteration continues until the maximum change over all interior points falls below a tolerance :

A typical value is .

Convergence is guaranteed because the resulting matrix is diagonally dominant: the diagonal entry has magnitude greater than the sum of the absolute values of the off-diagonal entries - just at the boundary of strict diagonal dominance, but the fixed boundary conditions ensure convergence.

Computing the Maximum Error

Two equivalent approaches:

Python
Output

The np.amax version is more concise and vectorised.

Algorithm

  1. Create two 2D arrays u_xy and unew_xy of size , initialised to zero.
  2. Set Dirichlet boundary conditions on all four edges of u_xy.
  3. Copy u_xy to unew_xy.
  4. Loop over all interior points ; update unew_xy[i,j] using the four neighbours from u_xy.
  5. Compute max_error = np.amax(np.abs(unew_xy - u_xy)).
  6. Copy unew_xy into u_xy (use u_xy = 1.0*unew_xy to copy by value).
  7. Repeat from step 4 until max_error < epsilon.
  8. Plot the result with matplotlib’s plot_surface.

Arrays and Matrices in Python

Creating and Indexing

Python
Output

Array copying

B = A does not copy an array - it creates an alias. Both A and B then point to the same data. Use B = 1.0*A or B = A.copy() to get an independent copy.


Pre-Lecture Notes from University Notes

  • 2D Laplace equation: ; steady-state condition on 2D diffusion.
  • Finite difference discretisation gives: .
  • Liebmann update: .
  • Iterate until (e.g. ).
  • Convergence guaranteed by diagonal dominance of the system matrix.
  • Max error: np.amax(np.abs(unew_xy - u_xy)) is the vectorised approach.
  • Array copy: B=1.0*A or B=A.copy(); never B=A for independent copies.
  • Next session: revision - feedback on Python implementations and a list of practice exercises.