Lesson 12 of 15

Green's Functions

Green's Functions

A Green's function is the impulse response of a differential operator — the solution when the source term is a Dirac delta. If L\mathcal{L} is a linear differential operator, then:

LG(r,r)=δ(rr)\mathcal{L}\, G(\mathbf{r}, \mathbf{r}') = \delta(\mathbf{r} - \mathbf{r}')

Once we have G, the solution to Lu=f\mathcal{L}\, u = f is:

u(r)=G(r,r)f(r)dru(\mathbf{r}) = \int G(\mathbf{r}, \mathbf{r}')\, f(\mathbf{r}')\, d\mathbf{r}'

1D Poisson Equation

For d2u/dx2=f(x)-d^2u/dx^2 = f(x) on [0,L][0, L] with u(0)=u(L)=0u(0) = u(L) = 0:

G(x,x)=1Lmin(x,x)(Lmax(x,x))G(x, x') = \frac{1}{L} \min(x, x')\bigl(L - \max(x, x')\bigr)

This has a characteristic "tent" shape — it is continuous with a kink at x=xx = x'.

The solution is then:

u(x)=0LG(x,x)f(x)dxu(x) = \int_0^L G(x, x')\, f(x')\, dx'

For example, if f(x)=1f(x) = 1 (constant forcing), the solution is u(x)=x(Lx)/2u(x) = x(L-x)/2 — a parabolic profile that satisfies the boundary conditions and the equation.

Free-Space Green's Function (1D Laplacian)

In 1D free space (no boundary conditions), the Green's function for d2/dx2-d^2/dx^2 is:

G(x,x)=xx2G(x, x') = -\frac{|x - x'|}{2}

Numerical Solution via Green's Function

We discretise xx' into NN points and approximate the integral as a sum:

u(x)i=0N1G(x,xi)f(xi)Δxu(x) \approx \sum_{i=0}^{N-1} G(x, x_i')\, f(x_i')\, \Delta x'

where xi=(i+0.5)L/Nx_i' = (i + 0.5) \cdot L/N and Δx=L/N\Delta x' = L/N.

Implementation

  • greens_1d_poisson(x, x_prime, L) — returns G(x,x)G(x, x') for the 1D Poisson problem
  • greens_free_space_1d(x, x_prime) — returns xx/2-|x - x'|/2
  • poisson_solution(x, f_values, L, N=100) — evaluates u(x)u(x) by summing GfΔxG \cdot f \cdot \Delta x
import math

def greens_1d_poisson(x, x_prime, L):
    return (1.0 / L) * min(x, x_prime) * (L - max(x, x_prime))
Python runtime loading...
Loading...
Click "Run" to execute your code.