anthropocene
Computational Physics / ODE Solvers, One by One
◆ core25 min

Forward Euler, and why it is not enough

The simplest possible integrator. Worth studying not because you will use it, but because every failure mode of every later method is already visible here in its purest form.

An initial value problem gives you the slope everywhere and the state at one moment:

You know which way the trajectory is heading from any point. You want the trajectory.

The obvious move is to trust the slope for a short while:

That is forward Euler, and it is the finite difference from the previous chapter rearranged. It is also, in code, almost nothing:

export const forwardEuler = {
  step: (f, t, y, h) => axpy(h, f(t, y), y),   // y + h·f(t, y)
};

That is the actual implementation this page runs. Every curve below comes from it.

Two kinds of error, and the factor that connects them

Taylor again. Over one step, assuming was exact:

So a single step is wrong by — the local truncation error, which is .

But you do not take one step. To cross a fixed interval you take of them, and the errors accumulate:

The global error is one order worse than the local error. That factor of is the reason a method described as " per step" is called a -th order method. It applies to every integrator in this chapter.

convergence — Exponential decay (λ = 1)
roundoff floor10⁻³10⁻²10⁻¹10⁻⁵10⁻⁴10⁻³STEP SIZE HENDPOINT ERROR
Forward Euler (excluded)Forward Euler — fitted slope 0.972
integrators
Forward Euler · theory 1measured 0.972
Endpoint error against step size for y' = −y. Forward Euler's fitted slope is 1: halving h halves the error, and no more. Switch on the others to see what higher order looks like — but note the vertical scale before you conclude anything about cost.

Slope 1. Ten times the work buys ten times the accuracy — a terrible exchange rate, and the reason nobody integrates anything serious with Euler.

predictcommit first

You integrate y' = −y from t = 0 to t = 5 with forward Euler. Where in the run is the error largest?

The failure that is not about accuracy

Here is the part that matters more than the order.

Apply forward Euler to with . The exact solution decays to zero. The numerical one satisfies

so after steps, . This decays only if , which means

Cross that threshold and the computed solution does not merely become inaccurate — it grows without bound, oscillating in sign, while the true solution decays quietly to zero. There is no warning and no partial credit. It is a cliff.

tunefind the threshold

This is y' = −50y, whose exact solution (dashed) is essentially zero after t = 0.2. Find the step size where forward Euler stops decaying and starts blowing up.

00.20.40.60.811.21.41.61.8200.20.40.60.81TY
forward Euler, h = 0.010exact
0.500
peak |y|1.00e+0
behaviourdecaying

That distinction is the whole reason the rest of this chapter exists:

  • Accuracy asks how close you are, and improves smoothly as shrinks.
  • Stability asks whether you are bounded at all, and fails discontinuously.

When is large — a stiff problem — the stability limit can force a step size thousands of times smaller than accuracy alone would need. You end up spending all your computation resolving a transient that decayed to nothing in the first microsecond. That is the problem implicit methods exist to solve.

recallscheduled for review
For y' = −λy, what step size does forward Euler require, and is it an accuracy limit or a stability limit?

Build it yourself

Now write the step function. It is graded by measuring the order of accuracy your implementation actually achieves — so any correct formulation passes, and a plausible one that is secretly wrong does not.

implementgraded on measured order

Implement one forward Euler step. You are given f(t, y) → State, the current time t, the current state y (an array), and the step size h. Return the new state.

step(f, t, y, h) → State

What to carry forward

Forward Euler is not a bad method because someone made a mistake. It is the honest consequence of using the only information you have — the slope at the point you are standing on. Everything that follows is an answer to a specific complaint about it:

  • first order is too slow → sample the slope more than once per step (Heun, RK4)
  • the stability limit is intolerable → evaluate the slope at the destination (implicit methods)
  • a fixed h is wasteful → estimate the error and resize (adaptive stepping)
  • energy drifts on long runs → preserve the geometry, not the trajectory (symplectic methods)

Next: the first of those.