Euler Method Visualizer

change step size and watch global error accumulate

Loading interactive simulation...

Halving the step only halves the error 🖖

Euler steps forward along the tangent line: yn+1 = yn + h · f(xn, yn). One step is wrong by about h²/2 times the second derivative of the solution. That is small. But shrinking h also multiplies the steps — 1/h of them across a fixed interval — so those h² errors accumulate into a total proportional to h, not h². One power of h is what first order means, and it prices accuracy: a further correct decimal digit costs ten times the arithmetic.

Following the slope one step at a time 🖖

Euler's method is the simplest honest guess: from where you are, head in the direction the equation says the curve is going, walk a short distance h, then stop and re-aim. The exact curve keeps bending, but a straight step ignores that bend and drifts off. And it drifts the same way every time: below a curve that bends upward, above one that bends down. All seven presets here obey that. The panel prints the endpoint error twice, at h and at h/2, so the ratio between them is there to read.

Where the number e hides inside Euler 🖖

Apply Euler's method to the equation y' = y starting at y = 1, and each step simply multiplies by (1 + h). Take N steps of size h = 1/N across the interval [0, 1] and the result is exactly (1 + 1/N)N β€” the very formula for compound interest. As N grows it converges to e β‰ˆ 2.71828, so Euler's crude straight-line stepping quietly reconstructs continuous compounding and the definition of the exponential.

EULER'S METHOD β€” THE STEP SIZE DECIDES WHETHER THE ANSWER MEANS ANYTHING

Which Step-Size Case Are You In?

Euler takes the slope where it is standing and walks in a straight line for h before looking again: yβ‚™β‚Šβ‚ = yβ‚™ + hΒ·f(xβ‚™, yβ‚™). Everything that goes wrong is about h. Small enough and the error shrinks in proportion; too large and the answer oscillates or explodes; and no h at all protects you from a solution that runs to infinity while the numbers on screen stay calm.

A sensible step β€” the error is there but small yn+1 = yn + h f(xn, yn)
Step too big β€” the answer oscillates around the truth |1 + hλ| > 1
A fine step β€” you pay in work, not in accuracy ε ∝ h
The exact solution escapes to infinity β€” and Euler does not notice y′ = y² ⇒ y → ∞, x < ∞

01

A sensible step β€” the error is there but small

What you know: A smooth, stable equation with a step well inside the stability limit. The numerical curve tracks the exact one and lags slightly behind it.

Step: yn+1 = yn + h f(xn, yn)

Worked example: yβ€² = x βˆ’ y from y(0) = 1 with h = 0.2 β†’ at x = 2 Euler gives 1.2147 against the exact 1.2707, an error of 0.056

Open this case: linear stable
A sensible step β€” the error is there but small. The straight-line steps stay close to the true curve and lean consistently to one side of it. A smooth, stable equation with a step well inside the stability limit. The numerical curve tracks the exact one and lags slightly behind it.
The straight-line steps stay close to the true curve and lean consistently to one side of it.

02

Step too big β€” the answer oscillates around the truth

What you know: A decaying equation where h has passed the point at which one step overshoots the equilibrium. The exact solution never changes sign; the numerical one does.

Step: |1 + hλ| > 1

Worked example: yβ€² = βˆ’2y with h = 0.6 β†’ 1, then βˆ’0.2, 0.04, βˆ’0.008: the first step alone jumps past zero, while the exact value at x = 0.6 is 0.301

Open this case: decay coarse h
Step too big β€” the answer oscillates around the truth. One step overshoots the axis, so the numbers flip sign while the true solution never does. A decaying equation where h has passed the point at which one step overshoots the equilibrium. The exact solution never changes sign; the numerical one does.
One step overshoots the axis, so the numbers flip sign while the true solution never does.

03

A fine step β€” you pay in work, not in accuracy

What you know: The same equation with a much smaller step. The error falls in proportion to h, and the step count rises in inverse proportion.

Step: ε ∝ h

Worked example: yβ€² = βˆ’2y at x = 0.6: with h = 0.1 the error is 0.039, with h = 0.05 it is 0.019 β€” half the step, half the error, twice the steps

Open this case: decay fine h
A fine step β€” you pay in work, not in accuracy. Halving the step halves the gap to the exact curve, and doubles the number of steps. The same equation with a much smaller step. The error falls in proportion to h, and the step count rises in inverse proportion.
Halving the step halves the gap to the exact curve, and doubles the number of steps.

04

The exact solution escapes to infinity β€” and Euler does not notice

What you know: A nonlinear equation whose true solution has a vertical asymptote at a finite x. The numerical solution sails past it and keeps returning ordinary numbers.

Step: y′ = y² ⇒ y → ∞, x < ∞

Worked example: yβ€² = yΒ² from y(0) = 0.18 blows up at x = 1/0.18 = 5.56, yet Euler with h = 0.18 reports a comfortable 0.68 at x = 4.32, where the true value is already 0.81

Open this case: quadratic growth
The exact solution escapes to infinity β€” and Euler does not notice. The true curve turns vertical at finite x; the numerical one strolls straight past. A nonlinear equation whose true solution has a vertical asymptote at a finite x. The numerical solution sails past it and keeps returning ordinary numbers.
The true curve turns vertical at finite x; the numerical one strolls straight past.
References (1)
  • The method, as Euler set it out: L. Euler, Institutiones calculi integralis, Volume I. Academia Imperialis Scientiarum, Saint Petersburg, 1768.
Common wrong intuition

More steps do not guarantee accuracy by themselves. If h is still too large for curvature, Euler remains biased.

Problem solved in full

  1. Euler's answer at x = 8 for yβ€² = x βˆ’ y 5 steps

    Write down Euler's answer at x = 8 in closed form, without taking a single step, and then explain why halving h does not halve the error. This is yβ€² = x βˆ’ y started at (0, 1) with h = 0.2 and 40 steps.

    1. Start with the answer Euler is aiming at. The equation is linear, x βˆ’ 1 is a particular solution, and the initial condition fixes the coefficient of the decaying part at 2.

    2. Euler's rule on this equation is not a general nonlinear mess β€” it is an affine recurrence. And the same x βˆ’ 1 that solved the differential equation solves the recurrence exactly, step for step. Euler gets the straight part of the answer perfectly right.

    3. So the entire error lives in what is left, and what is left is a geometric sequence with ratio 1 βˆ’ h. Forty factors of 0.8 land on the panel's endpoint with no stepping done at all.

    4. Now put the two decaying parts side by side: the true one is eβˆ’x, Euler's is (1 βˆ’ h)x/h. Both are exponentials in x, and Ξ΄ is the whole difference between their rates. Its series starts at xh/2 β€” that leading h is the entire content of the phrase “first order”.

    5. The error is what survives when the two exponentials are subtracted. First order predicts that halving h halves it, so the ratio should be 2.

    Answer

    Euler ends at 7.000266 against an exact 7.000671, a global error of 0.000405; halve the step and it falls only to 0.000234, a ratio of 1.731285 where first order promised 2. The promise is not broken β€” it has not started. It needs Ξ΄ β‰ˆ xh/2 to be small, and at x = 8 with h = 0.2 that number is 0.8, so the linear term in the error is still competing with every term behind it; dragging the observed ratio up to 1.9933 takes h = 0.005, which is 1600 steps across the same eight units. The closed form gives away the sharper reading: Euler is not approximating this solution, it is solving a different equation exactly, with geometric decay 0.8n standing in for eβˆ’x β€” and 0.8 is the multiplier 1 + hΞ» the panel already prints. Measured on that decaying part alone, Euler is wrong by 60%. The global error looks tiny only because the part it gets wrong has almost died out by the time x reaches 8.

Learning path

Three numerical methods, and where each one gives out

Example problems

  • linear stable - The one equation here whose Euler answer has a closed form: 7 + 2(0.8)⁴⁰, no stepping needed, so the error is checkable to the last digit.
  • decay coarse h - At h = 0.6 the Euler multiplier is -0.2, so the approximation flips sign at every step while the true solution never leaves the positive side.
  • logistic medium h - Logistic growth from 0.2, where the slope rises, peaks, and dies away. Euler overshoots to 0.9993 against 0.9987, because the curve bends down and the tangent does not.
  • decay fine h - The same decay equation at h = 0.05: the multiplier is 0.9 and the sign-flipping stops. Twelve times the steps buys stability, not only accuracy.
  • cooling curve - Coffee at 90 degrees cooling toward a 20 degree room. At the end of the run Euler reads 20.06 against an exact 20.12 -- six hundredths, after a fall of seventy.
  • sine forcing - y' = cos(x) has no y on the right, so Euler here is exactly the left Riemann sum of the cosine: 1.079 where the true integral gives 0.970.
  • quadratic growth - y' = yΒ² runs to infinity at x = 5.56 and the panel stops at 4.32, reading 0.68 where the truth is 0.81. It looks calmest where it is least trustworthy.