Heat Equation Solver
Topic:
advanced.pde.heat_equation
The heat equation (also called diffusion equation) governs how temperature distributes through materials over time. Solves parabolic PDEs with boundary and initial conditions using separation of variables and Fourier series.
Mathematical Definition
where:
- is temperature at position and time
- is thermal diffusivity (m²/s):
- (1D) or (2D)
Fourier's Law of Heat Conduction:
Conservation of Energy:
Heat Equation Solver
Mathematical Model
The heat equation (also called diffusion equation) governs how temperature distributes through materials over time:
where:
- is temperature at position and time
- is thermal diffusivity (m²/s):
- = thermal conductivity
- = density
- = specific heat capacity
- (1D) or (2D)
Physical Interpretation
Fourier's Law of Heat Conduction: Heat flows from hot to cold at a rate proportional to the temperature gradient.
Heat Flux: (negative sign: heat flows toward lower temperature)
Conservation of Energy: Rate of temperature change = net heat flow in/out
For constant material properties:
Real-World Example: Cooling Metal Rod
Problem Setup
A steel rod of length meter is initially heated uniformly to . Both ends are suddenly plunged into ice water (maintained at ). Find the temperature distribution as the rod cools.
Material Properties (steel):
- Thermal conductivity:
- Density:
- Specific heat:
- Thermal diffusivity:
Mathematical Formulation
PDE:
Boundary Conditions (Dirichlet):
Initial Condition:
Analytical Solution via Separation of Variables
Step 1: Assume Product Solution
Step 2: Separate Variables
Substitute into PDE:
Divide by :
(separation constant chosen for stability)
Step 3: Spatial ODE with Boundary Conditions
Eigenvalue Problem: Only specific give non-trivial solutions.
Solution:
Step 4: Temporal ODE
Solution:
Step 5: General Solution (Superposition)
Step 6: Fourier Coefficients from Initial Condition
Match :
Fourier sine series:
Final Solution:
Solution Behavior
Exponential Decay
Each mode decays exponentially:
Decay rate increases with :
- Mode : decay time
- Mode : decay time (4× faster)
- Mode : decay time (9× faster)
Physical interpretation: Higher spatial frequencies smooth out faster.
Long-Time Behavior
After time :
Only the fundamental mode survives. Temperature profile is half-sine wave.
Maximum Principle
Theorem: For the heat equation with Dirichlet BCs, the maximum temperature occurs either:
- Initially ()
- On the boundary ( or )
Never in the interior for .
Numerical Example: Temperature at Center
At the rod's center ( m), how long until temperature drops to ?
Series solution (first 5 terms):
Dominant term (first mode):
Set :
Physical check: Steel rod cools to half initial temperature in about 2 hours. Reasonable for a 1-meter rod.
Limitations and Edge Cases
Insulated Boundaries (Neumann BCs)
⚠️ NOT SUPPORTED in current MathHook version.
For insulated ends: ,
Different eigenvalues: for (includes !)
Different modes:
Phase 2 feature.
Non-Homogeneous BCs
⚠️ NOT SUPPORTED directly.
For , (non-zero):
Transformation: Let
Then satisfies homogeneous BCs:
Apply MathHook to , then add back steady-state.
Time-Dependent BCs
⚠️ NOT SUPPORTED.
For or :
Requires Duhamel's principle or Green's functions. Phase 2 feature.
Multi-Dimensional Heat Equation
⚠️ 2D/3D NOT SUPPORTED currently.
For 2D:
Solution: Product of 1D solutions:
Eigenvalues: (sum of 1D eigenvalues)
Phase 2 feature.
Examples
Cooling Steel Rod
A 1-meter steel rod initially at 100°C with both ends plunged into ice water (0°C). Demonstrates heat diffusion with Dirichlet boundary conditions.
Rust
#![allow(unused)] fn main() { use mathhook::prelude::*; // Define variables let u = symbol!(u); let x = symbol!(x); let t = symbol!(t); // PDE: u_t = α u_xx let equation = expr!(u); // Placeholder (solver knows structure) let pde = Pde::new(equation, u, vec![x.clone(), t.clone()]); // Thermal diffusivity for steel let alpha = expr!(0.000013); // 1.3 × 10^-5 m²/s // Boundary conditions: u(0,t) = 0, u(1,t) = 0 let bc1 = BoundaryCondition::dirichlet( expr!(0), BoundaryLocation::Simple { variable: x.clone(), value: expr!(0), }, ); let bc2 = BoundaryCondition::dirichlet( expr!(0), BoundaryLocation::Simple { variable: x, value: expr!(1), // L = 1 meter }, ); // Initial condition: u(x,0) = 100°C let ic = InitialCondition::value(expr!(100)); // Solve let solver = HeatEquationSolver::new(); let result = solver.solve_heat_equation_1d(&pde, &alpha, &[bc1, bc2], &ic)?; // What you get: println!("Solution structure: {}", result.solution); // u(x,t) = A_1*sin(π*x)*exp(-π²*α*t) + A_2*sin(2π*x)*exp(-4π²*α*t) + ... println!("Eigenvalues: {:?}", result.eigenvalues); // [π², 4π², 9π², ...] = [(nπ/L)² for n=1,2,3,...] println!("Coefficients (symbolic): {:?}", result.coefficients); // [A_1, A_2, A_3, ...] - SYMBOLIC, not numerical values }
Python
from mathhook import symbol, expr, Pde, BoundaryCondition, BoundaryLocation, InitialCondition, HeatEquationSolver
# Define variables
u = symbol('u')
x = symbol('x')
t = symbol('t')
# PDE: u_t = α u_xx
equation = expr(u)
pde = Pde(equation, u, [x, t])
# Thermal diffusivity for steel
alpha = expr(0.000013)
# Boundary conditions: u(0,t) = 0, u(1,t) = 0
bc1 = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple(variable=x, value=expr(0))
)
bc2 = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple(variable=x, value=expr(1))
)
# Initial condition: u(x,0) = 100°C
ic = InitialCondition.value(expr(100))
# Solve
solver = HeatEquationSolver()
result = solver.solve_heat_equation_1d(pde, alpha, [bc1, bc2], ic)
print(f"Solution: {result.solution}")
print(f"Eigenvalues: {result.eigenvalues}")
print(f"Coefficients: {result.coefficients}")
JavaScript
const { symbol, expr, Pde, BoundaryCondition, BoundaryLocation, InitialCondition, HeatEquationSolver } = require('mathhook');
// Define variables
const u = symbol('u');
const x = symbol('x');
const t = symbol('t');
// PDE: u_t = α u_xx
const equation = expr(u);
const pde = new Pde(equation, u, [x, t]);
// Thermal diffusivity for steel
const alpha = expr(0.000013);
// Boundary conditions: u(0,t) = 0, u(1,t) = 0
const bc1 = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple({ variable: x, value: expr(0) })
);
const bc2 = BoundaryCondition.dirichlet(
expr(0),
BoundaryLocation.simple({ variable: x, value: expr(1) })
);
// Initial condition: u(x,0) = 100°C
const ic = InitialCondition.value(expr(100));
// Solve
const solver = new HeatEquationSolver();
const result = solver.solveHeatEquation1d(pde, alpha, [bc1, bc2], ic);
console.log(`Solution: ${result.solution}`);
console.log(`Eigenvalues: ${result.eigenvalues}`);
console.log(`Coefficients: ${result.coefficients}`);
Performance
Time Complexity: O(n) for n Fourier modes
API Reference
- Rust:
mathhook_core::pde::HeatEquationSolver - Python:
mathhook.pde.heat_equation_solver - JavaScript:
mathhook.pde.heatEquationSolver