Solve the heat equation ∂T/∂t = α·∂²T/∂x² numerically. Watch temperature profiles evolve with Dirichlet/Neumann/periodic boundary conditions. See Fourier series convergence in real time.
The 1D heat equation is ∂T/∂t = α·∂²T/∂x². Explicit finite difference: T_i^(n+1) = T_i^n + r·(T_{i+1}^n − 2T_i^n + T_{i-1}^n) where r = α·dt/dx². Stability requires r ≤ 0.5. Analytical solution: T(x,t) = Σ aₙ·sin(nπx/L)·e^(−(nπ/L)²·α·t).
Dirichlet (fixed temperature): the bar ends are held at constant temperature — like a metal rod with its ends in ice water and boiling water. Neumann (insulated): no heat flux through the ends — temperature gradient is zero at boundaries. Periodic: the bar wraps around, as if it were a ring.
Any initial temperature distribution can be decomposed into sine modes T(x,0) = Σ aₙ·sin(nπx/L). Higher modes (larger n) decay exponentially faster: amplitude ~ e^(−n²t). This is why heat spreads and smooths out — fine-scale features disappear first, leaving only the slowest-decaying fundamental mode.
This simulation numerically solves the 1D heat equation ∂T/∂t = α·∂²T/∂x² on a 200-point rod using an explicit finite-difference scheme. You choose an initial temperature profile and a boundary condition, then watch heat diffuse and smooth out in real time. A live bar chart decomposes the temperature curve into its first five Fourier sine modes, showing directly why higher-frequency features fade away fastest.
A rod of 200 grid points evolving under T_i^(n+1) = T_i^n + r·(T_{i+1} − 2T_i + T_{i-1}), with r = α·dt/dx² and dt chosen automatically at 80% of the stability limit (r ≤ 0.5). The colour strip and the profile plot track the same temperature array; a separate bar chart shows the magnitude of Fourier sine modes n = 1 to 5 extracted from the current profile.
Set the Thermal Diffusivity α slider (0.01–0.5), pick an Initial Condition (Gaussian Pulse, Step Function, Sine Wave, Hot End) and a Boundary type (Dirichlet fixed-temperature, Neumann insulated, or Periodic), then press Run. The four preset buttons load ready-made combinations — try Hot End with Dirichlet to watch a heat front spread from one end, or Periodic with a sine wave to see a single mode decay cleanly.
The Fourier mode chart is not decoration — it is the same sine decomposition Joseph Fourier introduced in 1822 to solve exactly this equation. Because each mode n decays as e^(−(nπ/L)²·α·t), higher modes vanish roughly n² times faster than the fundamental, which is why any rough initial profile always relaxes into a single smooth bump.
It solves the 1D heat (diffusion) equation ∂T/∂t = α·∂²T/∂x² on a rod of 200 grid points, using an explicit finite-difference scheme: each new temperature value is the old value plus a correction proportional to the curvature of its neighbours, scaled by r = α·dt/dx². The time step dt is recalculated from the diffusivity α and fixed automatically at 80% of the stability limit (r ≤ 0.5), so the simulation never blows up no matter how you set the diffusivity slider.
Dirichlet holds both ends of the rod at a fixed temperature — 1.0 at the hot end for the "Hot End" preset, 0.0 otherwise — like a rod with its tips clamped to a heater and an ice bath. Neumann sets a zero temperature gradient at each end (T_new[0]=T_new[1], T_new[N-1]=T_new[N-2]), modelling a perfectly insulated rod that cannot exchange heat with its surroundings. Periodic wraps the rod into a ring, so heat that would exit the right end re-enters on the left.
The α slider (range 0.01 to 0.5) sets how fast heat spreads: it appears directly in the finite-difference update and in the automatically computed time step dt = 0.8 × 0.4 × dx² / α. Larger α smooths the temperature profile faster in simulated time, and because dt scales inversely with α, the simulation also advances through more physical time per rendered frame at high diffusivity.
Gaussian Pulse starts with a bell-shaped hot spot centred at the middle of the rod; Step Function starts as a flat-topped hot region between x=0.3 and x=0.7; Sine Wave starts as a single half-period sine curve, which is a pure Fourier mode and therefore the simplest case to watch decay; Hot End clamps only the leftmost 5% of the rod to maximum temperature, simulating one end held against a heat source.
For each mode n from 1 to 5, the simulation numerically integrates the current temperature array against sin(nπx/L) to extract that mode's amplitude, exactly the discrete version of a Fourier sine series coefficient. It matters because the exact analytical solution of the heat equation is T(x,t) = Σ aₙ·sin(nπx/L)·e^(−(nπ/L)²·α·t): every mode decays exponentially, with higher n decaying far faster, which is precisely the smoothing behaviour visible in the rod and profile plots.