Heun: O(h²) 2nd order
RK4: O(h⁴) 4th order
Halving h → RK4
error × 1/16
Compare Euler, Heun, RK2, RK4, and RK45 methods on the same problem. Visualize accuracy and stability differences. Presets: logistic growth, Van der Pol oscillator, Lorenz equations.
The core of any ODE solver is approximating the derivative $dy/dt$ at a point to predict the next value. The general first-order ODE is:
$$ \frac{dy}{dt}= f(t, y), \quad y(t_0) = y_0 $$Here, $f(t, y)$ is the rate function (e.g., growth rate), $t$ is time, $y$ is the state we're solving for (like population), and $y_0$ is the initial condition. The solver's job is to find $y_1, y_2, ...$ at times $t_1 = t_0 + h, t_2 = t_0 + 2h$, etc., where $h$ is the step size you control in the simulator.
The methods differ in how they estimate the "average slope" across a step. For example, Euler's method (1st order) simply uses the slope at the beginning of the step:
$$ y_{n+1}= y_n + h \cdot f(t_n, y_n) $$Meanwhile, the classic 4th-order Runge-Kutta (RK4) method takes a weighted average of four slope estimates within the step:
$$ \begin{align*}k_1 &= f(t_n, y_n) \\ k_2 &= f(t_n + h/2, y_n + h k_1/2) \\ k_3 &= f(t_n + h/2, y_n + h k_2/2) \\ k_4 &= f(t_n + h, y_n + h k_3) \\ y_{n+1}&= y_n + \frac{h}{6}(k_1 + 2k_2 + 2k_3 + k_4) \end{align*} $$This extra computation gives a much better estimate of the true average slope, which is why RK4's error shrinks as $O(h^4)$. Halving the step size reduces its error by a factor of $2^4 = 16$, as noted in the theory panel.
CAE & Multibody Dynamics: When simulating the motion of a car's suspension or a robotic arm, the equations of motion are complex, coupled ODEs. Solvers like RK4 are the workhorses behind the scenes, calculating positions and velocities at each time step to generate accurate animations and force data.
Circuit Simulation (SPICE): Simulating voltage and current over time in an electronic circuit involves solving ODEs defined by capacitors and inductors. Adaptive methods like RK45 are crucial here to handle both fast switching transients and long, steady-state periods efficiently.
Epidemiology & Population Modeling: Models like logistic growth or SIR (Susceptible-Infected-Recovered) are systems of ODEs. Public health officials use numerical solvers to project infection curves and test intervention strategies, where stability of the solution is critical for reliable forecasts.
Aerospace & Trajectory Control: Calculating a spacecraft's flight path involves integrating equations for position, velocity, and attitude. High-fidelity simulations use advanced, adaptive solvers to minimize fuel consumption errors over long journeys while ensuring numerical stability.
First, understand that "higher-order does not always equal better". It's true that RK4 is vastly more accurate than Euler's method. However, there are cases, like in real-time simulations for control systems where calculation speed is paramount and some error is absorbed within the feedback loop, where Euler's method might be chosen. Try selecting "Logistic Growth" in this tool and comparing the methods with a step size of h=1.0. The results for RK4 and Euler will differ significantly, but if you refine the step size to h=0.1, even Euler's method approaches a solution usable in practice. In other words, there is a trade-off relationship between "step size" and "order".
Next, don't overlook "stability". For example, if you run Euler's method on the "Van der Pol Oscillator" with a very large step size like h=2.0, the solution may diverge and the graph can blow up. This is a phenomenon called numerical instability, and the maximum allowable step size differs by method. In practical work, it's essential to estimate a stable step size in advance to prevent the calculation from failing.
Finally, don't overtrust the "automatic step size control" of RK45. It's not a universal tool; you need to set a target accuracy—the tolerance (the "Tolerance" parameter in the tool). Setting a loose tolerance (e.g., 1e-3) makes the calculation fast but yields a coarse solution, while a strict tolerance (e.g., 1e-9) yields high precision but skyrockets computational cost. Always determine parameters by working backward from the requirement: "What level of accuracy is needed?"
For logistic growth with y0=10, T=20, h=0.01: Euler (O(h)) requires 2000 steps and produces 3.2% error; Heun (O(h²)) uses 2000 steps with 0.15% error; RK4 (O(h⁴)) achieves 0.0008% error. RK45 adaptive starts with h=0.01, reduces to h=0.002 near rapid changes, completing in 1847 accepted steps. For the stiff equation with h=0.1, Euler diverges unstably, while RK4 remains stable but requires h≤0.0005 for accuracy—adaptive RK45 auto-selects safe steps.