What Euler's method actually does
Euler's method turns a differential equation into repeated addition. You know the value of y at one point, and the equation dy/dx = f(x,y) tells you the slope of the solution curve at any point you can name. So you stand at , read the slope there, walk along that straight line for a short horizontal distance h, and call where you land the solution at . Then you read the slope again and repeat.
That is the whole method, and its honesty is what makes it the first numerical scheme every course teaches. You are approximating a curve by a chain of straight segments, so you are always slightly wrong, and the error compounds because every step starts from a point that was already off. Understanding how that error grows is the real content of the topic.
You reach for a numerical march when the equation has no closed-form solution, when the closed form exists but is unpleasant to evaluate, or when f comes from measured data rather than an expression. Nonlinear equations such as dy/dx = x·y, population models, and circuit transients with arbitrary driving signals all land here. If your equation happens to be linear and first order, solve it exactly with the integrating factor calculator instead and use Euler only as a check.
Where the update rule comes from, and what Heun adds
Expand the true solution in a Taylor series about : y(xₙ + h) = y(xₙ) + h·y′(xₙ) + (h²/2)·y″(ξ). The first two terms are exactly the Euler update, because y′(xₙ) = f(xₙ, yₙ). Everything you throw away sits in the h² term. That discarded piece is the local truncation error, and it is proportional to h².
Here is the step that surprises people. To cross a fixed interval of length L you take n = L/h steps, so you accumulate roughly L/h errors of size h² each. The product is proportional to h. That is why Euler's method is called first order: halve the step size and you halve the final error, not quarter it. Doubling your work buys you one extra binary digit of accuracy, which is a poor exchange rate.
Heun's method — improved Euler, or the explicit trapezoidal rule — fixes the most obvious defect. Forward Euler uses only the slope at the left end of the step, which systematically misses whenever the slope is changing across the step. Heun takes a provisional Euler step to get a predicted right-end value , evaluates the slope there too, and steps again using the average of the two slopes. Averaging the endpoints is the trapezoidal rule, so the h² terms cancel and the global error becomes proportional to h². Halve h now and the error falls by a factor of four, for exactly twice the function evaluations.
Notice the special case: when f depends on x alone, the differential equation is just an integral, Euler collapses to the left Riemann sum and Heun collapses to the trapezoidal rule. Every accuracy statement you already know about those quadrature rules carries straight over.
Worked example: dy/dx = x + y, y(0) = 1, four steps of h = 0.25
This problem has the closed-form solution y = 2eˣ − x − 1, so you can check every figure. At x = 1 the exact value is 2e − 2 = 3.436564.
- Step 1. Slope
f(0, 1) = 0 + 1 = 1. Increment0.25 × 1 = 0.25. New point:x = 0.25,y = 1.25. - Step 2. Slope
f(0.25, 1.25) = 1.5. Increment0.25 × 1.5 = 0.375. New point:x = 0.5,y = 1.625. - Step 3. Slope
f(0.5, 1.625) = 2.125. Increment0.53125. New point:x = 0.75,y = 2.15625. - Step 4. Slope
f(0.75, 2.15625) = 2.90625. Increment0.7265625. Final point:x = 1,y = 2.8828125.
The error is 3.436564 − 2.882813 = 0.553751, about 16% low. Euler undershoots here because this solution is convex: every straight segment is drawn below the curve it is chasing.
Now halve the work instead. With h = 0.5 you get y₁ = 1 + 0.5(1) = 1.5 and y₂ = 1.5 + 0.5(2) = 2.5, an error of 0.936564. Compare the two errors: 0.936564 / 0.553751 = 1.69. Halving h cut the error by a factor heading toward 2, exactly as first-order convergence predicts, with the ratio approaching 2 as h shrinks.
Run the same interval with Heun at h = 0.5 and watch the difference. Step 1: left slope f(0,1) = 1, predictor ỹ = 1 + 0.5(1) = 1.5, right slope f(0.5, 1.5) = 2, average 1.5, so y₁ = 1 + 0.5(1.5) = 1.75. Step 2: left slope f(0.5, 1.75) = 2.25, predictor 2.875, right slope f(1, 2.875) = 3.875, average 3.0625, so y₂ = 1.75 + 0.5(3.0625) = 3.28125. The error is 0.155314 — six times smaller than Euler at the same step size, for two slope evaluations per step instead of one.
How to read the result and choose a step size
Treat a single Euler run as unverified. The only cheap, reliable check is to halve h and compare: this calculator does that for you and reports the Same method at half the step size figure. If the two runs agree to the precision you care about, you are converged; if they differ in the second significant figure, your step size is far too coarse. The gap between them is itself a decent error estimate — for a first-order method the remaining error in the coarse run is roughly equal to that gap.
Two failure signatures are worth recognising immediately. Sign flipping — values alternating positive and negative while the true solution decays smoothly — means you have crossed the stability limit. For the linear test problem y′ = λy with λ negative, the Euler update multiplies y by (1 + hλ) each step, so the numbers only decay while |1 + hλ| < 1, that is while h|λ| < 2. At h|λ| = 2 exactly you get a perfect ±1 oscillation. Beyond it the approximation grows without bound while the real solution vanishes. The calculator warns you when the local ∂f/∂y puts you at or past that threshold.
Overflow — a march that runs off to enormous values — means either the same instability or a genuine vertical asymptote in the solution. dy/dx = y² style blow-ups are real, and no step size rescues you past the asymptote; you have to stop the interval before it.
For a well-behaved non-stiff problem, a reasonable working rule is to pick h so that the solution changes by no more than a few percent per step, then halve it once and confirm the answer barely moves. If halving h changes your answer by less than your tolerance, stop.
Error at x = 1 for dy/dx = y, y(0) = 1, as the step size shrinks
| Step size h | Steps | Euler value | Euler error | Heun value | Heun error |
|---|---|---|---|---|---|
| 1 | 1 | 2.000000 | 0.718282 | 2.500000 | 0.218282 |
| 0.5 | 2 | 2.250000 | 0.468282 | 2.640625 | 0.077657 |
| 0.25 | 4 | 2.441406 | 0.276876 | 2.694856 | 0.023426 |
| 0.125 | 8 | 2.565785 | 0.152497 | 2.711841 | 0.006441 |
| 0.1 | 10 | 2.593742 | 0.124539 | 2.714081 | 0.004201 |
Read the two error columns downward. Euler's error falls by roughly a factor of 2 each time h is halved (0.468 → 0.277 → 0.152); Heun's falls by roughly a factor of 4 (0.0777 → 0.0234 → 0.0064). That contrast is what first order versus second order means in practice.
Stability and accuracy are different problems
A step size can be accurate enough and still unstable, and the symptoms look nothing alike. Accuracy error drifts smoothly away from the truth; instability explodes or oscillates. Stiff equations — ones containing both a very fast and a very slow timescale — force explicit Euler to use a step size set by the fastest mode even when you only care about the slow one, which is why stiff problems demand implicit methods such as backward Euler or a BDF solver rather than a smaller explicit step.
Mistakes that make an Euler answer wrong
- Counting steps instead of grid points. Marching from x₀ to x₀ + n·h takes n steps and produces n + 1 points. Ask for 10 steps from 0 with h = 0.1 and you land on x = 1, not x = 0.9.
- Updating y before evaluating the slope. The slope in step n must be evaluated at the old pair (xₙ, yₙ). Overwriting y first is the single most common coding error in this method.
- Using the predicted value as the answer in Heun. The predictor ỹ is scaffolding, not the result. The step value is y plus h times the averaged slope.
- Reporting more digits than you have. An Euler run with h = 0.1 rarely deserves more than two significant figures. Quote what the halved-step comparison supports.
- Assuming small h always helps. Below roughly 10⁻⁸ in double precision, rounding error in the repeated additions starts to grow faster than truncation error falls, so the total error stops improving.
- Ignoring an asymptote. If the true solution blows up inside your interval, no step size gives a meaningful answer past that point. Check the equation for the possibility before trusting the table.
Where Euler sits among the alternatives
Euler's method is the first member of the Runge-Kutta family and is essentially never the right choice for production work. Its value is pedagogical and diagnostic: it is transparent enough that you can verify a single step by hand, which makes it the right tool for checking that you have coded f correctly before switching to something better.
Move up in this order. Heun doubles the work per step and squares the accuracy benefit — take it whenever Euler is not enough. Classical RK4 costs four slope evaluations per step and is fourth order, so on any smooth problem it delivers far more accuracy per unit of work than either; the RK4 calculator shows the same march with k₁ through k₄ printed for every step. Beyond that, adaptive schemes such as Runge-Kutta-Fehlberg estimate the local error at each step and adjust h automatically, and implicit solvers handle stiffness.
Also check whether you need a numerical method at all. Constant-coefficient linear equations have exact closed-form solutions: use the characteristic equation calculator for second-order homogeneous problems, or the Laplace transform calculator when there is a forcing function and initial conditions to carry. An exact answer beats any grid.
Higher-order equations are not an obstacle. Any n-th order ODE becomes a system of n first-order equations by setting u₁ = y, u₂ = y′ and so on, and Euler applies component by component with the same step size. The step table simply gains a column per component.
Key terms
- Initial value problem (IVP)
- A differential equation together with the value of the solution at one point. The initial condition is what makes the solution unique, and it is where the march starts.
- Local truncation error
- The error introduced by one single step, assuming the starting point was exact. It is O(h²) for Euler and O(h³) for Heun.
- Global error
- The accumulated error at the end of the interval. One power of h lower than the local error, because you take O(1/h) steps.
- Explicit method
- One where the new value is written directly in terms of already-known quantities. Euler and Heun are explicit; backward Euler is implicit and requires solving an equation at each step.
- Stiffness
- A property of equations containing widely separated timescales, which forces an explicit method to take much smaller steps than accuracy alone would require.
- Order of a method
- The exponent p in a global error proportional to hᵖ. Euler is order 1, Heun is order 2, classical Runge-Kutta is order 4.
