A tool that visualizes Heun's method, the two-stage predictor-corrector integrator for ordinary differential equations. Predict with explicit Euler, correct with the trapezoidal rule, and change the step size h and initial value to see the error improvement over plain Euler and the agreement with the exact solution in real time.
Parameters
Test ODE
Choose an ODE with a known exact solution
Step size h
Time span advanced in one step
Initial value y0
Initial value of y at t=0
Integration time t_end
s
Total time over which to integrate
Results
—
Heun final value
—
Euler final value
—
Exact final value
—
Heun max error
—
Euler max error
—
Error improvement (%)
—
Predictor & corrector one step — solution-plane animation
A marker steps along the exact solution curve one step at a time. The magnified inset compares the Euler predictor slope and predicted point with the trapezoidal corrector (the average of the start and predicted-end slopes) and the corrected point.
The predictor is explicit Euler. It advances one step using only the start slope at t_n to obtain the provisional end value ỹ. f is the right-hand side, h the step size.
Heun's method is a two-stage, second-order Runge-Kutta method (RK2) with global error O(h²). Halving h cuts the error to about a quarter.
What is the Predictor-Corrector Method?
🙋
I learned Euler's method first for solving differential equations on a computer. But the name "predictor-corrector method" sounds like it has two steps. What is it actually doing?
🎓
Roughly speaking, it does exactly what the name says — "predict, then correct" in two steps. First you make a rough guess of the next point, even a crude one (the predictor). Then you use that guess to recompute it with a more accurate formula (the corrector). Heun's method is the classic example: it predicts with Euler and corrects with the trapezoidal rule. Only two steps, yet it raises the accuracy one order above Euler.
🙋
Euler's method just "goes straight along the slope at the current point", right? What's wrong with that?
🎓
Good question. The problem is that the slope changes partway through the interval. For something like y'=-2y, where the solution curves as it decays, going straight along just the start slope always lands you somewhere off by the end of the step — for decay, a little too far down every time. The error is systematic, so you have to make the step size h tiny just to keep it small.
🙋
I see. So using the trapezoidal rule fixes that "slope changes partway through" problem?
🎓
Exactly that. The trapezoidal rule advances by averaging two slopes — the one at the start and the one at the end of the interval. Because it looks at both the entrance and the exit, it corrects the slope change to first order. But here's the catch: to know the end slope you need the end value — and that's still unknown. That's where the predictor comes in. You first guess the end roughly with Euler, then use that guess to evaluate the end slope. Predict, then correct: that's the whole picture of Heun's method.
🙋
You evaluate the function f twice per step. Is it really worth the extra work?
🎓
It is, solidly. Euler is first-order, so its error is proportional to h. Heun is second-order, so its error is proportional to h². Halve h and Euler's error halves, but Heun's drops to a quarter. Look at the "maximum error vs step size" chart above — the Heun line drops far more steeply. The work is doubled, but you can reach the same accuracy with a much larger h, so the total work is often actually smaller.
🙋
Are there many kinds of predictor-corrector methods? I'm curious about ones other than Heun's.
🎓
There are. Heun's method is a single-step method — both predictor and corrector use only information from the current step. But for big production runs, the "Adams-Bashforth / Adams-Moulton" pairing is widely used, which stores the slopes of the past few steps. You pair the explicit Adams-Bashforth as the predictor with the implicit Adams-Moulton as the corrector. The idea is the same as Heun's — "predict, then correct". So once you understand Heun's method, the higher-order predictor-corrector methods come naturally.
Frequently Asked Questions
A predictor-corrector method is a two-stage numerical integrator that first 'predicts' the value at the next step with a simple formula, then 'corrects' it with a more accurate formula that uses that prediction. Heun's method is the classic example: the predictor is explicit Euler, ỹ = y + h·f(t,y), and the corrector is the trapezoidal rule, y_new = y + (h/2)·[f(t,y) + f(t+h, ỹ)]. Averaging the slopes at the start and the predicted end raises the first-order accuracy of Euler to second order (global error O(h²)).
Explicit Euler is first-order, with global error O(h). Heun's method is second-order, with global error O(h²), so halving the step size h cuts the error roughly in half for Euler but to about a quarter for Heun. For y'=-2y solved with h=0.2, Heun's maximum error is tens of times smaller than Euler's. Heun needs two evaluations of f per step, but because it reaches the same accuracy with a much larger h, the total work is often smaller.
Explicit Euler advances one step using only the slope f(t_n,y_n) at the start, so it drifts systematically wherever the slope changes across the interval. The trapezoidal rule uses the average of the start slope f(t_n,y_n) and the end slope f(t_{n+1},ỹ), which corrects the slope change to first order. Because the end value is unknown, Heun's method first predicts ỹ with the Euler predictor and substitutes it into the end-slope evaluation. This can also be seen as one iteration of the trapezoidal rule.
Yes — Heun's method is one variant of the explicit two-stage, second-order Runge-Kutta family (RK2). RK2 has several variants depending on the coefficients; Heun's method is the 'trapezoidal RK2' that averages the start slope and the predicted-end slope with equal weight 1/2. The midpoint method (an RK2 that uses the slope at the interval midpoint) has the same second-order accuracy but evaluates the slope at a different point. Both have local truncation error O(h³) and global error O(h²), sitting between Euler (RK1) and RK4.
Real-World Applications
Real-time simulation in control and robotics: When the equations of motion of a drone or industrial robot are integrated in time on a microcontroller, Euler's method is not accurate enough while RK4 is too heavy per step. Heun's method delivers second-order accuracy with only two function evaluations, making it well suited to real-time control where you want a "good enough, light enough" balance on limited hardware. It is also a common internal integrator inside model predictive control (MPC), which itself relies on a prediction step.
Molecular dynamics and particle simulation: Molecular dynamics, which solves the motion of many particles, routinely uses velocity-Verlet and predictor-corrector integrators that share Heun's "predict then correct" idea. Predicting the positions first and correcting the velocities with the new forces (slopes) has exactly the same structure as Heun's method in this tool. The predictor-corrector framework is valued for taking large time steps while preserving energy conservation.
Circuit simulation and transient analysis: SPICE-class circuit simulators classically solve the trapezoidal rule (the same formula as Heun's corrector) implicitly, but using an Euler prediction as the initial estimate reduces the number of iterations. The predictor-corrector method also serves to supply a good initial guess for the Newton iteration of an implicit solver.
Teaching numerical analysis and verifying algorithms: Heun's method always appears in numerical-analysis courses as "the first higher-order method beyond Euler". Changing the step size h and actually observing the error fall as h², as in this tool, makes the abstract concept of "order of convergence" tangible. The verification technique of checking whether a newly implemented integrator produces a slope-2 convergence line against a known solution is widely used in practice too.
Common Misconceptions and Pitfalls
The biggest misconception is "because it is second-order, the step size h can be made as large as you like". A high order of accuracy and stability are two different things. Heun's method also has a finite region of absolute stability, and if you make h too large on a fast-decaying (stiff) problem, the numerical solution oscillates or diverges even though the method is second-order. In fact, raising h up to 1.0 for y'=-2y in this tool makes the error grow sharply. The step h must be chosen from both "the accuracy requirement" and "staying inside the stability region".
Next, "iterating the corrector many times improves accuracy further". Heun's method is a "PEC (predict-evaluate-correct)" scheme that completes in one prediction and one correction. Even if you iterate the corrector until it converges, what you obtain is the trapezoidal-rule solution itself, and the order of accuracy stays at second order — it does not rise. Iteration can improve stability somewhat, but it only adds function evaluations without changing the order. To raise accuracy to third or fourth order, you switch to a different method such as RK3 or RK4, not to iteration.
Finally, beware of the idea "the predictor can be sloppy, so its accuracy does not matter". It is true that as a whole, Heun's method ends up second-order even though its predictor is first-order Euler — but that is because the orders of the predictor and corrector mesh well together. In higher-order predictor-corrector methods (such as the Adams family), if you do not match the orders of the predictor and corrector, the corrector's order goes to waste. When you build a predictor-corrector method yourself, always check that the two orders are consistent.
How to Use
Set step size (h) between 0.01–0.5 to control discretization intervals for the ODE solution
Enter initial condition y₀ (typically 0–10) and final time tEnd (0.5–5.0 seconds)
Click Simulate to execute Heun's predictor-corrector method alongside Euler's method for comparison
Review tabulated results: Heun final value, Euler final value, exact analytical solution, and pointwise error metrics
Worked Example
Solve dy/dt = -2y with y₀=1.0, h=0.1, tEnd=1.0. Heun's method yields y(1.0)≈0.1353 versus Euler's 0.1215 (exact: 0.1353e⁻²=0.1353). Maximum point error for Heun: 0.0032; Euler: 0.0138. Error improvement: 77%. The predictor step estimates y* at each stage; the corrector averages endpoint slopes for O(h³) local truncation versus Euler's O(h²).
Practical Notes
Smaller h (0.01) reduces Heun error to <0.1% for stiff systems; Euler requires h<0.005 for equivalent accuracy in chemical kinetics
For oscillatory problems (dy/dt = -y·sin(t)), step sizes h>0.2 cause Heun to overshoot phase; h≤0.1 recommended
Error improvement saturates beyond h=0.05 for smooth IVPs; diminishing returns from finer grids reveal round-off noise
Heun is explicit: O(h²) global error suitable for real-time CFD post-processing; implicit methods needed for λh>2 stability regions