How this calculation works
The one-dimensional heat equation spreads a temperature profile through constant diffusion. This calculator uses a uniform spatial mesh, centered second differences and backward-Euler time steps with fixed endpoint temperatures. The final nodal profile and mesh ratios are shown so stability can be separated from approximation accuracy.
(I−alpha dt Dxx)u^(n+1)=u^n, with fixed endpoint temperatures.A worked example
For zero endpoints on [0,1] and initial sin(pi x), the exact continuous solution is exp(−pi²t)sin(pi x). With eleven nodes and one hundred steps to t=0.1, the discrete sine mode decays by the backward-Euler amplification factor raised to the hundredth power. Its peak is close to, but not exactly, exp(−pi²/10).
Good to know
One spatial dimension, 3–81 uniformly spaced nodal values and 1–3,000 time steps. Constant positive diffusivity and fixed Dirichlet boundaries only. Initial endpoints must match them. Unconditional scheme stability does not establish adequate spatial or temporal accuracy.
Reference: FEniCS heat-equation time discretization (opens in a new tab) ↗
The initial list defines a uniform spatial mesh
The first and last temperature values are endpoint data, and the remaining entries lie at equally spaced positions across the declared interval length. Changing the number of entries changes the spatial step. An arbitrary list of nonuniform coordinate-temperature pairs would require a different spatial discretization and is not inferred from this field.
The initial endpoint values must equal the selected fixed boundary temperatures. A contradictory pair of values would require an explicit convention about an instantaneous boundary jump. This calculator instead rejects the contradiction, keeping the displayed initial profile and boundary conditions consistent from the first computed time step.
The Finite element one dimensional Poisson equation calculator covers the nearby task. Heat flow includes time evolution and a stability/accuracy problem; Poisson is a static boundary solve.
Implicit stability does not eliminate discretization error
Backward Euler solves a linear system at every time step and is stable for positive diffusivity without an explicit CFL restriction. Nevertheless, coarse time steps can over-damp the profile, and a coarse spatial mesh changes the decay rate of every discrete mode. Stable output is not the same as an accurate continuous solution.
The printed diffusion ratio combines diffusivity, time step and squared spatial step. Refining time at fixed mesh tests temporal error; refining the mesh at sufficiently fine time steps tests spatial error. Changing both without a comparison can conceal whether apparent agreement comes from compensating errors or a genuinely converged approximation.
Fixed boundaries contribute to each time solve
Known fixed endpoints enter the interior right-hand side at every implicit solve. They are not evolved as free interior unknowns. This makes nonzero endpoint temperatures possible while preserving the same diffusion operator, and prevents a solver from accidentally cooling the boundaries when the intended model keeps them at a prescribed temperature.
A sine initial profile with homogeneous boundaries gives a closed-form continuous decay and a separate exact discrete amplification factor. Verification compares against both, distinguishing implementation error from expected discretization error. No adaptive meshing, variable diffusivity, heat source or mixed boundary-condition capability is implied by the basic constant-diffusion demonstration.
Derive the implicit finite-difference step
At an interior mesh node, backward Euler gives (uj(new)−uj(old))/dt=α[uj−1(new)−2uj(new)+uj+1(new)]/dx². Rearranging yields −r uj−1(new)+(1+2r)uj(new)−r uj+1(new)=uj(old), with r=αdt/dx². Fixed endpoint terms move to the right-hand side for the first and last interior equations.
The resulting tridiagonal system is solved at every time step. Unlike forward Euler, this scheme does not impose r≤1/2 for stability. It is nevertheless only first-order in time and second-order in space for sufficiently smooth compatible data. A stable, heavily damped solution can still be a poor approximation when the grid or time step is too coarse.
Check a three-node calculation exactly
Enter initial values 0,1,0, length 1, diffusivity 1, time 0.1, one step and both boundary values zero. Then dx=0.5, dt=0.1 and r=0.4. There is only one interior unknown, and its equation is (1+0.8)u=1, giving u=5/9≈0.555556. The endpoints stay zero.
Keeping the same grid and final time but using two steps gives r=0.2 and final center value (1/1.4)²=25/49≈0.510204. This is time refinement on a fixed spatial grid, not a new physical diffusivity. Further time refinement approaches the spatially discretized solution; refining the spatial grid is a separate operation.
Perform space and time refinement separately
To refine time, keep the initial nodal samples and length fixed while increasing the step count. Compare the output at matching physical positions. To refine space, sample the same initial temperature function at more equally spaced nodes; merely repeating every value changes the represented function and is not a principled grid refinement.
For the smooth zero-endpoint mode sin(πx/L), the continuous solution is exp(−απ²t/L²)sin(πx/L). This provides a useful independent benchmark. Agreement should improve as both resolutions improve, but a large r can still produce excess time-discretization error despite the absence of instability. Record dx, dt and the final time with any reported comparison.
Respect boundary values and the physical interpretation
The initial list includes both endpoints, and those values must equal the fixed left and right temperatures. This enforces compatibility with the boundary condition used from time zero. An insulated endpoint would require a Neumann condition, and periodic endpoints require a different system; neither is selected by typing identical temperatures at both ends.
Diffusivity has units length²/time. Temperatures can use any consistent linear scale, but spatial length and time must match α. With no source term, the model smooths the initial profile toward the linear steady profile between fixed endpoints. It does not model internal heating, changing material properties, convection or a spatially varying cross-section. Those omissions matter when comparing the numerical curve with a real object.
A few questions, answered
Is backward Euler always accurate because it is stable?
No. Coarse time and spatial steps can still introduce substantial damping and discretization error.
Can the initial endpoints differ from the fixed boundaries?
Not in this implementation; they must agree explicitly.
Why can a very large mesh ratio still give an answer?
Backward Euler is unconditionally stable for this linear diffusion problem. Stability prevents a particular numerical blow-up; it does not guarantee a small discretization error.
Does the initial list include the boundary nodes?
Yes. Its first and last values must match the entered fixed boundary temperatures. Interior-only samples would represent a different mesh.