Numerical Methods · Worked example

Ritz-Galerkin in 2D — a Heated Square Plate

The same trial-function trick from the 1D Bessel example, now on a square plate with uniform internal heat generation. One trial term gets the center close; a second term tightens that up further — but watch what it does away from the center.

∂²θ/∂x² + ∂²θ/∂y² + Ėgen/k = 0,  θ=0 on all 4 edges  →  θ ≈ (L²−x²)(l²−y²)(a₀ + a₁x²)
A square plate of side 2, generating heat uniformly, clamped to zero temperature at every edge.

θ(x,y) — Ritz-Galerkin approximation

Center θ(0,0) is hottest (red) · edges are clamped to 0 (dark)
θ(0,0), this approx.
θ(0,0), finite-difference
Error at center
Coefficients

Number of trial terms

Conductivity k (W/m·K)

275

Generation fixed at Ėgen = 10⁶ W/m³, matching the source notes' plate. Only the ratio Ėgen/k actually matters — lowering k is equivalent to raising the generation rate.

What you're seeing

The weighted-residual equations being solved, live

    Worked from the site author's own teaching notes on the Ritz-Galerkin method, the 2D companion to the 1D Bessel example. References cited there: Optimization by Variational Methods, Morton M. Denn, McGraw-Hill Book Company, 1969; Conduction Heat Transfer, V. Arpaci, Addison-Wesley Publishing Company, 1966.

    Same idea, one more dimension

    The trial function φ₀(x,y) = (L²−x²)(l²−y²) is built the same way as the 1D case: it's exactly zero on all four edges, automatically, for any coefficient you put in front of it — so the boundary condition θ=0 is satisfied by construction, and only the PDE itself needs approximating. The Galerkin condition generalizes from a single integral to a double integral over the plate: ∫∫ R(x,y)·φᵢ(x,y) dx dy = 0 for each trial function used.

    A second term that only refines one direction

    The second trial function here is φ₁(x,y) = (L²−x²)(l²−y²)x² — it adds extra flexibility in x, but none in y. For a square plate, the true solution is symmetric under swapping x and y, but this particular two-term trial space isn't: it can only bend the approximation's shape along x. The result is a genuinely interesting trade-off, verified directly against an independent finite-difference solve of the same plate: the center gets noticeably closer to the true value, while points off the diagonal can actually get slightly worse than the one-term approximation, because the extra term is pulling the shape in a direction that isn't the one the true solution actually varies in. Toggle between 1 and 2 terms and watch the heatmap stop being diagonally symmetric.

    The lesson: adding a trial function always reduces the residual in the aggregate (weighted) sense the method enforces — but it doesn't guarantee improvement everywhere, pointwise. A trial space that doesn't reflect the true solution's symmetry can trade accuracy in one place for accuracy in another.

    How "the truth" was checked here

    Rather than trust a single method, this lab computes a completely independent reference: a fine finite-difference solve of the exact same Poisson equation, using the same kind of relaxation sweep as the 2D Conduction lab and Gauss-Seidel lab. The Ritz-Galerkin approximation and the finite-difference grid solve the same physics two completely different ways — when they agree, that's real evidence, not a coincidence of algebra.

    EngineeringCandy · Numerical Methods · weighted residuals computed live, checked against an independent finite-difference solve · build it, break it, learn