Separation of Variables for PDEs

Separation of variables is the fundamental technique for solving linear partial differential equations (PDEs) with boundary conditions. This method transforms a PDE into a system of ordinary differential equations (ODEs) that can be solved independently, then combines the solutions into an infinite series.

πŸ“

Mathematical Definition

For a PDE with two independent variables (xx and tt), the product ansatz assumes:

u(x,t)=X(x)β‹…T(t)u(x,t) = X(x) \cdot T(t)

where X(x)X(x) depends only on spatial variable xx and T(t)T(t) depends only on temporal variable tt.

Code Examples

Heat Equation with Dirichlet BCs

Solve 1D heat equation with fixed boundary conditions

use mathhook::prelude::*;

let u = symbol!(u);
let x = symbol!(x);
let t = symbol!(t);
let alpha = symbol!(alpha);

let equation = expr!(u);
let pde = Pde::new(equation, u, vec![x.clone(), t.clone()]);

// Boundary conditions: u(0,t) = 0, u(Ο€,t) = 0
let bc_left = BoundaryCondition::dirichlet_at(x.clone(), expr!(0), expr!(0));
let bc_right = BoundaryCondition::dirichlet_at(x.clone(), expr!(pi), expr!(0));
let bcs = vec![bc_left, bc_right];

// Initial condition: u(x,0) = sin(x)
let ic = InitialCondition::value(expr!(sin(x)));
let ics = vec![ic];

let solution = separate_variables(&pde, &bcs, &ics)?;
// Result: eigenvalues [1, 4, 9, 16, ...], eigenfunctions [sin(x), sin(2x), ...]

Wave Equation

Solve 1D wave equation with Dirichlet boundary conditions

use mathhook::prelude::*;

let u = symbol!(u);
let x = symbol!(x);
let t = symbol!(t);
let L = symbol!(L);

let pde = Pde::new(expr!(u), u, vec![x.clone(), t.clone()]);

let bc_left = BoundaryCondition::dirichlet_at(x.clone(), expr!(0), expr!(0));
let bc_right = BoundaryCondition::dirichlet_at(x.clone(), expr!(L), expr!(0));
let bcs = vec![bc_left, bc_right];

// Initial displacement and velocity
let ic_displacement = InitialCondition::value(expr!(sin(pi * x / L)));
let ic_velocity = InitialCondition::derivative(expr!(0));
let ics = vec![ic_displacement, ic_velocity];

let solution = separate_variables(&pde, &bcs, &ics)?;

Laplace Equation on Rectangle

Solve Laplace's equation on rectangular domain

use mathhook::prelude::*;

let u = symbol!(u);
let x = symbol!(x);
let y = symbol!(y);
let a = symbol!(a);

let pde = Pde::new(expr!(u), u, vec![x.clone(), y.clone()]);

let bc_left = BoundaryCondition::dirichlet_at(x.clone(), expr!(0), expr!(0));
let bc_right = BoundaryCondition::dirichlet_at(x.clone(), expr!(a), expr!(0));
let bcs = vec![bc_left, bc_right];

let ics = vec![];  // Laplace is elliptic, not time-dependent

let solution = separate_variables(&pde, &bcs, &ics)?;

πŸ”— Related Topics