Laplace Equation Solver
Topic:
advanced.pde.laplace_equation
Laplace's equation describes steady-state (equilibrium) distributions in physics. Solves elliptic PDEs with boundary conditions for harmonic functions in 2D rectangular domains.
Mathematical Definition
In 2D:
Key property: No time dependence → equilibrium state.
Physical applications:
- Electrostatics: (electric potential in charge-free regions)
- Steady-state heat: (temperature at equilibrium)
- Potential flow: (stream function)
- Gravity: (gravitational potential in vacuum)
Laplace Equation Solver
Mathematical Model
Laplace's equation describes steady-state (equilibrium) distributions:
In 2D:
Key property: No time dependence → equilibrium state.
Physical Interpretation
Laplace's equation governs:
- Electrostatics: (electric potential in charge-free regions)
- Steady-state heat: (temperature at equilibrium)
- Potential flow: (stream function for irrotational, incompressible flow)
- Gravity: (gravitational potential in vacuum)
Real-World Example: Electrostatic Potential in Rectangular Plate
Problem Setup
A thin rectangular conducting plate (dimensions = 10 cm × 5 cm) has:
- Bottom edge (): Grounded (0 V)
- Top edge (): Fixed potential 100 V
- Left/Right edges (, ): Grounded (0 V)
Find the electrostatic potential inside the plate.
Mathematical Formulation
PDE:
Boundary Conditions:
Analytical Solution
Separation of variables:
Eigenvalue problem from x-direction BCs:
Eigenvalues and eigenfunctions:
Y equation:
Apply : (cosh term vanishes)
General solution:
Apply top BC:
Fourier sine series:
Final solution:
Properties of Harmonic Functions
Definition: Solutions to Laplace's equation are called harmonic functions.
Maximum Principle
Theorem: If is harmonic on domain with boundary , then:
(Maximum occurs on boundary, not interior)
Physical interpretation: Equilibrium → no local maxima inside.
Mean Value Property
Theorem: Harmonic function value at any point equals average over any circle centered at that point:
Proof: Green's identity + Laplace equation.
Uniqueness
Theorem: Laplace equation with Dirichlet BCs has unique solution.
Proof: Suppose two solutions and . Let . Then:
- (Laplace)
- on boundary (same BCs)
- By maximum principle:
- Similarly:
- Therefore: everywhere →
Numerical Example: Potential at Center
For our 10 cm × 5 cm plate, what's the potential at the center cm?
Series solution (first 3 odd terms):
Note: for
Physical check: Center is about halfway between 0 V (bottom) and 100 V (top), so ~48 V is reasonable.
Limitations
⚠️ Rectangular domains only: Circular/irregular geometries require different coordinates.
⚠️ Dirichlet BCs only: Neumann BCs ( on boundary) require different eigenfunction matching.
⚠️ Symbolic coefficients: Same limitation as heat/wave equations.
⚠️ 2D only currently: 3D Laplace not yet implemented.
Examples
Electrostatic Potential in Rectangular Plate
10cm × 5cm conducting plate with bottom/sides grounded (0V) and top at 100V. Demonstrates equilibrium potential distribution.
Rust
#![allow(unused)] fn main() { use mathhook::prelude::*; let u = symbol!(u); let x = symbol!(x); let y = symbol!(y); let equation = expr!(u); let pde = Pde::new(equation, u, vec![x.clone(), y.clone()]); // Boundary conditions let bc_left = BoundaryCondition::dirichlet( expr!(0), BoundaryLocation::Simple { variable: x.clone(), value: expr!(0) }, ); let bc_right = BoundaryCondition::dirichlet( expr!(0), BoundaryLocation::Simple { variable: x.clone(), value: expr!(0.1) }, // a=10cm ); let bc_bottom = BoundaryCondition::dirichlet( expr!(0), BoundaryLocation::Simple { variable: y.clone(), value: expr!(0) }, ); let bc_top = BoundaryCondition::dirichlet( expr!(100), BoundaryLocation::Simple { variable: y, value: expr!(0.05) }, // b=5cm ); // Solve let solver = LaplaceEquationSolver::new(); let result = solver.solve_laplace_equation_2d(&pde, &[bc_left, bc_right, bc_bottom, bc_top])?; // What you get: println!("Solution: {}", result.solution); // u(x,y) = C_1*sin(λ₁*x)*sinh(λ₁*y) + C_2*sin(λ₂*x)*sinh(λ₂*y) + ... println!("X-eigenvalues: {:?}", result.x_eigenvalues); // [π/a, 2π/a, 3π/a, ...] = [nπ/a for n=1,2,3,...] println!("Coefficients: {:?}", result.coefficients); // [C_1, C_2, C_3, ...] SYMBOLIC }
Python
from mathhook import symbol, expr, Pde, BoundaryCondition, BoundaryLocation, LaplaceEquationSolver
u = symbol('u')
x = symbol('x')
y = symbol('y')
equation = expr(u)
pde = Pde(equation, u, [x, y])
# Boundary conditions
bc_left = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple(variable=x, value=expr(0))
)
bc_right = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple(variable=x, value=expr(0.1))
)
bc_bottom = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple(variable=y, value=expr(0))
)
bc_top = BoundaryCondition.dirichlet(
expr(100),
BoundaryLocation.simple(variable=y, value=expr(0.05))
)
# Solve
solver = LaplaceEquationSolver()
result = solver.solve_laplace_equation_2d(pde, [bc_left, bc_right, bc_bottom, bc_top])
print(f"Solution: {result.solution}")
print(f"X-eigenvalues: {result.x_eigenvalues}")
print(f"Coefficients: {result.coefficients}")
JavaScript
const { symbol, expr, Pde, BoundaryCondition, BoundaryLocation, LaplaceEquationSolver } = require('mathhook');
const u = symbol('u');
const x = symbol('x');
const y = symbol('y');
const equation = expr(u);
const pde = new Pde(equation, u, [x, y]);
// Boundary conditions
const bcLeft = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple({ variable: x, value: expr(0) })
);
const bcRight = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple({ variable: x, value: expr(0.1) })
);
const bcBottom = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple({ variable: y, value: expr(0) })
);
const bcTop = BoundaryCondition.dirichlet(
expr(100),
BoundaryLocation.simple({ variable: y, value: expr(0.05) })
);
// Solve
const solver = new LaplaceEquationSolver();
const result = solver.solveLaplaceEquation2d(pde, [bcLeft, bcRight, bcBottom, bcTop]);
console.log(`Solution: ${result.solution}`);
console.log(`X-eigenvalues: ${result.xEigenvalues}`);
console.log(`Coefficients: ${result.coefficients}`);
Performance
Time Complexity: O(n) for n Fourier modes in each direction
API Reference
- Rust:
mathhook_core::pde::LaplaceEquationSolver - Python:
mathhook.pde.laplace_equation_solver - JavaScript:
mathhook.pde.laplaceEquationSolver