mathematics//numerical methods//numerical integration//Euler method
The Euler method is the simplest scheme of numerical integration, which advances a differential equation by following the current slope in a straight line for one step, and it is what most embedded code and physics engines run because it costs one evaluation of the dynamics per step. With \(\dot x=f(x,u)\) and a step \(\Delta t\), the **explicit Euler** update is
The Euler method is the simplest scheme of numerical integration, which advances a differential equation by following the current slope in a straight line for one step, and it is what most embedded code and physics engines run because it costs one evaluation of the dynamics per step. With x˙=f(x,u)\dot x=f(x,u)x˙=f(x,u) and a step Δt\Delta tΔt, the explicit Euler update is
xk+1=xk+Δt f(xk,uk).x_{k+1}=x_k+\Delta t\,f(x_k,u_k).xk+1=xk+Δtf(xk,uk).
Its accumulated error is proportional to Δt\Delta tΔt: half the step, half the error. A drone's attitude estimator that adds the gyroscope's rate times 1 ms to its angle at every tick is running exactly this, and with dynamics of tens of milliseconds it is accurate enough.
Accuracy is rarely what breaks it. On a system that should decay, x˙=λx\dot x=\lambda xx˙=λx with λ<0\lambda<0λ<0, explicit Euler multiplies the state by 1+λΔt1+\lambda\Delta t1+λΔt each step, so it only decays while Δt<2/∣λ∣\Delta t<2/|\lambda|Δt<2/∣λ∣; with λ=−50\lambda=-50λ=−50 per second (a 20 ms time constant) that is 40 ms, and beyond it the numerical solution explodes while the real one dies out (numerical stability).
On an oscillator, explicit Euler adds energy at every step, whatever the step.
An undamped mode has λ=±jω\lambda=\pm j\omegaλ=±jω, and ∣1+jωΔt∣|1+j\omega\Delta t|∣1+jωΔt∣ is always greater than one, so the simulated mass on a spring spirals outwards: the only perpetual motion machine that works, and only inside a computer. When a simulated machine slowly gains energy, suspect the integrator before the design.
Semi-implicit Euler fixes the oscillator for free. It updates the velocity first and then the position with the new velocity; the cost is identical and the energy stays bounded (it wobbles around the true value instead of drifting). It is the simplest symplectic integrator, which is why so many physics engines and game loops use it, and why it is the default choice for mechanical simulations on a microcontroller.
Implicit Euler evaluates the slope at the arrival point, xk+1=xk+Δt f(xk+1)x_{k+1}=x_k+\Delta t,f(x_{k+1})xk+1=xk+Δtf(xk+1). On x˙=λx\dot x=\lambda xx˙=λx it gives xk+1=xk/(1−λΔt)x_{k+1}=x_k/(1-\lambda\Delta t)xk+1=xk/(1−λΔt), which decays for any step, at the price of solving an equation at every step (a division here, a linear or nonlinear solve in general). It is the entry point to the methods used for stiffness.
The same update hides in other fields. Gradient descent is explicit Euler on the flow θ˙=−∇L\dot\theta=-\nabla Lθ˙=−∇L, with the learning rate as the step, and its limit η<2/λmax\eta<2/\lambda_{\max}η<2/λmax is the stability limit above. The next step up in accuracy is the Runge-Kutta method.