Free lesson · Differential equations
Euler stepping, convergence and stability
Open interactive lessonPractice calculationsExplore labs
Start with the idea
- The original model may shrink toward zero while a poorly chosen numerical step produces a growing zigzag. The calculation method can be the source of the problem.
Symbols, units & horizon
- n: time-step index
- h: positive time-step length
- t_n=nh: grid time
- f(t,y): rate function defining the ODE
- y_n: numerical state, not generally the exact solution at t_n
- κ: positive decay speed
- |1−κh|<1: stability condition for this scalar Euler decay example
When and why to use this
Use an exact solvable equation as a benchmark, compare several step sizes, and test stability. The ODE lab deliberately allows unstable steps so their consequences are visible.
Start here · the same idea in everyday words
| Technical term | Everyday meaning | Concrete example |
|---|---|---|
| Discretise | Replace continuous change with a sequence of finite steps. | Approximate a one-year path using monthly or daily updates. |
| Convergence | Numerical answers approach the intended solution as the step size shrinks. | Compare paths over the same ending time while using smaller steps. |
| Numerical stability | Small errors do not grow uncontrollably under the numerical update. | A badly chosen step can make a decaying model alternate and grow instead. |
Unpack a technical sentence
Technical wording: An unstable discretisation can diverge even when the continuous dynamics decay.
Read it as: The original model may shrink toward zero while a poorly chosen numerical step produces a growing zigzag. The calculation method can be the source of the problem.
A slower worked example · one step at a time
- Take a dimensionless state starting at 1, with continuous decay rate 2 per year.
- Euler uses the current decay slope for a whole step. For a .25-year step, the update multiplier is 1−2 times .25=.5.
- Two steps reach time .5 years and give 1 times .5 times .5=.25. The exact model value at the same time is exp(−1), about .367879.
- Use a much larger 1.5-year step. The multiplier is 1−2 times 1.5=−2. The numerical sequence starts 1,−2,4,−8. It alternates sign and grows in size.
- The exact continuous decay remains positive and shrinks. A numerical explosion therefore does not prove the continuous model explodes. To check convergence, reduce steps while keeping the ending time fixed.
Self-assessed: Why compare methods at the same ending time?
Otherwise you change both the numerical step and the amount of model time. You cannot tell which change caused the different result.
- A local slope is not constant over a finite interval, so replacing the full path with repeated tangent steps introduces discretisation error.
- Under standard smoothness and stability conditions, explicit Euler has first-order global error over a fixed horizon.
- For a decay equation, a step can be so large that the numerical solution oscillates or grows even though the exact solution decays.
- This is an algorithmic effect, not newly discovered behaviour of the physical or financial model.
Euler stepping, convergence and stability
- Integrate y′=f(t,y) over one step: y(t+h)−y(t)=∫ₜᵗ⁺ʰ f(s,y(s))ds. Replace the integrand by its starting value to obtain Euler’s update.
- For f=−κy, factor the update into (1−κh)y_n. Repeating n times gives y_n=(1−κh)ⁿy₀.
- Decay of the numerical magnitude requires |1−κh|<1, equivalent to 0<κh<2. If 1<κh<2 the numerical path alternates sign even though its magnitude decays.
For κ=2 and y₀=1, h=.25 gives successive values 1,.5,.25. The exact value at t=.5 is exp(−1)≈.3679. With h=1.1 the multiplier is −1.2, so the numerical magnitude grows.
Architecture pseudocode
def euler(function,initial,start,end,steps):
if not isinstance(steps,int) or steps<1 or end<=start: raise ValueError("Valid interval and positive steps required")
h=(end-start)/steps
t,y=start,initial
path=[(t,y)]
for i in range(steps):
y=y+h*function(t,y)
t=start+(i+1)*h
path.append((t,y))
return path
print(euler(lambda t,y:-2*y,1,0,.5,2))
# Replay the slower, synthetic example above. Units are stated in its steps.
def plain_language_example():
from math import exp, e # Standard library; no extra dependency.
return {
"small_multiplier": 1-2*.25,
"two_steps": (1-2*.25)**2,
"exact": exp(-1),
"unstable_multiplier": 1-2*1.5,
}
print(plain_language_example())An analogy to remember
Following a curved route using straight steps works better with appropriately short steps. A step that is too long can cross the destination and keep overshooting.
How this becomes a building block
ODE solvers support calibration, filtering and deterministic state evolution. Euler–Maruyama adds a Brownian increment to a similar update, but stochastic convergence notions differ. Solver error should be checked before interpreting a simulation result as model risk or economic evidence.
Python implementation
Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.
def euler(function,initial,start,end,steps):
if not isinstance(steps,int) or steps<1 or end<=start: raise ValueError("Valid interval and positive steps required")
h=(end-start)/steps
t,y=start,initial
path=[(t,y)]
for i in range(steps):
y=y+h*function(t,y)
t=start+(i+1)*h
path.append((t,y))
return path
print(euler(lambda t,y:-2*y,1,0,.5,2))
# Replay the slower, synthetic example above. Units are stated in its steps.
def plain_language_example():
from math import exp, e # Standard library; no extra dependency.
return {
"small_multiplier": 1-2*.25,
"two_steps": (1-2*.25)**2,
"exact": exp(-1),
"unstable_multiplier": 1-2*1.5,
}
print(plain_language_example())Continue learning
Differential Equations & Numerical Models — all lessons- Start with a rate rule and an initial value
- Ordinary differential equations: growth and mean reversion
- Euler stepping, convergence and stability
- Partial differential equations and the bridge to current research
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations