Learning Objectives
By the end of this section, you will be able to:
- Set up Laplace's equation on a rectangle with Dirichlet boundary values on all four sides, and reduce the four-boundary problem to four one-boundary problems by superposition.
- Derive the building-block solution from separation of variables, and explain why the sign of the separation constant is forced by the boundary conditions.
- Compute the Fourier-sine coefficients of the non-homogeneous boundary by hand for at least one boundary function.
- Recognise the exponential decay of high-frequency modes encoded in as the smoothing mechanism of Laplace's equation.
- Build a working solver in Python and PyTorch and double-check it against an analytically known boundary.
- Use the interactive viewers to watch a single mode, to fit a custom top edge, and to inspect the full interior of the rectangle as you change the mode count.
The Big Picture
"A harmonic function on a region is the function that has no choice but to interpolate its boundary values as smoothly as possible."
Laplace's equation looks almost embarrassingly simple. Two second derivatives, set to zero. Yet this equation governs the steady-state temperature of a metal plate, the gravitational and electrostatic potentials in empty space, the shape of a soap film stretched on a wire frame, the velocity potential of an ideal fluid, and the equilibrium of countless other physical systems. Anywhere you find a system that has settled down and stopped changing, Laplace is hiding underneath.
In a rectangle the equation becomes one of the cleanest stories in applied mathematics. The rectangle has four straight edges, the operator is symmetric under , and the basis we will discover — products of sines and hyperbolic sines — is so well-matched to the geometry that the entire problem reduces to one Fourier series.
The intuition in one sentence
The boundary values are projected onto a sine basis along the active edge, and each projection is carried into the interior with a known exponential decay rate — bigger frequency means faster decay away from the boundary.
The Problem We Want to Solve
Fix a rectangle . We seek a function defined on that satisfies
together with Dirichlet boundary conditions on each of the four sides. To keep the derivation clean we start with the simplest non-trivial case: three sides clamped to zero, one side given:
- Left wall: for .
- Right wall: for .
- Bottom edge: for .
- Top edge: — the only non-zero edge.
Solving this single-active-edge case will turn out to be enough, because of linearity: if all four edges are active, we just solve four problems of the above type and add the answers. That trick is the whole reason we focus our energy on one edge.
Why the corners are not a problem
At the corners the boundary specification can clash — from the left wall but from the top edge. The fix is to require so the two prescriptions agree. The Fourier-sine basis we are about to use enforces this automatically — every basis function vanishes at and .
The Intuition: Steady-State Heat in a Plate
Before any algebra, picture a thin rectangular metal plate. Three edges are held in an ice bath at . Along the top edge a heater paints a pattern : hot in the middle, say, and cool near the corners. Wait long enough for the temperature inside the plate to stop changing. The resulting steady temperature is exactly the solution we seek.
Two physical facts already tell us nearly everything about the answer:
- The maximum is on the boundary. Heat flows from hot to cold; an interior hotspot would lose heat to its neighbours and cool down, contradicting steady state. The peak value of is achieved at some point on the boundary — and so is the minimum.
- Information from the heater decays with depth. A sharp spike on the top edge cannot punch through to the bottom; it gets smeared out by the time it has travelled even a small fraction of the rectangle height. The finer the spike, the faster it attenuates. We will see this decay quantitatively as : high frequency ⇒ shallow penetration.
Both facts will fall out of the formula. Hold this picture in your head: a heated edge whose imprint diffuses smoothly across the plate.
The Strategy: Separation of Variables
We guess that the answer is a product:
This is a strong, restrictive guess: most functions of two variables are not products. The reason it works here is the equation's linearity — once we find every product solution we can add them up to build the general one. Substitute the guess into Laplace's equation:
Divide through by (legal away from the boundary, where the product is nonzero):
The left side depends only on , the right side only on . The only way these two can be equal for all is if both equal the same constant. Call that constant (the minus sign is chosen to make the next two equations look standard):
The hidden art of the minus sign
Whether the constant is or looks arbitrary — but it is forced by the boundary conditions. The side walls demand , a homogeneous Dirichlet problem on a finite interval, and that problem has non-trivial solutions only when . So we set up the equation with (oscillatory in ) and the partner (exponential in ). The geometry chooses for us.
The X-Equation: Sine Modes from the Side Walls
The X-equation with side-wall conditions is the classic Sturm–Liouville eigenvalue problem. Take ; the general solution is
The left wall kills the cosine: . The right wall demands either (trivial) or , which forces
So the allowed -functions are for , and the corresponding separation constants are . These are the only building blocks compatible with the side walls — there is no other choice.
Why we can drop B = 0
The trivial solution gives , which is the unique answer only when on the top edge. For any non-trivial top boundary we need at least one mode with , so we are forced into the discrete spectrum .
The Y-Equation: Hyperbolic Sines from the Bottom
With fixed by the side walls, the -equation becomes
Now the sign of the constant matters: this is the exponential ODE, not the oscillatory one. Its general solution is
The bottom-edge condition (so that ) forces , because while . We are left with
The constant is absorbed into the overall coefficient of the mode (we have one free constant per ; whether we put it on or on is bookkeeping). It is convenient to normalise the hyperbolic sine so that the mode equals at the top edge:
With this normalisation the mode profile rises from at to at , and any leftover scaling lives in the coefficient we will compute from the top edge.
One Building-Block Mode
Multiplying the two pieces together, the n-th building block is
Each is harmonic (verify by direct substitution), satisfies all three zero boundary conditions, and equals on the top edge — the n-th sine wave of the boundary basis. So our problem is reduced to matching the top edge with a sum of sines, which is exactly a Fourier sine series.
| n | Top-edge shape sin(nπx/a) | Vertical decay rate from y = b |
|---|---|---|
| 1 | one bump, peak at x = a/2 | slowest, e^{-π(b−y)/a} |
| 2 | one positive bump, one negative | twice as fast |
| 3 | three lobes alternating sign | three times as fast |
| n | n lobes with n−1 sign changes | n × baseline |
Interactive: A Single Mode
Slide below. Watch two things at once: on the heatmap, the top edge gets the n-th sine wave imprinted on it; in the interior, the wiggles fade exponentially as you move downward. The little side panels show the two factors and — the building blocks themselves.
What to notice while you play
- For , the mode penetrates almost all the way to the bottom — the slow-frequency component reaches deepest.
- For , the wiggles are basically invisible below . High frequency, shallow imprint.
- The profile is always 0 at and 1 at — the normalization we chose so that the coefficient absorbs all the boundary scaling.
Superposition: Adding Modes to Match the Top
A single mode can only match a top boundary that already looks like . For a general we need a weighted sum:
Because each is harmonic and Laplace's equation is linear, every finite sum (and every convergent infinite sum) is also harmonic. Each term carries its share of the boundary; together they have to add up exactly to on the top edge. Setting and using :
That last line is the heart of the matter. The whole 2D problem reduces to a 1D Fourier sine expansion of the top-edge function. The coefficients we read off here immediately feed into the 2D formula above.
Reading the Top Edge as a Fourier Sine Series
How do we extract from ? The sines are orthogonal on :
Multiply the boundary identity by and integrate from to . By orthogonality, every term in the sum vanishes except , leaving
Solving for (and renaming ):
This is the only formula you need to remember. The 2D problem is completely determined by these 1D integrals along the active edge.
Interactive: Fitting the Top Boundary
Pick a top-edge function and slide . The thick black curve is the true ; the red curve is the partial sum . The stem plot underneath shows all the coefficients (red = kept, grey = thrown away).
The shape of b_n tells you everything
- Smooth bump: coefficients decay exponentially. Three modes essentially nail it.
- Triangular pluck: coefficients decay like because the function has a corner (kink in the first derivative).
- Square plateau: jumps at and . Coefficients decay only like ; you get persistent ~9% overshoot at the jumps no matter how many modes you keep — the Gibbs phenomenon.
- Single mode sin(3πx): exactly one non-zero coefficient, . The fit is already perfect at .
The Full Solution Formula
Putting it all together:
Every symbol has a meaning we have earned:
| Symbol | Role | Where it came from |
|---|---|---|
| sin(nπx/a) | horizontal shape of mode n | side-wall boundary conditions |
| sinh(nπy/a) | vertical growth from bottom | bottom-edge condition Y(0) = 0 |
| sinh(nπb/a) | normalisation at top | convenience: makes the mode equal 1 on the top |
| b_n | weight of mode n | Fourier inner product with f on the top edge |
Interactive: The Full Rectangle Solver
Choose a top-boundary function. Slide (number of modes summed) and (rectangle height). The interior of the rectangle is the harmonic function determined by the chosen boundary. Red is positive, blue is negative, white is zero.
Three experiments to try
- Pick Square plateau, set . Notice the boundary fits poorly near the jumps but the interior looks perfectly smooth. Harmonic functions are instantly analytic in the interior — only the boundary values inherit the roughness.
- Pick Triangular pluck, slide from (short rectangle) to (tall rectangle). The taller the rectangle, the cleaner the bottom-half interior becomes — the high-frequency boundary information cannot reach down that far.
- Pick sin(3πx) at . The fit is wrong (only the first mode contributes). Increase to and watch the answer snap into place — this boundary is a single building block, so three modes is overkill but two is short.
Worked Numerical Example
We commit to specific numbers and turn the crank by hand. Set up the problem so the answer is something we can recognise.
Hand-traced example: top edge , rectangle
Step 1 — Compute the coefficients. The top-edge function is already a linear combination of basis sines, so the integrals are pure orthogonality bookkeeping. Using :
For only the first term contributes : . For only the second term contributes : . All other .
Step 2 — Plug into the master formula with :
Step 3 — Sanity-check the boundary.
- At : , so . ✓
- At : , so . ✓
- At and : , so . ✓
Step 4 — Evaluate at a single point. Take . Then (kills the first term) and (full amplitude for the second).
Numerically and , so
Step 5 — Interpret. The top edge is order at (the second term peaks there with value ), but by the midline the contribution from the mode has been attenuated by a factor of . That is the price of frequency: each unit of roughly halves the depth of penetration in this rectangle.
Sanity check this with the interactive solver
Open the rectangle solver above, select sin(3πx), push to 1, change b to 1.0. The colour scale shows the same attenuation effect we just computed by hand for a different boundary — the principle is identical.
Python: Computing the Coefficients by Hand
For boundaries that are not already a sum of sines, the integral has to be done numerically. The midpoint rule with a few hundred points is enough to recover the coefficients to 4–5 digits. Here is the cleanest possible implementation, with each line annotated.
Try this
Change to (a smooth parabola). Run the script. You should see only odd coefficients are non-zero (parabolic boundary is symmetric about ) and they decay like (smoothness pays for itself).
PyTorch: A Vectorised Solver in 12 Lines
Once we have the coefficients, evaluating on a whole grid is a single tensor operation. The same code works on CPU or GPU without modification, and it scales effortlessly to a million grid points.
Why einsum is the right tool here
Three rank-1 ingredients (, , ) combine to a rank-2 output via a contraction over . That is the textbook use case for . Writing it with three nested for-loops would be hundreds of times slower and ten times harder to read.
Four Active Boundaries by Superposition
Real problems give you all four edges. Decompose the prescribed data as
- Problem T: top edge =, other three = 0. We just solved this.
- Problem B: bottom edge = , other three = 0. Same formula with .
- Problem L: left edge = , other three = 0. Same formula with and .
- Problem R: right edge = , other three = 0. Same as Problem L with the role of left/right swapped.
By linearity, the full solution is . Each piece is worked out independently using the single-boundary machinery we derived. There is no new mathematics — only careful labelling.
Why superposition is allowed
Laplace's equation is linear and homogeneous: . The boundary conditions add as well (each piece is non-zero on a different edge), so the sum exactly satisfies the full four-edge data. Uniqueness of the Dirichlet problem (proved in section 28-02) then guarantees this is the answer.
What the Decay Rates Really Mean
The factor is the secret carrier of every interesting physical fact about Laplace's equation in a rectangle. For large , both sinh's look like half their exponential, so
Read this carefully. At depth below the active top edge, the n-th boundary mode is suppressed by a factor of . So a feature of characteristic width on the boundary (which has dominant frequency ) will decay over a depth of order . Narrow features die fast; broad features reach deep.
This is the same principle that lets you see a mountain from far away but not read a book on the mountaintop with binoculars: high spatial frequencies decay rapidly with distance.
Common Pitfalls
- Wrong sign on the separation constant. If you accidentally set (instead of ) the solutions become hyperbolic, the side-wall conditions force , and the only solution you get is . Always let the geometry pick the sign for you.
- Forgetting to divide by sinh(nπb/a). Without the normalisation, your formula equals on the top edge, which is huge for large . Your reconstruction of will look like a spike train.
- Numerical overflow for tall rectangles. overflows around in double precision. For a 4:1 aspect ratio that is around . Either use the asymptotic for large arguments, or truncate before overflow — the high-n terms are negligible anyway.
- Boundary mismatch at the corners. If or , the basis cannot reproduce the corner values exactly and you get Gibbs ringing. Either subtract off a corner-linear interpolant before expanding, or live with the overshoot.
- Using cosines instead of sines. Cosines are natural for Neumann conditions (zero normal derivative). For zero Dirichlet conditions on the side walls, only sines vanish at both endpoints — sines are forced. Picking the wrong basis ruins everything downstream.
Summary
The whole section in one breath:
| Question | Answer |
|---|---|
| What PDE are we solving? | uₓₓ + u_yy = 0 on [0,a]×[0,b] |
| Which boundary is non-zero? | One edge at a time — superposition handles the rest |
| What ansatz? | Product u = X(x) Y(y) |
| What are the X-modes? | sin(nπx/a) for n = 1, 2, 3, ... |
| What are the Y-modes? | sinh(nπy/a) / sinh(nπb/a) |
| How are the coefficients chosen? | Fourier sine projection of f on the active edge |
| How fast do modes decay? | Like e^(-nπ(b−y)/a) — narrow features die fast |
| How do we implement it? | Compute b_n by quadrature, then one einsum |
The single sentence to take with you
The Laplace problem on a rectangle is a Fourier-sine projection of the boundary along its homogeneous direction, paired with an exponential (sinh) interpolation across the inhomogeneous direction — geometry chooses the basis, orthogonality chooses the coefficients, and chooses how deeply each boundary feature reaches into the interior.