Euler's method

Level UniversityDifficulty ★★★★★Method⌖ Open in the map

What is it?

The simplest numerical ODE solver: follow the tangent for a small time step, yk+1=yk+h f(tk,yk)y_{k+1} = y_k + h\,f(t_k, y_k). First order (error O(h)O(h)), easy to destabilize — and, in its semi-implicit form, the default integrator of game physics.

Why does it exist?

Most ODEs have no closed-form solution. Euler's idea (1768): we know the slope at the current point, so assume it stays constant for a short time, step, and repeat. It turns any ODE into a loop.

Intuition

Walking with your eyes closed, opening them every hh seconds to check your heading. Small hh: you follow the path closely. Large hh: you drift off, and on a circular orbit you spiral outwards because each tangent step leaves the circle. Error per step O(h2)O(h^2), accumulated over 1/h1/h steps: O(h)O(h).

Formal definition

Explicit Euler: yk+1=yk+h f(tk,yk)y_{k+1} = y_k + h\,f(t_k, y_k). Global error max⁡k∣y(tk)−yk∣=O(h)\max_k|y(t_k) - y_k| = O(h) for Lipschitz ff. On the test equation y′=λyy' = \lambda y (λ<0\lambda < 0) it is stable only if ∣1+hλ∣≤1|1 + h\lambda| \le 1, i.e. h≤2/∣λ∣h \le 2/|\lambda|.

Formulas

yk+1=yk+h f(tk,yk)y_{k+1} = y_k + h\,f(t_k, y_k)
explicit Euler
vk+1=vk+h F(xk)m,xk+1=xk+h vk+1v_{k+1} = v_k + h\,\frac{F(x_k)}{m}, \qquad x_{k+1} = x_k + h\,v_{k+1}
semi-implicit (symplectic) Euler, used in game engines
θk+1=θk−η ∇L(θk)⟺θ˙=−∇L(θ)\theta_{k+1} = \theta_k - \eta\,\nabla L(\theta_k) \quad\Longleftrightarrow\quad \dot\theta = -\nabla L(\theta)
gradient descent is explicit Euler on the gradient flow

How is it computed?

t, y = t0, y0
while t < T:
    y = y + h * f(t, y)
    t = t + h

For mechanics, update velocity first and then position with the new velocity (semi-implicit): energy stays bounded instead of growing.

Example

y′=−2yy' = -2y, y(0)=1y(0) = 1 (exact e−2te^{-2t}), step h=0.1h = 0.1: yk=0.8ky_k = 0.8^k, so y(1)≈0.810=0.107y(1) \approx 0.8^{10} = 0.107 vs e−2=0.135e^{-2} = 0.135. With h=1.5h = 1.5: yk=(−2)ky_k = (-2)^k — the numerical solution explodes while the true one decays. That is numerical instability.

Why does it matter?

Every game engine steps its world with a variant of Euler at 60 Hz. And the most important algorithm of machine learning is Euler's method in disguise: gradient descent is explicit Euler applied to the gradient flow θ˙=−∇L\dot\theta = -\nabla L, with the learning rate as the time step — so its stability limit η<2/λmax⁡\eta < 2/\lambda_{\max} is Euler's stability limit.

Where it shows up in computing

  • Physics engines★★★★★fundamentalPhysics and simulation

    Semi-implicit Euler is the default integrator of Box2D, Bullet and most game engines.

Where it shows up in AI

  • Gradient descent★★★★★advancedAI and machine learning

    GD is explicit Euler on θ˙=−∇L\dot\theta = -\nabla L; the learning rate is the time step and inherits its stability limit.

  • Generative models★★★★★advancedAI and machine learning

    Diffusion and flow-matching samplers integrate a learned ODE/SDE with Euler-type steps.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

Exercises

1Computation

Do three Euler steps with h=0.5h = 0.5 for y′=t−yy' = t - y, y(0)=1y(0) = 1.

Solution

y1=1+0.5(0−1)=0.5y_1 = 1 + 0.5(0 - 1) = 0.5; y2=0.5+0.5(0.5−0.5)=0.5y_2 = 0.5 + 0.5(0.5 - 0.5) = 0.5; y3=0.5+0.5(1−0.5)=0.75y_3 = 0.5 + 0.5(1 - 0.5) = 0.75 (exact y(1.5)=1.5−1+2e−1.5≈0.946y(1.5) = 1.5 - 1 + 2e^{-1.5} \approx 0.946).

2Computing

Simulate a planet on a circular orbit with explicit Euler. What happens to its energy? How does semi-implicit Euler fix it?

Solution

Each explicit step moves along the tangent, outside the circle: the radius and energy grow every step and the planet spirals out. Semi-implicit Euler is symplectic: it preserves a slightly perturbed energy, so the orbit stays closed for very long times.

3AI

Explain why a learning rate above 2/λmax⁡(H)2/\lambda_{\max}(H) makes training diverge, using Euler's method.

Solution

Near a minimum ∇L≈H(θ−θ∗)\nabla L \approx H(\theta - \theta^\ast), so GD is Euler on e˙=−He\dot e = -He. Along the top eigenvector, ek+1=(1−ηλmax⁡)eke_{k+1} = (1 - \eta\lambda_{\max})e_k, which grows when ∣1−ηλmax⁡∣>1|1 - \eta\lambda_{\max}| > 1, i.e. η>2/λmax⁡\eta > 2/\lambda_{\max}.

↑ ↓ to navigate · ↵ · Esc